on Airdrop Download trigger
This commit is contained in:
25
trigger/com.user.template.plist
Normal file
25
trigger/com.user.template.plist
Normal file
@@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
|
||||
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>Label</key>
|
||||
<string>template_label</string>
|
||||
|
||||
<key>UserName</key>
|
||||
<string>template_username</string>
|
||||
|
||||
<key>ProgramArguments</key>
|
||||
<array>
|
||||
<string>open</string>
|
||||
<string>template_app_path</string>
|
||||
</array>
|
||||
|
||||
<key>WatchPaths</key>
|
||||
<array>
|
||||
<string>template_disk_path</string>
|
||||
</array>
|
||||
|
||||
</dict>
|
||||
</plist>
|
||||
|
||||
BIN
trigger/icone.png
Normal file
BIN
trigger/icone.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 40 KiB |
18
trigger/onAirdropDownload.sh
Executable file
18
trigger/onAirdropDownload.sh
Executable file
@@ -0,0 +1,18 @@
|
||||
#! /bin/bash
|
||||
set -eux
|
||||
date
|
||||
echo `date` >> /tmp/heho
|
||||
find ${HOME}/Downloads
|
||||
mkdir -p ${HOME}/Documents/.DanceVideos
|
||||
find ${HOME}/Documents/.DanceVideos
|
||||
|
||||
DLDIR=${HOME}/Downloads
|
||||
|
||||
DESTDIR=${HOME}/Documents/.DanceVideos
|
||||
|
||||
DL_VIDEOS=`find $DLDIR -type f -iname "*.mp4" -or -iname "*.mov" -maxdepth 1`
|
||||
[ -z "$DL_VIDEOS" ] || {
|
||||
for v in "$DL_VIDEOS"; do
|
||||
echo `basename "$v"` >> /tmp/foo
|
||||
done
|
||||
}
|
||||
7
trigger/onSD_DANSEMount.sh
Executable file
7
trigger/onSD_DANSEMount.sh
Executable file
@@ -0,0 +1,7 @@
|
||||
#! /bin/bash
|
||||
set -eux
|
||||
if [ -d '/Volumes/SD_DANSE/' ]; then
|
||||
echo "`date` mounted SD Dance" >> /tmp/foo
|
||||
else
|
||||
echo "`date` unmounted SD Dance" >> /tmp/foo
|
||||
fi
|
||||
47
trigger/registerApp.sh
Executable file
47
trigger/registerApp.sh
Executable file
@@ -0,0 +1,47 @@
|
||||
#!/bin/bash
|
||||
set -eux
|
||||
SCRIPTS_DIR=$(dirname `realpath ${BASH_SOURCE[0]}`)
|
||||
|
||||
# Arguments
|
||||
SCRIPT=${1:-onAirdropDownload.sh}
|
||||
if [ "$SCRIPT" = `basename $SCRIPT` ]; then
|
||||
SCRIPT="${SCRIPTS_DIR}/${SCRIPT}"
|
||||
fi
|
||||
|
||||
DISK_PATH_TO_WATCH=${2:-${HOME}/Downloads}
|
||||
|
||||
# create App
|
||||
|
||||
APP_NAME=`basename $SCRIPT | sed 's#\..*$##' | awk '{print toupper(substr($0,1,1)) substr($0,2)}'`
|
||||
TEMPLATE_APP="/Applications/HelloWorldTemplate.app"
|
||||
NEW_APP="/Applications/DanceVideos${APP_NAME}.app"
|
||||
rm -rf "$NEW_APP"
|
||||
cp -R "$TEMPLATE_APP" "$NEW_APP"
|
||||
sed -i '' "s|echo hello world|bash ${SCRIPT}|g" "$NEW_APP/Contents/document.wflow"
|
||||
|
||||
sips -s format icns ${SCRIPTS_DIR}/icone.png --out /tmp/monIcone.icns
|
||||
mv /tmp/monIcone.icns "$NEW_APP/Contents/Resources/ApplicationStub.icns"
|
||||
|
||||
# register trigger
|
||||
|
||||
PLIST_label=`tr '[:upper:]' '[:lower:]' <<< "com.user.watch_${APP_NAME}"`
|
||||
PLIST_TEMPLATE_username=${USER}
|
||||
PLIST_TEMPLATE_app_path=${NEW_APP}
|
||||
PLIST_TEMPLATE_disk_path=${DISK_PATH_TO_WATCH}
|
||||
|
||||
PLIST_FILEPATH="${HOME}/Library/LaunchAgents/${PLIST_label}.plist"
|
||||
|
||||
launchctl unload "${PLIST_FILEPATH}" | :
|
||||
|
||||
touch ${PLIST_FILEPATH}
|
||||
|
||||
cat ${SCRIPTS_DIR}/com.user.template.plist \
|
||||
| sed "s#template_label#${PLIST_label}#" \
|
||||
| sed "s#template_username#${PLIST_TEMPLATE_username}#" \
|
||||
| sed "s#template_app_path#${PLIST_TEMPLATE_app_path}#" \
|
||||
| sed "s#template_disk_path#${PLIST_TEMPLATE_disk_path}#" \
|
||||
> "${PLIST_FILEPATH}"
|
||||
|
||||
launchctl load "${PLIST_FILEPATH}"
|
||||
# launchctl list | grep watch_
|
||||
launchctl start ${PLIST_label}
|
||||
16
trigger/trigger.sh
Executable file
16
trigger/trigger.sh
Executable file
@@ -0,0 +1,16 @@
|
||||
#!/bin/bash
|
||||
set -eux
|
||||
SCRIPTS_DIR="$(dirname "$(realpath "${BASH_SOURCE[0]}")")"
|
||||
default_disk_path="${HOME}/Downloads"
|
||||
|
||||
for script in "$SCRIPTS_DIR"/on*.sh; do
|
||||
[ -f "$script" ] || continue
|
||||
script_name="$(basename "$script")"
|
||||
|
||||
case "$script_name" in
|
||||
onSD_DANSEMount.sh) disk_path="/Volumes/SD_DANSE" ;;
|
||||
*) disk_path="$default_disk_path" ;;
|
||||
esac
|
||||
|
||||
"$SCRIPTS_DIR/registerApp.sh" "$script" "$disk_path"
|
||||
done
|
||||
Reference in New Issue
Block a user