Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Disable iPhoto sharing via AppleScript Apps
I needed an automated way to disable/enable iPhoto sharing with ControlPlane. I used GUI scripting in AppleScript to accomplish this task. The most recent version of the script below can be found here.

How to run it: osascript toggle_iphoto_sharing.scpt "disable" "no"
- the first parameter is the status to set sharing to - disable or enable
- the second parameter is whether or not to start iPhoto to make the change
Note: iPhoto must be running for this script to change anything.

on appIsRunning(appName)
	tell application "System Events" to (name of processes) contains appName
end appIsRunning

on run argv
	set a_stat to (item 1 of argv)
	#set a_stat to "disable"
	
	set start_iphoto to (item 2 of argv)
	
	set do_work to "no"
	
	if not appIsRunning("iPhoto") then
		if start_iphoto is equal to "yes" then
			set do_work to "yes"
		end if
	else
		set do_work to "yes"
	end if
	
	if do_work is equal to "yes" then
		
		tell application "iPhoto" to activate
		tell application "System Events"
			tell process "iPhoto"
				click menu item 3 of menu "iPhoto" of menu bar 1
				click button "Sharing" of tool bar 1 of window 1
				
				if value of checkbox "Share my photos" of group 1 of group 1 of window 1 is equal to 1 then
					if a_stat is equal to "disable" then
						click checkbox "Share my photos" of group 1 of group 1 of window 1
					end if
				else
					if a_stat is equal to "enable" then
						click checkbox "Share my photos" of group 1 of group 1 of window 1
					end if
				end if
				
				click button 1 of window 1
				
			end tell
		end tell
		
	end if
	
end run

    •    
  • Currently 3.80 / 5
  You rated: 3 / 5 (5 votes cast)
 
[3,335 views]  

Disable iPhoto sharing via AppleScript | 5 comments | Create New Account
Click here to return to the 'Disable iPhoto sharing via AppleScript' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Disable iPhoto sharing via AppleScript
Authored by: mr. applescript on Jun 22, '12 08:31:05PM

Just a quick FYI. To execute a script only if a particular application is running, try using the "running" property of application objects:

if running of application "iPhoto" is true then
-- do something
end if

This was introduced a couple of OS releases ago. You no longer have to compare a name against a list of running application processes. Cheers!



[ Reply to This | # ]
Disable iPhoto sharing via AppleScript
Authored by: dhaskew on Jun 23, '12 12:13:19PM

Thanks for the tip!



[ Reply to This | # ]
Disable iPhoto sharing via AppleScript
Authored by: hypercat on Jun 25, '12 09:48:02AM

I would caution against using:

if running of application "Some App Name" then
-- do something
end if

since if "Some App Name" is not the correct name for the app (i.e. "Filemaker Pro 11" but the app on your system is named "Filemaker Pro 11 Advanced") then you will get the dreaded "Choose Application" modal dialog box asking you "Where is Some App Name?"

One way to avoid the "Choose Application" modal dialog box is to use the application id (creator code):

set nonsense_app_id to "zzxx"
set filemaker_pro_app_id to "FMP7"
set sublime_text_app to "subl"

IsAppRunning(sublime_text_app)

on IsAppRunning(the_app_id)
set is_running to false
try
if running of application id the_app_id is true then
set is_running to true
end if
on error errMsg number errNum
-- if the application id is not recognized then error -1728 is generated
set is_running to false -- unrecognized apps are not running by default
end try
return is_running
end IsAppRunning



[ Reply to This | # ]
Disable iPhoto sharing via AppleScript
Authored by: dhaskew on Jun 25, '12 05:58:43PM

I thought creator codes, and correct me if I am mistaken, where phased out in Lion. Or the phase out was started anyway. Is that not so? I remember some conversation around this topic when Lion was released. What might I have been thinking of?



[ Reply to This | # ]
Disable iPhoto sharing via AppleScript
Authored by: hypercat on Jun 29, '12 02:54:25PM

Creator codes are still used in Lion and you can use the creator codes to identify an application in Lion.

What changed in the OS since Snow Leopard is that files no longer use the creator code to determine which application to use to open the file.

Much more info on this topic is here:
http://tidbits.com/article/10537



[ Reply to This | # ]