why does this work just when system prefs are open?

hi
i’m starting a script which accesses the system prefs pane but can’t get it to activate and go into the sharing section
it just errors,
But if i have system prefs open already it works ok

activate application "System Preferences"

tell application "System Events"
	tell process "System Preferences"
		application "System Preferences"
		tell menu bar 1
			tell menu bar item "View"
				tell menu 1
					click menu item "Sharing"
				end tell
			end tell
		end tell
	end tell
end tell

anyone any ideas

thanks

Hi pidge1,

There may be a better way but you can add the following before what you have now. This opens System Preferences and adds a delay for it to show up:


tell application "System Preferences"
	activate
	repeat until name of preferences window is "System Preferences"
		tell application "System Events"
			tell process "System Preferences"
				application "System Preferences"
			end tell
		end tell
	end repeat
	delay 2
end tell

I was trying to find a way to test for the menu item name. I tried to get it to wait for the View menu bar item to appear but I couldn’t get that working.

Why not use something like this?

tell application "System Preferences"
	activate
	set current pane to pane id "com.apple.preferences.sharing"
end tell

This will return a list of ids

tell application "System Preferences"
	launch
	return id of panes
end tell

Why is it this

set current pane to pane "com.apple.preferences.sharing"

instead of this?

set current pane to pane "com.apple.preference.sharing"--without the "s" at the end of "preferences"

as in

	set current pane to pane "com.apple.preference.quicktime"

Thanks for the script to get pane IDs, by the way.

j

I think that’s a question for Apple.

Well, at least your script will prevent some head scratching on my part, thanks.

j

This works too:

tell application "System Preferences" to set current pane to pane "Sharing"

According to Script Debugger, the “Pane” class has a property “name” which is “name of the preference pane as it appears in the title bar”.

Hey Guys

Thanks for all the solutions.

All of the properties are listed in System Preferences’ dictionary. Note, however, that ˜name’ may vary depending on the current language. The ˜id’ property is the locale indepentant name.