7
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Mac OS X 起動時・スリープ復帰時にAFPボリュームを自動マウント

Last updated at Posted at 2014-05-01

Install terminal-notifier

$ brew install terminal-notifier

Create Automator App which automatically mount afp volume

Automator enables a shell script to run silently.

mount_all.app

Content of shell script

function mount_afp_volume()
{
	host=HOSTNAME_OR_IPADDRESS
	username=AFP_USERNAME
	password=AFP_PASSWORD
	mount_point=$1
	if [ ! -d /Volumes/$mount_point ]
	then
		mkdir -p /Volumes/$mount_point
		mount_afp afp://$username:$password@$host/$mount_point /Volumes/$mount_point
		/usr/local/bin/terminal-notifier -title "Mount" -message "/Volumes/"$mount_point" is now mounted." -sound Submarine
	fi
}

mount_afp_volume Data
mount_afp_volume TimeMachine

Install SleepWatcher

$ brew install SleepWatcher
==> Downloading http://www.bernhard-baehr.de/sleepwatcher_2.2.tgz
######################################################################## 100.0%
==> mv ../sleepwatcher.8 .
==> make install PREFIX=/usr/local/Cellar/sleepwatcher/2.2
 .
 .
 .
$ /usr/local/sbin/sleepwatcher
$ sudo cp /usr/local/Cellar/sleepwatcher/2.2/de.bernhard-baehr.sleepwatcher-20compatibility.plist /Library/LaunchDaemons/de.bernhard-baehr.sleepwatcher.plist
$ launchctl load /Library/LaunchDaemons/de.bernhard-baehr.sleepwatcher.plist
$ cat /Library/LaunchDaemons/de.bernhard-baehr.sleepwatcher.plist
<?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>de.bernhard-baehr.sleepwatcher</string>
	<key>ProgramArguments</key>
	<array>
		<string>/usr/local/sbin/sleepwatcher</string>
		<string>-V</string>
		<string>-s /usr/local/etc/sleepwatcher/rc.sleep</string>
		<string>-w /usr/local/etc/sleepwatcher/rc.wakeup</string>
	</array>
	<key>RunAtLoad</key>
	<true/>
	<key>KeepAlive</key>
	<true/>
</dict>
</plist>
$ sudo cat >> /usr/local/etc/sleepwatcher/rc.wakeup << EOF
# Mount AFP Volume
sleep 5
open -a /Users/gumob/Applications/mount_all.app

EOF
7
10
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?