tags:

views:

60

answers:

2

Hi all,

Can anyone suggest me:

How to set Primary Button, Secondary Button and other properties of Mouse Preference via AppleScript?

I have now tried this, script:

tell application "System Preferences"
    activate
end tell
tell application "System Events"
    tell process "System Preferences"
        click menu item "Mouse" of menu "View" of menu bar 1
        tell window "Mouse"
            set value of pop up button 1 to "Primary Button"
        end tell
    end tell
end tell

but it is giving this error message:

System Events got an error: Can't get pop up button 1 of window "Mouse" of process "System Preferences". Invalid index.

Can anyone suggest me where I may be wrong or some better trick to implement it?

Thanks,

Miraaj

A: 

goto system preferences, universal access pane, select "Enable access for assistive devices"

this needs to be enable on an mac that is going to run as script the uses GUI scripting

EDIT

now that you have done that you can change your script since it got an error, have your script click the radio button like so

  tell application "System Preferences"
   activate
   set current pane to first pane whose name is "Mouse"
  end tell

  tell application "System Events"
   tell process "System Preferences"
    try
     click radio button "Left" of every radio group of window "Mouse"
    on error theError
     --An error occured
     display dialog ("Sorry, an error occured while altering Keyboard and Mouse settings:" & return & theError) buttons "OK" default button "OK"
    end try
   end tell
  end tell

ADDITIONAL INFO

check out Scriptable System Preferences you may find that thread more helpful

mcgrailm
thanks for your reply... but now I am getting this error message: Can’t set «class actT» of "left mouse button" to "Primary Button", can you suggest me where I may be wrong?
Miraaj
thanks for the script... I tried it, but getting following error message: System Events got an error: Can't get radio group 1 of window "Mouse" of process "System Preferences". Invalid index :(
Miraaj
what version of mac os are you running ? do you have ui browser ?
mcgrailm
it is MacOSX 10.6.4.. no I don't have ui browser!
Miraaj
ok I edited my post try that
mcgrailm
the above script is not causing any error now :), but it is not performing the action which I want: to set some action say "Primary Button" to "Left Mouse Button" in Mouse Preference pane :(
Miraaj
thats what the script does its set the primary button to "Left" mouse change the click line to click radio button "Right" of every radio group of window "Mouse" and see it work
mcgrailm
thanx.. mcgrailm for the link, I will definitely look at it!
Miraaj
A: 

You need to do exactly what that error message says. Look under Universal Access in System Preferences, and you will see a checkbox for "Enable access for assistive devices". I'll leave it as an exercise to you to sort out how to enable that via Applescript.


Please post all of the relevant code. There are lot of reason why that might not work. The Universal Access pane may not be active, the button or the type may not be accessible via Applescript (the latter being more than likely).

Philip Regan
@Philip Regan lol you were 5 seconds ahead of me !
mcgrailm
I noticed that, too, but I thought you got in before I did. So, I guess you read through the questions first thing in the morning when you get into work like me?
Philip Regan
thanks for your reply... but now I am getting this error message: Can’t set «class actT» of "left mouse button" to "Primary Button", can you suggest me where I may be wrong?
Miraaj
@Philip Regan..you are correct!
mcgrailm