Try this
tell application "Firefox"
activate
tell application "System Events"
keystroke tab
keystroke (key code 125)
keystroke (key code 125)
keystroke (key code 125)
end tell
end tell
You might not need to activate Firefox if it's the current active app. Them you just need :
tell application "System Events"
keystroke tab
keystroke (key code 125)
keystroke (key code 125)
keystroke (key code 125)
end tell
Updated/Better Answer:
1) This new script doesn't flash.
2) For reasons unbeknownst to man and logic (or just me), applescript sometimes/almost-always fails to Turn Bluetooth Off, if the System Preference window is in the background. Instead of turning off, what actually occurs is that Bluetooth immediately re-enable itself, so the pane is in a fresh state: it's ON, but no connections.
To overcome that, one way to to bring SysPref to the front, as in the original answer. Or, run a loop that click the button again (or for a 3rd time) until Bluetooth is really off. That's why there are two variables and a loop in the script. This should make the script more reliable. statName
variable records the original status. Loop
will continue clicking the button until status has changes. failSafe
makes sure the script will not run forever in case of error. All at the cost of aesthetics of the code.
tell application "System Events"
tell process "System Preferences"
activate
end tell
tell application "System Preferences"
set current pane to pane "com.apple.preferences.Bluetooth"
end tell
tell process "System Preferences"
set statName to name of button 3 of window 1 as string
set failSafe to 0
repeat until statName is not name of button 3 of window 1 as string ¬
or failSafe is 10
click button 3 of window 1
set failSafe to failSafe + 1
delay 0.1
end repeat
end tell
tell application "System Preferences"
quit
end tell
end tell
Original Answer:
tell application "System Preferences"
activate --Change 1/2
reveal pane "com.apple.preferences.Bluetooth"
end tell
tell application "System Events" to tell process "System Preferences"
click button 3 of window 1 --Change 2/2
end tell
quit application "System Preferences"
From Accessibility Inspector:
button 3
in the the no.6 item on the list. The 6th button is no.11 in the list. When you call button 6
Preference Window goes Genie. I guess Mavericks had all the buttons bunched up at the front.
Best Answer
You can check the components of the UI interface of the application you're trying to script with the "UI elements" command
you can then drill down the list to find where the required item is
actually using the Accessibility Inspector app (part of Xcode) can help you to identify which element to inspect
For our purposes, it looks like the popup we are interested into is the pop up button 2 of tab group 1 of window "Keyboard"
Since it is a pop up, to interact with its menu, you have to click on it and then to select the item you want to activate. It can be done by specifying the whole label of the menu item to click, I preferred to simulate the keystrokes needed to switch the selection (either the up or down arrow and then the return)...
by the way, in another question, someone noticed that if you don't activate the System Preferences app, the scripts will still work but without showing its window (you will still see the popup menu being switched, though)