Automate Bluetooth?

Hi there,
i'm new to Automator and i can't figure out why a simple(?) action doesn't work.

I'm trying to activate Bluetooth from the menu and then establish a connection to my mobile.
Sound easy, doesn't it... 😉

So... i start up Automator, start recording my actions (click on the Bluetooth menu item and then just click on "activate" in the pulldown menu).
If i run the recorded actions, only the click on the menu item occurs. All further actions will be reported as "Error" (Only beeps).

What am i doing wrong?

Regards,
Herry

Mac OS X (10.5.3)

Posted on Jun 29, 2008 4:11 PM

Reply
4 replies

Jun 29, 2008 5:33 PM in response to Herry

Well, it's not that simple - it's a lot easier to just click a couple of times in the menu extra. I am guessing that the "Enable access for assistive devices" box is checked in the System preferences > Universal Access, since at least the main menu is getting clicked. Using GUI scripting is a bit of a hack to begin with, and the menu extras (the menu items on the right side of the menu bar) aren't your regular menu items. Scripting the regular menus usually works OK if that is the only way to do it, but the menu extras can fail in a number of mysterious ways since they are built different.

The following AppleScript is an example of clicking an item in a menu extra, and can be run by itself or placed in a "Run AppleScript action. I don't have a mobile to test, so I used the "Open Bluetooth Preferences…" item - replace the menu item with the name of the item you want to click:

<pre style="
font-family: Monaco, 'Courier New', Courier, monospace;
font-size: 10px;
margin: 0px;
padding: 5px;
border: 1px solid #000000;
width: 720px;
color: #000000;
background-color: #FFDDFF;
overflow: auto;"
title="this text can be pasted into the Script Editor">
tell application "System Events" to tell process "SystemUIServer"
tell menu bar 1
set menu_extras to value of attribute "AXDescription" of menu bar items
repeat with the_menu from 1 to the count of menu_extras
if item the_menu of menu_extras is "bluetooth" then tell menu bar item the_menu
click
delay 0.5
click menu item "Open Bluetooth Preferences…" of front menu
delay 0.5
end tell
end repeat
end tell
end tell</pre>

Jun 29, 2008 6:33 PM in response to Herry

Herry wrote:
What am i doing wrong?


The answer to your question is simple:
Record mouse-clicks in a menu extra´s submenu does not work.
But you can realize it like this: Click on the menu extra and then use the keyboard to navigate to and activate the sub menu´s item (by using "arrow down" and "return")

A GUI Script works a bit more "safe" then an Automator-record, but not that "safe" at all. If there is any chance to avoid it, do not use it.
In your case maybe the best solution to use a command-line tool named blueutil

If you will give it a try, to run it from Automator you need the Run shell script action with the command: +/usr/local/bin/blueutil on+

And maybe later in the workflow
+/usr/local/bin/blueutil off+

Spażek

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Automate Bluetooth?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.