Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Is it possible to open a program when connecting an external hard drive?

Is it possible to open a program when connecting an external hard drive?


I have a external hard drive with an iphoto library. I just want to connect my drive and automatically see iphoto open! Possible?


I know there are some action scripts, am i right?

MacBook Air, Mac OS X (10.7.3)

Posted on Dec 27, 2012 4:44 PM

Reply
14 replies

Dec 27, 2012 5:00 PM in response to fraveu

Yes you can do this. I've written about how to do this to automatically change the Safari download folder when a drive is connected, but a similar approach can be taken to have the system launch iPhoto whenever a specific drive (or any drive) is attached.


http://reviews.cnet.com/8301-13727_7-20101099-263/applescript-fun-automatically- changing-safaris-downloads-folder/


I have to book it right now, but if later on I can write up a small edit to these steps that will have them work in your situation, if you are not able to figure out how to do this on your own from the steps in that article.

Dec 28, 2012 3:09 PM in response to fraveu

Ok, here are the steps to take. Doing this involves generating two scripts, the first of which will have the system monitor the attachment of a hard drive, and the second which will conditionally open iPhoto. To make these and set them up, perform the following steps (it is a little involved, but will get you the result you want):


Script 1: A launch agent to monitor attached hard drives


1. Open the Terminal utility in the /Applications/Utilities/ folder. Then copy and paste the following command into it and press Enter, which will open up an editor program in the Terminal:


pico ~/Library/LaunchAgents/iphotodrive.plist


2. Now copy and paste the following text to the Terminal window in its entirety so it is all entered into the Terminal editor:


<?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.iPhotoDrive</string>
          <key>QueueDirectories</key>
          <array/>
          <key>WatchPaths</key>
          <array>
                    <string>/Volumes</string>
          </array>
          <key>ProgramArguments</key>
          <array>
                    <string>/Users/USERNAME/Library/iphotodrive.sh</string>
          </array>
</dict>
</plist>


3. Use the arrow keys to navigate your cursor down to the place where it says /Users/USERNAME/Library..., and change the text of "USERNAME" to be the same name as your account home folder. For example, my login name in OS X is "tkessler" so my home folder is also "tkessler," so for me this is what should go in place of "USERNAME" in the text above.


4. Now press Control-O to save the file, and then Control-X to exit the editor (use Control, and not the standard Command key here).



Script 2: A shell script to open iPhoto when your drive is attached


1. Type (or copy and paste) the following command in the same Terminal window to make the second script in the same editor:


pico ~/Library/iphotodrive.sh


2. Now copy and paste the following text into the Terminal editor:


#/bin/bash

if [ -d /Volumes/"IPHOTODRIVE" ]; then
        open -a iPhoto;
fi


3. Again use the arrow keys to navigate, and edit the text IPHOTODRIVE to be the exact name of the drive you would like to spur iPhoto to open. The name will be case-sensitive, and spaces are OK within the quotes.


4. Again save this file by pressing Control-O, then press Control-X to quit the editor.


5. Next ensure this new script can be run, so to do this now copy and paste the following command:


chmod +x ~/Library/iphotodrive.sh



Now to activate these scripts you can log out of your account and log back in, and they should work as expeted, and will launch iPhoto only when a drive named "IPHOTODRIVE" (or whatever you edited this entry to be) is attached to the system. This procedure will create two files at the following locations on your computer, so to undo it simply remove these two files followed by logging out and back in, and you should be good to go:


/Users/USERNAME/Library/iphotodrive.sh

/Users/USERNAME/Library/LaunchAgents/iphotodrive.plist


If you run into any problems, then write back here and we can figure out if there are any nuance details to cover for your setup.

Dec 28, 2012 7:12 PM in response to fraveu

Yikes! ok...you can do the following to prevent it from continually opening iPhoto. Its odd that it should do this, but it is...


1. Open the Terminal and edit the shell script file by running the following command:


pico ~/Library/iphotodrive.sh


2. Modify it so it looks like the following (or simply erase its contents and copy and paste the following):



#/bin/bash

killall -d iPhoto &> /dev/null

if [ -d /Volumes/"IPHOTODRIVE" ] && [ $? ]; then
        open -a iPhoto;
fi



3. Press Control-O followed by Control-X to save and exit, and then the script should run both contitionally on the presence of the drive and only do so when iPhoto is not running. If iPhoto is running then the script should not do anything.


I'll think about this more, but the one problem here that is not addressed is that if you quit iPhoto then as long as the drive is attached then this script will run and re-launch the program, so one approach is to remember to unmount the drive first and then quit the program.

Dec 29, 2012 7:56 AM in response to fraveu

That is very bizarre that it is continually running and invoking iPhoto. Do you have many external hard drives and other attached storage drives (even network shares) set up on your system? If it is blocking your work you can drag the iPhoto window to be smaller temporarily and then edit the script file to be as I mentioned below. Saving this will then have it run conditionally on iPhoto's running status so it does not always load the program and bring it to the front.

Is it possible to open a program when connecting an external hard drive?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.