Last active
April 28, 2016 14:28
-
-
Save munepi/66e9736531120af8effb0783a79790f8 to your computer and use it in GitHub Desktop.
An agent script to start/stop some cloud strage services depending a status running iPhone tethering - iPhoneテザリングON/OFF時にクラウド型ストレージをON/OFFにするスクリプト
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# an agent script to start/stop some cloud strage services | |
# depending a status running iPhone tethering | |
## set your iPhone name | |
iPhoneName=${iPhoneName:-Your_iPhone_Name} | |
isTethering=0 | |
export PATH=/usr/bin:/bin:/usr/sbin:/sbin | |
__airport=/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport | |
## iPhone USB-wired tethering network | |
[ -z "$(networksetup -getinfo "iPhone USB" | grep "^IP address")" ] || isTethering=1 | |
## wireless iPhone tethering network | |
currSSID=$($__airport -I | grep -e "SSID" | tail -n 1 | sed "s,.*: *,,") | |
[ "$currSSID" = "$iPhoneName" ] && isTethering=1 | |
## appDropbox [start|stop] | |
appDropbox(){ | |
local status=$1 | |
local app=${FUNCNAME[0]} | |
case $status in | |
start) | |
pgrep -q Dropbox | |
[ $? -eq 1 ] && echo Starting $app && \ | |
[ -d /Applications/Dropbox.app ] && \ | |
open -a Dropbox | |
;; | |
stop) | |
pgrep -q Dropbox | |
[ $? -eq 0 ] && echo Stopping $app && \ | |
killall -KILL Dropbox | |
;; | |
*) | |
echo unknown option: $1 | |
return 1 | |
;; | |
esac | |
return 0 | |
} | |
## appGoogleDrive [start|stop] | |
appGoogleDrive(){ | |
local status=$1 | |
local app=${FUNCNAME[0]} | |
case $status in | |
start) | |
pgrep -q "Google Drive" | |
[ $? -eq 1 ] && echo Starting $app && \ | |
[ -d /Applications/"Google Drive.app" ] && \ | |
open -a "Google Drive" | |
;; | |
stop) | |
pgrep -q "Google Drive" | |
[ $? -eq 0 ] && echo Stopping $app && \ | |
killall -KILL "Google Drive" | |
;; | |
*) | |
echo unknown option: $1 | |
return 1 | |
;; | |
esac | |
return 0 | |
} | |
## main | |
if [ $isTethering -eq 0 ]; then | |
appDropbox start || exit 1 | |
appGoogleDrive start || exit 1 | |
else | |
appDropbox stop || exit 1 | |
appGoogleDrive stop || exit 1 | |
fi | |
exit | |
$ vim ~/Library/LaunchAgents/local.manage.cloudstrage.airport.plist | |
<?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>local.manage.cloudstrage.airport</string> | |
<key>ProgramArguments</key> | |
<array> | |
<string>/some/where/_manage-cloudstrage-airport.sh</string> | |
</array> | |
<key>StartInterval</key> | |
<integer>60</integer> | |
</dict> | |
</plist> | |
$ launchctl load ~/Library/LaunchAgents/local.manage.cloudstrage.airport.plist | |
$ launchctl start local.manage.cloudstrage.airport |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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>local.manage.cloudstrage.airport</string> | |
<key>ProgramArguments</key> | |
<array> | |
<string>/usr/local/bin/_manage-cloudstrage-airport.sh</string> | |
</array> | |
<key>OnDemand</key> | |
<true/> | |
<key>StartInterval</key> | |
<integer>60</integer> | |
</dict> | |
</plist> |
- プロセスを
KILL
しているところを、アプリ側の「一時停止」にしたい。- Linux 版 Dropbox に対する command line interface はあるのに、Mac OS X版のそれがないから、Dropboxの一時停止ができない><
KILL
よりも、PAUSE
&CONT
でもいいけど。
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
_manage-cloudstrage-airport.sh
to somewhere like/usr/local/bin
.~/Library/LaunchAgents/local.manage.cloudstrage.airport.plist
as above attached one.$ launchctl load ~/Library/LaunchAgents/local.manage.cloudstrage.airport.plist
$ launchctl start local.manage.cloudstrage.airport