I found a different solution here - http://automagical.livejournal.com/4117.html#cutid1 - it uses the bluetooth menu extra, so check “Show Bluetooth in the menu bar” in System preferences if you haven’t already.
--http://automagical.livejournal.com/4117.html#cutid1
tell application "System Events" to tell the front menu bar of process "SystemUIServer"
try
click bt_menu
tell the second menu item of the front menu of bt_menu to if title contains "Bluetooth" then
click
else
error
end if
on error
repeat with x in menu bar items
click x
try
if the title of the first menu item of the front menu of x starts with "Bluetooth" then exit repeat
end try
end repeat
set bt_menu to x
try
tell the second menu item of the front menu of bt_menu to if title contains "Bluetooth" then
click
else
error
end if
on error
click bt_menu
display alert "Bluetooth Menu Extra not found."
end try
end try
end tell
I got some help from MacRumors and it works great.
tell application "System Preferences"
activate
end tell
tell application "System Preferences"
activate
set current pane to pane "com.apple.preferences.Bluetooth"
tell application "System Events"
if (UI elements enabled) then
tell process "System Preferences"
try
click radio button 1 of tab group 1 of window 1
click button 1 of tab group 1 of window 1
tell application "System Preferences"
quit
end tell
return 1
on error
return 2
end try
end tell
else
return 0
end if
end tell
end tell
I thought I tried that. I switched to “button 1” etc., before I found the script I posted. Oh well.
Thanks for posting the solution.
j
You know, now that I have found exactly what I am looking for. I realize I was looking for the wrong thing. Or well, not the wrong thing but not everything I need.
Cause now that I’m saving space in my menu bar I realize that I don’t know when I have airport or bluetooth on or off. So I would have to either toggle it twice or as I have now decided. What if I could set a Growl Notification Status script? Is this too ambitious? I’m currently looking at how to operate Growl.
I don’t use Growl, so can’t help with that.
I rewrote the Airport script. Now it speaks Airport’s status (on or off) and a dialog pops up asking if you want to turn it on/off. The default button is “Cancel” so you can hit return to stop the script, leaving Airport as is, but the dialog gives up after 5 seconds, and the script will continue.
It may not be quite what you want, but it works and is as unobtrusive as I could make it under the circumstances. i haven’t tried this on your Bluetooth script - that’s a bit more work.
tell application "Internet Connect"
activate
tell application "System Events"
tell window 1 of process "Internet Connect"
tell button "Airport" of tool bar 1
click
end tell
if exists button "Turn AirPort On" then
tell application "Internet Connect" --brings the following dialog window to the front, allowing you to hit the return key to cancel, otherwise you'd have to click on the dialog window to bring it to the front - as I had to do in my first attempt.
say "Airport, iz, off"
display dialog "Turn Airport on?" default button "Cancel" giving up after 5 --script will continue and turn on Airport if you don't cancel
end tell
tell button "Turn Airport On"
click
end tell
say "Airport, On"
else
tell application "Internet Connect" --brings the following dialog window to the front
say "Airport , iz , on"
display dialog "Turn Airport off?" default button "Cancel" giving up after 5 --script will continue and turn Airport off if you don't cancel
end tell
tell button "Turn Airport Off"
click
end tell
say "Airport, Off"
end if
end tell
end tell
quit
end tell