diff options
Diffstat (limited to 'launchd_scripts')
-rwxr-xr-x | launchd_scripts/attempt_vim_switch.sh | 13 | ||||
-rwxr-xr-x | launchd_scripts/bootstrap.sh | 34 | ||||
-rwxr-xr-x | launchd_scripts/notice.sh | 5 | ||||
-rwxr-xr-x | launchd_scripts/notice_2.sh | 5 | ||||
-rwxr-xr-x | launchd_scripts/process_files.sh | 15 | ||||
-rw-r--r-- | launchd_scripts/vars.json | 3 | ||||
-rw-r--r-- | launchd_scripts/watch_volumes.plist | 19 | ||||
-rw-r--r-- | launchd_scripts/watch_volumes.plist.tpl | 19 |
8 files changed, 113 insertions, 0 deletions
diff --git a/launchd_scripts/attempt_vim_switch.sh b/launchd_scripts/attempt_vim_switch.sh new file mode 100755 index 000000000000..65f77c342671 --- /dev/null +++ b/launchd_scripts/attempt_vim_switch.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash + + +if [ -d /Volumes/usb_vim ] && \ # usb has mounted + [ ! -L "$HOME/.vimrc" ] && \ # .vimrc is a symlink + [ ! -L "$HOME/.vim" ]; then # .vim dir is a symlink + . "/Volumes/usb_vim/vim/vim_point_to_usb.sh" + . "$HOME/pc_settings/launchd_scripts/notice.sh" +else + . "$HOME/pc_settings/launchd_scripts/notice_2.sh" +fi + + diff --git a/launchd_scripts/bootstrap.sh b/launchd_scripts/bootstrap.sh new file mode 100755 index 000000000000..0df2689ae18e --- /dev/null +++ b/launchd_scripts/bootstrap.sh @@ -0,0 +1,34 @@ +#!/usr/bin/env bash + + +# Unload scripts in case there have been changes since it was last loaded. +echo -n "Unloading personal *.plist files... " && +launchctl unload ~/Library/LaunchAgents/watch_volumes.plist && +echo "Done." || echo "Error." + + +# Remove *.plist symlinks created last time. +echo -n "Removing *.plist symlinks... " && +rm ~/Library/LaunchAgents/watch_volumes.plist && +echo "Done." || echo "Error." + + +# Process the *.tpl files, replacing global identifiers with the values +# from vars.json. +echo -n "Processing *.tpl files... " && +. ./process_files.sh && +echo "Done." || echo "Error." + + +# Recreate those symlinks. +echo -n "Recreating *.plist symlinks to ~/Library/LaunchAgents ... " && +ln -s ~/pc_settings/launchd_scripts/watch_volumes.plist \ + ~/Library/LaunchAgents/watch_volumes.plist && +echo "Done." || echo "Error." + + +# Reload scripts in case there have been changes since it was last loaded. +echo -n "Reloading personal *.plist files... " && +launchctl load ~/Library/LaunchAgents/watch_volumes.plist && +echo "Done." || echo "Error." + diff --git a/launchd_scripts/notice.sh b/launchd_scripts/notice.sh new file mode 100755 index 000000000000..1567be3601e4 --- /dev/null +++ b/launchd_scripts/notice.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash + +osascript -e "tell Application \"System Events\" to display alert\ + \"New volume mounted.\"" + diff --git a/launchd_scripts/notice_2.sh b/launchd_scripts/notice_2.sh new file mode 100755 index 000000000000..188ee813a06c --- /dev/null +++ b/launchd_scripts/notice_2.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash + +osascript -e "tell Application \"System Events\" to display alert\ + \"Not going to switch!\"" + diff --git a/launchd_scripts/process_files.sh b/launchd_scripts/process_files.sh new file mode 100755 index 000000000000..a5e330d7705b --- /dev/null +++ b/launchd_scripts/process_files.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env bash + +# This script processes certain files and replaces +# {{<IDENTIFIER>}} with the entries in vars.json + +output_path="./watch_volumes.plist" +template_file="watch_volumes.plist.tpl" +usb_drive_path=$(jq < ./vars.json '.USB_DRIVE_PATH' | \ + sed 's/\//\\\//g' | sed 's/"//g') + +cat "$template_file" | perl -p -e 's/(\{\{[^}]+\}\})/'$usb_drive_path'/g' \ + >"$output_path" + +echo "Done." + diff --git a/launchd_scripts/vars.json b/launchd_scripts/vars.json new file mode 100644 index 000000000000..6b5328c461f4 --- /dev/null +++ b/launchd_scripts/vars.json @@ -0,0 +1,3 @@ +{ + "USB_DRIVE_PATH": "/Volumes/usb_vim/" +} diff --git a/launchd_scripts/watch_volumes.plist b/launchd_scripts/watch_volumes.plist new file mode 100644 index 000000000000..f082952fec76 --- /dev/null +++ b/launchd_scripts/watch_volumes.plist @@ -0,0 +1,19 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" +"http://www.apple.com/DTDs/PropertyList-1.0.dtd"> +<plist version="1.0"> +<dict> + <key>Label</key> + <string>WatchVolumes</string> + + <key>ProgramArguments</key> + <array> + <string>/Users/wcarroll/pc_settings/launchd_scripts/attempt_vim_switch.sh</string> + </array> + + <key>WatchPaths</key> + <array> + <string>/Volumes/usb_vim/</string> + </array> +</dict> +</plist> diff --git a/launchd_scripts/watch_volumes.plist.tpl b/launchd_scripts/watch_volumes.plist.tpl new file mode 100644 index 000000000000..be5cb4ad763d --- /dev/null +++ b/launchd_scripts/watch_volumes.plist.tpl @@ -0,0 +1,19 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" +"http://www.apple.com/DTDs/PropertyList-1.0.dtd"> +<plist version="1.0"> +<dict> + <key>Label</key> + <string>WatchVolumes</string> + + <key>ProgramArguments</key> + <array> + <string>/Users/wcarroll/pc_settings/launchd_scripts/attempt_vim_switch.sh</string> + </array> + + <key>WatchPaths</key> + <array> + <string>{{USB_DRIVE_PATH}}</string> + </array> +</dict> +</plist> |