It's basically the same thing except it tells if there's an error.(GUI not enabled, no bluetooth detected)
So it's more user friendly.
Cheers!

Quote:

on try_again()
set try_again2 to false
set error1 to false

tell application "System Events"
if (UI elements enabled) then

tell application "System Preferences"
activate
tell application "Finder"
set visible of every process whose visible is true and name is "System Preferences" to false
end tell

try
set current pane to pane "com.apple.preferences.Bluetooth"

on error
set error1 to true
beep
activate
display dialog "An error has occurred!
Please make sure your bluetooth module is properly installed." buttons {"PM Unorthodox", "Try again", "OK"} default button 3 with icon caution
if the button returned of the result is "PM Unorthodox" then
quit
tell application "Safari"
activate
open location "http://forums.macrumors.com/private.php?do=newpm&u=68509"
end tell
else
if the button returned of the result is "Try again" then
quit
set try_again2 to true
else
quit
end if
end if
end try
end tell

if error1 is false then
tell application "System Events"
tell process "System Preferences"
click radio button 1 of tab group 1 of window 1
click button 1 of tab group 1 of window 1
end tell
end tell

tell application "System Preferences"
quit
end tell
end if

else
activate
display dialog "You have to enable have GUI elements enabled to use this script." buttons {"Enable GUI", "OK"} with icon note default button 2
if the button returned of the result is "Enable GUI" then
tell application "AppleScript Utility"
activate
end tell
end if

end if
end tell

if try_again2 is true then
try_again()
end if
end try_again
try_again()

__________________
Advertise your site, software, or service in this space and be seen over 100,000ish times per day by your target audience. Click here for info.

I'm looking for a small applescript who can allow me sending sms message via bluetooth with my Filemaker Pro database.
Not for sms by internet but i want to be able to use my bluetooth cellphone connection for that like with the Mac Address Book.

It's basically the same thing except it tells if there's an error.(GUI not enabled, no bluetooth detected)
So it's more user friendly.
Cheers!

Great script! I customized it a little so that I could use it as an iCal alarm to turn off bluetooth at the end of the day so I can save the battery life of my magic mouse (and if I am still working, I added a 'snooze'). I never turn off my computer because I have so many concurrent projects running all the time. I'd set an alarm to remind me to turn off the mouse every day, but I rarely remembered even then, so with this alarm, I added a give-up time so if I don't respond to the dialog, it turns off bluetooth anyway.

I took out your link because you need a macrumors account to see it, which I didn't want to require if I shared the script with others).

To turn bluetooth on with a keyboard shortcut, I installed http://www.red-sweater.com/fastscripts/ and mapped a similar script to F13. Note: Keyboard shortcuts don't apparently work in 10.6.x for the script menu, bluetooth menu, or even the recent items menu - I tried for hours with multiple restarts - web searches corroborated my findings.

Here's the modified script:

Code:

on try_again()
set response to (display dialog "Would you like to turn off bluetooth?
(to save the magic mouse battery life)" buttons {"Cancel", "Gimme an hour", "Turn Bluetooth Off"} with icon 1 default button 3 giving up after 600)
if gave up of response is true or button returned of response is "Turn Bluetooth Off" then
set try_again2 to false
set error1 to false
tell application "System Events"
if (UI elements enabled) then
tell application "System Preferences"
activate
tell application "Finder"
set visible of every process whose visible is true and name is "System Preferences" to false
end tell
try
set current pane to pane "com.apple.preferences.Bluetooth"
on error
set error1 to true
beep
activate
display dialog "An error has occurred!
Please make sure your bluetooth module is properly installed." buttons {"Try again", "OK"} default button 2 with icon caution
if the button returned of the result is "Try again" then
quit
set try_again2 to true
else
quit
end if
end try
end tell
if error1 is false then
tell application "System Events"
tell process "System Preferences"
if value of checkbox 2 of window 1 is 1 then
click checkbox 2 of window 1
click button 1 of window 1
end if
end tell
end tell
tell application "System Preferences"
quit
end tell
end if
else
activate
display dialog "You have to enable have GUI elements enabled to use this script." buttons {"Enable GUI", "OK"} with icon note default button 2
if the button returned of the result is "Enable GUI" then
tell application "AppleScript Utility"
activate
end tell
end if
end if
end tell
if try_again2 is true then
try_again()
end if
else if button returned of response is "Gimme an hour" then
delay 3600
try_again()
end if
end try_again
try_again()

I recently started experiencing a problem with my scripts for toggling bluetooth. I have them set up to be activated via both ScriptSaver and FastScripts. Neither appears to be working right now and I get this error when the script tries to manipulate the System Preferences pane for bluetooth:

Anyone know how to fix that? Since I had to set up via scriptsaver, it actually caused my screensaver to not activate all weekend and now I have burn-in on my monitor! It's not real bad, but when there are dark colors on the screen, I can see a burned in excel spreadsheet. Yikes! I didn't think monitors these days were subject to that kind of problem.

Anyway, I've been trying to debug this problem and cannot seem to figure it out.

Looks like some sort of system update added an alert window for whenever the bluetooth checkbox is unchecked in system preferences:

For the purposes of google, the alert window says "If you turn bluetooth off you might not be able to control the computer. For example, you won't be able to use a bluetooth keyboard or mouse. Are you sure you want to turn Bluetooth off?"

I noticed that my mouse was still active upon unlocking my screen when it should have been off, so my mouse battery has been draining fast, especially over the weekends.

The alert window is a prudent improvement, but I could not figure out how to reliably dismiss it. I was able to dismiss it via the script by adding an 'ignore application responses' block with a 'keystroke space', but that wouldn't work via scriptsaver. And I could not figure out how to click the alert window button to "Turn Bluetooth Off" via the script.

-- put "blueutil" in ressources folder of this script saved as Script-Bundle or Application
set blueutilpath to quoted form of (POSIX path of (path to resource "blueutil"))
-- or start with this line if "blueutil" installed:
-- set blueutilpath to "usr/local/bin/blueutil"
set sb to last word of (do shell script blueutilpath & " status")
if sb is "on" then
do shell script blueutilpath & " off"
else
do shell script blueutilpath & " on"
end if