View difference between Paste ID: atC0j4az and P485zXmU
SHOW: | | - or go back to the newest paste.
1
set DeviceName to "Your Device"
2
3
tell application "System Events" to tell process "SystemUIServer"
4
	set bt to (first menu bar item whose description is "bluetooth") of menu bar 1
5
	click bt
6
	if exists menu item DeviceName of menu of bt then
7
		tell (first menu item whose title is DeviceName) of menu of bt
8
			click
9
			tell menu 1
10
				if exists menu item "Connect" then
11
					click menu item "Connect"
12
					return "Connecting..."
13
				else
14
					key code 53 -- hit Escape to close BT menu
15
					return "No connect button; is it already connected?"
16
				end if
17
			end tell
18
		end tell
19
	else
20
		key code 53 -- hit Escape to close BT menu
21
		return "Cannot find that device, check the name"
22
	end if
23
end tell