1

I think this is a bug in Mac OS X: with a dual monitor setup, the Dock switches to the 2nd (not main) monitor from time to time.

To fix this issue, I open the Dock, and click both the "Left" and "Bottom" radio buttons for the "Position on Screen" item.

I need to automate this with AppleScript. I could open the Dock using this script, but I'm not sure how to click the Left and then Bottom radio button in AppleScript.

tell application "System Preferences"
    set the current pane to pane id "com.apple.preference.dock"
    activate
end tell

I tried to add some code in the script, but it does not work.

click radiobutton "Left"

enter image description here

3
  • 1
    I'd suggest you use the Record button in Script Editor to have it generate code for you as you click the button you want. This will do two things: first, it will generate a working script, and second, you can learn from that script.
    – tubedogg
    Commented Oct 3, 2016 at 16:22
  • @tubedogg, the Record feature in the AppleScript Editor doesn't work at all in most cases and incompletely in other cases. Finder is one of the few apps it works with. Frankly, I've found it to be a useless feature. Commented Oct 3, 2016 at 16:30
  • @prosseek, I've updated my answer to work with OS X 10.11.6, as explained in the "Note:" at the bottom of my answer. Commented Oct 3, 2016 at 17:02

2 Answers 2

1

You can click the radio buttons in more then one way.

After the tell application "System Preferences" block use a tell application "System Events" block, e.g.:

tell application "System Preferences"
    set the current pane to pane id "com.apple.preference.dock"
    activate
end tell

tell application "System Events"
   click radio button 1 of radio group 1 of window 1 of process "System Preferences"
end tell

In this first usage, radio button 1 is Left, radio button 2 is Bottom and radio button 3 is Right.

Or:

tell application "System Preferences"
    set the current pane to pane id "com.apple.preference.dock"
    activate
end tell

tell application "System Events"
   click radio button "Left" of radio group 1 of window "Dock" of process "System Preferences"
end tell

In this second usage, use Left, Bottom or Right directly and you can also use Dock in place of window 1. (The latter of which you could do in any of these examples.)

Or:

tell application "System Preferences"
    set the current pane to pane id "com.apple.preference.dock"
    activate
end tell

tell application "System Events"
    click (every radio button whose value of attribute "AXTitle" is "Left") of radio group 1 of window 1 of process "System Preferences"
end tell

In this third usage, use Left, Bottom or Right for the value of (every radio button whose value of attribute "AXTitle" is "?") where the ? is one of these values.

Note: These examples have been tested under OS X 10.11.6 and work as now edited. I added
of radio group 1 between radio button and window. For use in OS X 10.8.5 remove of radio group 1 from the code.

3
  • None of the three code works for me (Mac OS X 10.11.6). The first example: Invalid index." number -1719 from radio button 1 of window 1 of process "System Preferences". The second example: Can’t get radio button \"Left\" of window \"Dock\" of process \"System Preferences\"." number -1728 from radio button "Left" of window "Dock" of process "System Preferences". The last example: missing value.
    – prosseek
    Commented Oct 3, 2016 at 16:40
  • @prosseek, These all work for me in OS X 10.8.5, which it want I'm using at the moment. I'll spin up an OS X 10.11.6 after lunch and see what's changed. Commented Oct 3, 2016 at 16:49
  • I just tested these under macOS sierra 10.12 and they work as written. Commented Oct 3, 2016 at 17:07
0

Rather than clicking buttons, something that is slower and more error-prone, it's better to change the settings directly using AppleScript.

To change set screen edge setting, run

tell application "System Events"
    tell dock preferences
        set properties to {screen edge:bottom}
    end tell
end tell

if you want it to go on the left, just exchange 'bottom' for 'left' above.

To get all possible settings, 'get properties' instead of set.

1
  • Is there documentation for this somewhere? I'd like to set the resolution of the display, but I'm having trouble discovering the correct references to use.
    – threed
    Commented Jul 10 at 22:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .