Currently Being ModeratedDec 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.
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.
Currently Being ModeratedDec 27, 2012 10:04 PM (in response to fraveu)
Do you want just this drive to cause iPhoto to open, or any drive you attach to cause the program to open?
Currently Being ModeratedDec 28, 2012 1:10 PM (in response to Topher Kessler)
Just this one...
Currently Being ModeratedDec 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:
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:
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:
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.MacBook Pro, OS X Mountain Lion (10.8.2), 17", 2.5GHz i7, 16GB RAM, 512GB SSD
Currently Being ModeratedDec 28, 2012 5:47 PM (in response to Topher Kessler)
It does work... but it keeps opennig iPhoto over and over... It keeps bringing iPhoto to front as well... I cant even write this post properly! lol
Currently Being ModeratedDec 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:
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.MacBook Pro, OS X Mountain Lion (10.8.2), 17", 2.5GHz i7, 16GB RAM, 512GB SSD
Currently Being ModeratedDec 28, 2012 7:14 PM (in response to fraveu)
These replies might be emailed to you by Apple's systems. I made a typo in that last script which would prevent it from working. I updated it just now, so it should work again.
Currently Being ModeratedDec 28, 2012 7:16 PM (in response to Topher Kessler)
One last edit...make that last script where it says [ $? ], change this to be the following:
[ $? == 1 ]
Currently Being ModeratedDec 28, 2012 7:32 PM (in response to fraveu)
Ugh...sorry about this. I'm mixing up scripting approaches here. The last script should be the following, so you can edit it as mentioned above and ensure its contents are as follows:
#/bin/bash killall -d iPhoto &> /dev/null STATUS=`echo $?` if [ -d /Volumes/"IPHOTODRIVE" ] && [ "$STATUS" -eq 1 ] ; then open -a iPhoto; fiMacBook Pro, OS X Mountain Lion (10.8.2), 17", 2.5GHz i7, 16GB RAM, 512GB SSD
Currently Being ModeratedDec 28, 2012 7:42 PM (in response to Topher Kessler)
I think those scripts should start with
Currently Being ModeratedDec 28, 2012 7:47 PM (in response to softwater)
Yes you're correct. It wont necessarily hurt anything to not to have this since the default interpreter for a user's account is already bash, but the proper syntax for this is indeed #!/bin/bash
I'm having one of those days where every word is a typo...the delete key is getting abundant exercise.
Currently Being ModeratedDec 28, 2012 8:08 PM (in response to Topher Kessler)
BTW, you probably already know this, but a safer way to provide scripts online is to put them in pastebin, then provide a link to it from here. That way, you can avoid the limitations of ASC timeout on editing posts and correct the script on pastebin as necessary.
I learned that one the hard way too!
Currently Being ModeratedDec 29, 2012 2:08 AM (in response to Topher Kessler)
Well... There is a catch here. I can't eject the drive since its been used by iPhoto and when I quit iPhoto it just open it again...
I haven't test the last script yet, btw. I'm taking your comments here...
Currently Being ModeratedDec 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.