system preferences

I’m trying make a simple script to open System Preferences and display the Network pane.

Sounds simple enough, but I can’t seem to do it. What’s my problem?

I hate it when it turns out to be so easy…

And thanks for not giving the obvious answer to “What’s my problem?”… much appreciated.

Thanks

I’m trying to open the Date & Time pane in System Preferences. Do you know how to select that pane?

Thanks.

tell application “System Preferences”
activate
set current pane to pane “com.apple.preference.datetime”
end tell

Hi,

To get a pane’s name, run System Preferences and open the pane you want. In Script Editor run this and look at the result:

tell application “System Preferences”
get name of current pane – get is optional
end tell

Then use the name to set the pane:

tell application “System Preferences”
set current pane to pane “com.apple.preference.datetime”
end tell

gl,

Of course, you can also get all the names at once:

Jon


[This script was automatically tagged for color coded syntax by Convert Script to Markup Code]

Thank you so much for the help. I have been trying to figure the pane name out for weeks.

I am trying to get the script to adjust the transparency of the Window Clock. I can get to the proper tab in the pane, but can’t figure out how to select and move the transparency bar. Any ideas?

Hi,

Do you mean you’re trying to set the transparency for the “Clock” application?

gl,

Hi,

If it’s the Clock.app you’re working with, then here’s an example that gets the possible values of the slider and resets it. You can run it in Script Editoy and look at the result to see the possible values:

tell application “Clock” to activate
tell application “System Events”
tell process “Clock”
tell menu bar 1
tell menu “Clock”
click menu item “Preferences…”
end tell
end tell
tell window “Clock Preferences”
tell radio group 2
click radio button “in a floating window”
end tell
tell slider 1
set cur_val to value
set min_val to minimum
set max_val to maximum
set value to min_val
set possible_values to {min_val}
repeat until (value is max_val)
increment
set end of possible_values to value
end repeat
set value to cur_val – resets the value to original value
end tell
end tell
end tell
end tell
return possible_values

gl,

Thank you for your suggestions. I have tried to run them in a script but cannot compile error free. I cannot find a clock.app on my system. I am running Script Editor 2.0 on OSX 10.3.4. The closest I can come is a plist called MenuBarClock.plist, which has a Transparency value in it.

Here is what i am trying to do. Open System Preferences, go to the Date & Time Pane, select the tab labled Clock and then select the Transparency slider and move it to a higher value, then close System Preferences. I have tried modifying the script you suggested to fit what I think would work but I cannot get an error free compile.

For example. it cannot find the application “Clock” so I changed it to “WindowClock” and it compiles. However I get the following error when I run:

System Events got an error: NSReceiverEvaluationScriptError: 4

This error is associated with the line:

click menu item “Preferences…”

I do not have a menu item called “Preferences…” so that’s why I assume your script works with a different OS.

I tried editing the script to match what I think are the correct instructions, but continue to get run errors.

Any additional light you can shed would be greatly appreciated.

Thanks.

JB

Hi JB,

Sorry, I’m running Jaguar 10.2.8 and didn’t know they placed the clock or transparency in System Preferences. In Jaguar there is a seperate Clock.app that you can set to open in a window with transparency.

gl,

Thanks for your time on this anyway. I still may be able to figure it out. Could you please tell me in your suggested script, what exactly do these two lines mean?

tell radio group 2
tell slider 1

I assume that the first line selects the 2nd radio button and the second line selects the first slider. Can you please confirm?

JB

Hi,

Basically, tell statements are used to state the target of commands. The basic structure of ui scripting is this:

tell application “iCal” to activate – runs iCal or brings it to front
tell application “System Events”
tell process “iCal”
– your stuff here
end tell
end tell

At this point, you could see all the ui elements of process “iCal” with this:

tell application “iCal” to activate – runs iCal or brings it to front
tell application “System Events”
tell process “iCal”
get UI elements – get is optional
end tell
end tell

and looking at the result, you find that menu bar 1 is an element of process “iCal”. Now if I type this:

tell application “iCal” to activate – runs iCal or brings it to front
tell application “System Events”
tell process “iCal”
tell menu bar 1
get UI elements
end tell
end tell
end tell

the result show that menu “View” is an element of menu bar 1 of etc… In the statement:

get ui elements

‘get’ is the command, ‘ui elements’ is the direct parameter, and the target in the later script is menu bar 1 of application process “iCal” of application “System Events”. Say I want to do something with the “View” menu. Here’s an example:

tell application “iCal” to activate
tell application “System Events”
tell process “iCal”
tell menu bar 1
tell menu “View”
click menu item “Week view”
click menu item “Go to Date…”
end tell
end tell
–keystroke “14”
–keystroke return
end tell
end tell

This opens up the “Go to Date” window and I could use keystrokes to select a certain day. Similarly, this would also work:

tell application “iCal” to activate
tell application “System Events”
tell process “iCal”
click menu item “Week view” of menu “View” of menu bar 1
click menu item “Go to Date…” of menu “View” of menu bar 1
–keystroke “14”
–keystroke return
end tell
end tell

Notice how the text:

of menu “View” of menu bar 1

is repeated. So, ‘tell’ statements are used to state the target of your commands. In the later script ‘click’ is the command and the targets are the objects menu item “Week view” and menu item “Go to Date…”. The ‘tell’ statement allows you to not need to write out the complete reference to an object over and over again.

Note that there are different ways to reference objects. For instance, menu bar 1 is a partial reference by index (the number 1). If menu bar 1 had a name like “MyMenu” and you could reference it by name, then you could write:

menu bar “MyMenu” of process “iCall” etc.

gl,

Thanks so much for taking the time to explain. I sincerely appreciate the help.

JB