I have a USB modem which is mounted as say XYZ(which contains the Dialer Software and Readme) when its inserted. In order to connect using it, I have to eject it and then connect it using ppp dialer.
Let us say that it mounts under the name /Volumes/XYZ
I want to do something like if I insert a USB device and it mounts under the name XYZ, I want it to be ejected immediately.
How do I do that?
Answer
I did something similar once upon a time, where whenever a drive named a certain way was mounted, a script immediately fired off to sync the contents of a set of folders to the drive.
To do something similar here, the script would need to look like this:
#!/bin/bash
if [ -d /Volumes/XYZ ];
then
echo “Ejecting XYZ!”;
umount /Volumes/XYZ
exit;
fi
Save it somewhere, your ~/bin/
directory if you have one, or maybe ~/Library/Scripts/
, just remember where.
The second piece of the puzzle is the LaunchAgent that will actually handle the event whenever a drive is mounted:
Label
com.superuser.226504.example
ProgramArguments
/Path/To/Script/unmount-modem.sh
QueueDirectories
StartOnMount
WatchPaths
That needs to be saved as a .plist (named similar to the string used in place of “com.superuser.226504.example”) and saved to ~/Library/LaunchAgents
. You can either load it from the terminal via launchctl load ~/Library/LaunchAgents/pathtoplist
or log out / log back in and it should get loaded if everything is configured properly.
No comments:
Post a Comment