Using USB Storage devices is very common nowadays. It has made data transfer so easy and fast. We are now able to carry upto 32GB of data in our palm.
Wouldn't it be nice, if the mounted i.e inserted USB triggers the action it's meant out to. Yes, it's possible in your system. For example,on insertion of a USB data card, the corresponding launch application or browser application can be opened or on insertion of a USB or pen-drive, or auto backup or copying/scanning files or playing music or video or photos can be done.
There are three ways to do this in a Mac. They are
- Using Launch Agent
- Using Folder Actions
- Using Third Party Apps
I will explain the first one and will share the links to the other two.
Launch Agent (launchd, launchctl) :
Here are some useful links where you can know what it is.
-> Apple Site
-> Wiki
1. Open textedit and add the following code,
#!/bin/bash
if [ -d "/Volumes/<Your_USB>" ]; then
say -v bell ding dong
open /Applications/<YourAppName>.app
fi
Replace YourAppName with any applications installed in your mac,which you want to open when usb is inserted and save it as mount.sh(sh stands for shell script), Copy it to "/Users/<Your_User_Account>/Library/Scripts/"
2. Open textedit and add the below code,
--------------------------------------------------------------------------------------------------------
<?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">
<dict>
<key>Label</key>
<string>com.usb.mount</string>
<key>LowPriorityIO</key>
<true/>
<key>Program</key>
<string>/Users/<Your_User_Account>/Library/Scripts/mount.sh</string>
<key>ProgramArguments</key>
<array>
<string>com.usb.mount</string>
</array>
<key>WatchPaths</key>
<array>
<string>/Volumes</string>
</array>
</dict>
</plist>
--------------------------------------------------------------------------------------------------------------
and save it as a plist file with name as the same value given for label in plist code, i.e. com.usb.mount.plist and place it in /Library/LaunchAgents
3. Now log out the current user and login again.
4. Open terminal and type the below command, to verify if your plist file is listed in there,
launchctl list
Thats' it. done. Boom !! Now each time you insert the usb drive a bell sound rings and starts out your app..
Folder Actions :
Please refer these links
Third Party Apps :
There are tools like MarcoPolo, Do Something when etc.,
References :
No comments:
Post a Comment