iPhoto / Image Capture Launch When Connecting a Camera

jamesdurler
Contributor

Hi guys,

I have a user requesting that whenever Students connect a camera to a mac that it does not automatically launch iPhoto or image capture.

This is an open access area where student accounts are wiped on logout so getting them to set this manually every time isn't really an option.

Does MCX even exist for something like this? I've done things using the user template before but I'm not quite sure where this preference lives.

Has anybody dealt with a request like this before?

Thanks

14 REPLIES 14

agurley
New Contributor II

I need help with this too. Actually, I wrote this exact issue down on my whiteboard over a year ago (it's still there!), did some research & tried a few things but was not successful. I believe the answer lies in the com.apple.ImageCapture plist in the ByHost folder; autolaunchApplicationPath key. Setting it to an empty string should do the trick, but I never was able to get this to work... I'd love some guidance. Or just a straight-up solution.

stevevalle
Contributor III

Hi
The file you need to edit is located

~/Library/Preferences/ByHost/com.apple.ImageCapture2.18A005D8-DCA6-5F28-9E05-39A4B8348DD0.plist (numbers at the end of the name will be different)

The section that changes when the iPhoto preference is changed is

<key>HotPlugActionPath</key>
    <string>/Applications/iPhoto.app</string>

You should be able to remove the <string> section and after a restart, the default app changes to "No Application"

Tested with iPhoto v9.5.1

** Edit: The problem you may face is the numbers on the end of the file name may be different.

ProfFrnswrth
New Contributor II

I know if you open iPhoto and go to Preferences you can just change the setting from there.

external image link

jamesdurler
Contributor

thanks for the responses. Pointed me in the right direction. I now have this working. I have basically created a package which drops the plist without the UUID appended into /var/tmp. I then have a post install script which appends the UUID to the plist and copies to the default user template.

This is the script if it helps anyone

#!/bin/bash

#Author James Durler
#Written 3/10/2014

#This script is deployed with the iPhoto No Launch When Connecting Camera.pkg. The package drops a plist
#which specifies to not launch iPhoto when the user plugs a camera in. The script then gets the machine UUID
#and then appends this to the end of the preference file as this plist exists in the byhost and appends UUID
#to the end of the plist. Once the name has been changed it then copies the new properly formatted file to
#the default user template.

#Revision 1.0 : Improved the system_profiler command time to return machine ID by running the command at detail #level basic

#path where the imagecapture2 plist is deployed by the package

filepath="/var/tmp/com.apple.imageCapture2.plist"

#grab the machine UUID

machineid=$(system_profiler -detailLevel basic | grep "Hardware UUID" | awk '{print $3}')

#append the UUID to the string .GlobalPreferences.

imagecapture="com.apple.ImageCapture2.$machineid.plist"

#copy to the default user template

if [ -d /System/Library/User Template/English.lproj/Library/Preferences/ByHost/ ]; then

#move the file from /var/tmp to the default user template
mv $filepath /System/Library/User Template/English.lproj/Library/Preferences/ByHost/$imagecapture

else

#Create the directory if it doesn't exist. I have seen some circumstances where the ByHost folder is not in the default user template

mkdir /System/Library/User Template/English.lproj/Library/Preferences/ByHost

#move the file from /var/tmp to the default user template
mv $filepath /System/Library/User Template/English.lproj/Library/Preferences/ByHost/$imagecapture

fi

#exit gracefully

exit 0

jamesdurler
Contributor

Anyone has any questions feel free to ask!

itupshot
Contributor II

@jamesdurler Hi James, do I have to delete the value in the initial key line from the plist too?

For example:

d2e0839216324feb80d3df33913bf606

mm2270
Legendary Contributor III

Hi James @jamesdurler you can improve the speed of the script quite a bit more if you drop system_profiler altogether in favor of ioreg. Here's the code to get the Mac's UUID:

ioreg -rd1 -c IOPlatformExpertDevice | awk -F'"' '/IOPlatformUUID/{print $4}'

bpavlov
Honored Contributor

@mm2270 How come ioreg is faster?

mm2270
Legendary Contributor III

@bpavlov Try them both and see.
I ran the system_profiler code in the script above as is to get the UUID on my Mac and it took several seconds to complete. I did not time it, but it was at least 4-5 seconds. Running the ioreg command it returns the UUID in about 1/2 second if not less.
system_profiler is always slow. I don't really know why though, you'd have to ask Apple about that :) I have noticed the first time it gets called when it hasn't been used in a while it takes a particularly long time. If you run the same command again right after it returns a result a little quicker, but that's probably just because the system_profiler code is being cached or something. Its always been a bit sluggish though, even when run repeatedly.

Edit: I should just note for the record that system_profiler can be run faster if you direct it to only print the section that you're interested in pulling info from, like this-

system_profiler SPHardwareDataType | grep "Hardware UUID" | awk '{print $3}'

Its still not quite as fast as ioreg, but much better.

itupshot
Contributor II

@mm2270 Thanks for that speed boost tip. I replaced the System Profiler line of the script with yours.

Do you know if I should delete that key value, though?

mm2270
Legendary Contributor III

@itupshot No problem. I don't know specifically because I haven't really tested out the script or this process. So I can't actually answer that.

agurley
New Contributor II

Revisiting this since I had some down time - big shout-out to @jamesdurler for the script and to @mm2270 for the ioreg tip. One important thing I encountered was that appending the complete UUID to the ImageCapture2 plist filename didn't work for my 10.9.x machines. I had to grab the last section of the UUID and just use that. Anyway, it appears to be working and for that I thank you. Seriously, this item has been on my to-do list for over a year.

jamesdurler
Contributor

glad you got it working :D

apizz
Valued Contributor

The challenge I'm finding here is that it seems the option to open a different app - like Image Capture - instead of Photos is device-specific, as the preference is tied to the device's specific ID.

Is there a way to get around this, or am I missing something?

I'm currently running the defaults -currentHost write com.apple.ImageCapture disableHotPlug -bool true command on a per user basis.

Ideally I'd like Image Capture to launch regardless of the camera device connected.