disabling bluetooth using applescript in mavericks

Discussion in 'Mac Programming' started by festermonkey, Apr 30, 2014.

  1. festermonkey, Apr 30, 2014
    Last edited by a moderator: Apr 30, 2014

    festermonkey macrumors newbie

    Joined:
    Apr 30, 2014
    #1
    I'm not a programmer, first off. So forgive my ignorance here. I am trying to disable bluetooth using applescript. My goal is to assign this applescript to my Griffin Powermate button to make it easier to use my iMac as a second screen for my MBP. I have this script, which gets it most of the way, but the problem is in mavericks, if you click the button to turn off bluetooth, you get another window that needs you to confirm that you want to do that. In comes in the form of two buttons, one that says "Turn bluetooth off" and the other that says "Leave bluetooth on".

    So I can't for the life of me figure out how to get the script to click the button in the secondary window (like a popup, but it's not modal)

    Thoughts?

    Here's the current script I have, which works great to turn bluetooth back on, by the way, because there is no secondary window.
    Code:
    tell application "System Preferences"
    	reveal pane "com.apple.preferences.Bluetooth"
    end tell
    tell application "System Events" to tell process "System Preferences"
    	click button 6 of window 1
    end tell
    quit application "System Preferences"
    
    Thanks so much for your help.
     

    Attached Files:

  2. kryten2 macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #2
    Take a look at UI Browser or Apple's free UIElementInspector (sometimes known as Accessibility Inspector) for al things related to GUI Scripting.

    Info : http://pfiddlesoft.com/uibrowser/
     
  3. Partron22, Apr 30, 2014
    Last edited: Apr 30, 2014

    Partron22 macrumors 68000

    Partron22

    Joined:
    Apr 13, 2011
    Location:
    Yes
    #3
  4. kryten2 macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #4
    Thanks for the reminder Patron22. I'd seen it before but forgot to bookmark it.
     
  5. snorkelman, Apr 30, 2014
    Last edited: Apr 30, 2014

    snorkelman macrumors 6502a

    snorkelman

    Joined:
    Oct 25, 2010
    #5
    edit scratch my command line suggestion its behaviour re bluetooth doesn't seem to be consistent in a script
     

Share This Page