0

I use the mouse with my left hand and sometimes switch to the right hand. So, I need to frequently swap the mouse buttons.

I would like to know how to swap the mouse button using AppleScript. I am using a standard mouse.

There is an elegant solution here, that doesn't work anymore since I upgraded to MacOS Ventura:

tell application "System Preferences"
    reveal pane "com.apple.preference.mouse"
end tell
tell application "System Events" to tell process "System Settings"
    tell radio group 1 of window 1
        if value of radio button 1 is 1 then
            click radio button 2
        else
            click radio button 1
        end if
    end tell
end tell

I found the code here: Swap Mouse Button using AppleScript

The new error I get is:

Can’t get pane "com.apple.preference.mouse".

I guess it's because the System Settings are changed a lot in Ventura.

How can I change the code so it works for macOS Ventura?

10
  • Can you provide some details how it’s not working in Ventura?
    – Allan
    Apr 20, 2023 at 14:26
  • Thanks, @Allan , I have added that information now.
    – Zoe
    Apr 21, 2023 at 16:16
  • Have you seen this answer? It is said to work on Ventura. :)
    – Thinkr
    Apr 22, 2023 at 7:38
  • Thanks, @Thinkr. That JavaScript version actually works, it's just terribly slow. AppleScript is performing under the hood, while I do other things, so it's much easier to use.
    – Zoe
    Apr 22, 2023 at 16:47
  • superuser.com/a/1782251/333202
    – 1110101001
    May 3, 2023 at 21:58

1 Answer 1

1

This isn’t a direct answer to your question, but it should assist you in solving the problem with the correct pane name which should ultimately solve your issue

Try this code to get the name of your pane that you’re interested in. Make sure you have that particular pane open.


tell application "System Preferences"
    set AppleScript's text item delimiters to ", "
    set CurrentPane to the id of the current pane
    get the name of every anchor of pane id CurrentPane
    set CurrentAnchors to get the name of every anchor of pane id CurrentPane
    set the clipboard to CurrentPane
    display dialog "Current Pane ID: " & CurrentPane & return & return & "Pane ID has been copied to the clipboard." & return & return & "Current Anchors: " & return & (CurrentAnchors as string)
end tell

I cannot remember where I found this script, but I’ve used it in the past to find the names of the panes that I wanted to manipulate. Once I had the correct name, I put it in my actual script.

1
  • Thanks Allan! I tried the script and got this message: "Current Pane ID: com.apple.Mouse-Settings.extension Pane ID has been copied to the clipboard. Current Anchors: mouseTab" I tried to put "com.apple.Mouse-Settings.extension" into my Script and got the error: "System Settings got an error: Can’t get pane "com.apple.Mouse-Settings.extension"." Any ideas?
    – Zoe
    May 20, 2023 at 10:31

You must log in to answer this question.

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