Last Updated: February 25, 2016
·
805
· sjodet

Automatically mount an external drive when launching iPhoto

My main PC is a MacBook Air. The SSD in it is not very large but my iPhoto library is.
In order to plug and unplug my MacBook Air as fast as possible, I wanted to mount the USB drive where my iPhoto library is only when I use iPhoto.

VOL='/dev/'$(diskutil list | grep -Eo '.*Apple_HFS Pictures.*' | grep -Eo 'disk.s.')
hdiutil mountvol $VOL
open -W /Applications/iPhoto.app
hdiutil detach $VOL

The first line parses the diskutil list command return to get the identifier for my USB drive. It is named "Pictures" and is formatted with "Apple_HFS" format. Just run the command manually and change "Apple_HFS Pictures" with whatever name and format you chose.

The second line mounts the drive.

The third line launches iPhoto. The -W option is important, it tells open to wait for the app to quit before returning.

The last line unmounts the drive.

Just drop this code into Automator to create an Application.

Picture