Sunday, June 16, 2019

#1 2007-08-11 03:20:08 am

StefanK
Member
From:: St. Gallen, Switzerland
Registered: 2006-10-21
Posts: 11563
Website

Pair your Bluetooth Mouse automatically

Apple's Mighty Mouse is a great device, but you have to clean it periodically.
Sometimes I do it during work, if one direction is starting to "stutter".
This script can reconnect the mouse quickly. Using FastScripts (or something like that) you can run it from the keyboard.

Applescript:

activate application "Bluetooth Setup Assistant"
tell application "System Events"
   tell process "Bluetooth Setup Assistant"
       tell window 1
           click button 4 -- button "Continue"
           delay 1
           click button 4 -- button "Continue"
           repeat until exists static text 3 of group 1
               delay 0.5
           end repeat
           repeat until (count rows of table 1 of scroll area 1 of group 1) > 0
               delay 0.5
           end repeat
           tell button 4
               click -- button "Continue"
               set n to its title
               repeat while its title is n -- wait until the button change to "Quit"
                   delay 0.5
               end repeat
               click -- button "Quit"
           end tell
       end tell
   end tell
end tell

PS: the script shoud work independent of any localization


regards

Stefan


Filed under: System

Offline

 

#2 2007-08-11 10:08:27 am

Adam Bell
Administrator
From:: Nova Scotia, Canada
Registered: 2005-10-04
Posts: 4665

Re: Pair your Bluetooth Mouse automatically

I didn't follow this through because I only have one bluetooth device to test on: my phone, but your elegant script can be generalized as follows: (untested, and, of course, linguistically sensitive)

Applescript:

tell application "System Events" to if exists process "Bluetooth Setup Assistant" then quit application "Bluetooth Setup Assistant"
set chosen to character 1 of ((choose from list {"1. Mouse", "2. Keyboard", "3. Mobile Phone", "4. Printer", "5. Headset", "6. Any Device"}) as text) as number -- returns an integer from 1 to 6
activate application "Bluetooth Setup Assistant"
tell application "System Events"
   tell process "Bluetooth Setup Assistant"
       tell window 1
           click button 4 -- button "Continue"
           delay 1
           click radio button chosen of radio group 1 of group 1 -- chosen is number of the device.
           click button 4 -- button "Continue"
           repeat until exists static text 3 of group 1
               delay 0.5
           end repeat
           repeat until (count rows of table 1 of scroll area 1 of group 1) > 0
               delay 0.5
           end repeat
           tell button 4
               click -- button "Continue"
               set n to its title
               repeat while its title is n -- wait until the button change to "Quit"
                   delay 0.5
               end repeat
               click -- button "Quit"
           end tell
       end tell
   end tell
end tell


iMac running OS X 10.13.1


Filed under: System

Offline

 

#3 2007-08-11 10:30:25 am

StefanK
Member
From:: St. Gallen, Switzerland
Registered: 2006-10-21
Posts: 11563
Website

Re: Pair your Bluetooth Mouse automatically

Very nice, Adam, thank you for the enhancement big_smile


regards

Stefan

Offline

 

#4 2008-01-16 04:29:35 pm

mtyers
Member
Registered: 2008-01-16
Posts: 1

Re: Pair your Bluetooth Mouse automatically

Hi
The script looks almost perfect but I have become stuck on a few bits.

I was trying to create a script to pair my bluetooth headset but when I run the script it stops at the point where I have to enter a pass code. I have tried modifying the script but to no avail - I have only been using Applescript for a very short time sad

The final task I am attempting is to unpair my headset.

Basically if I go out of range it screws up the settings so I thought the best solution would be to automate the unpairing and subsequent repairing of the headset.

Any help is greatfully received

many thanks

Mark

running Leopard

Offline

 

#5 2008-01-17 01:41:49 pm

Adam Bell
Administrator
From:: Nova Scotia, Canada
Registered: 2005-10-04
Posts: 4665

Re: Pair your Bluetooth Mouse automatically

Hi, Mark;

Show us your code so far and perhaps we can help (don't include your real pass code if it's there).


iMac running OS X 10.13.1

Offline

 

#6 2008-01-17 02:24:18 pm

StefanK
Member
From:: St. Gallen, Switzerland
Registered: 2006-10-21
Posts: 11563
Website

Re: Pair your Bluetooth Mouse automatically

Hi,

here is a modified script to pair a headset.
I also tried to write a script to disconnect the headset (UI scripting of System Preferences), but I got a couple of kernel panics.
So I gave up!

Applescript:


property pass : "0000"

activate application "Bluetooth Setup Assistant"
tell application "System Events"
   tell process "Bluetooth Setup Assistant"
       tell window 1
           click button 4 -- button "Continue"
           delay 1
           click radio button "Headset" of radio group 1 of group 1
           click button 4 -- button "Continue"
           repeat until exists static text 3 of group 1
               delay 0.5
           end repeat
           repeat until (count rows of table 1 of scroll area 1 of group 1) > 0
               delay 0.5
           end repeat
           click button 4
           delay 0.5
           repeat until enabled of button 4
               delay 0.5
           end repeat
           repeat until value of static text 3 of group 1 contains "passkey" -- works probably only on english systems!
               click button 4
               delay 0.5
           end repeat
           keystroke pass
           tell button 4
               click -- button "Continue"
               set n to its title
               repeat while its title is n -- wait until the button change to "Quit"
                   delay 0.5
               end repeat
               click -- button "Quit"
           end tell
       end tell
   end tell
end tell

Note: The option to pair a known headset again without entering a passkey is not considered


regards

Stefan


Filed under: System

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)