Apple script to click button in popup menu?

Discussion in 'Mac Programming' started by CharlieTeach, May 17, 2012.

  1. CharlieTeach, May 17, 2012
    Last edited by a moderator: May 17, 2012

    macrumors newbie

    Jun 16, 2011
    Hi everyone,
    I'm new to applescript but I've managed to cobble together a application to turn off bluetooth. I'm a teacher and work in a computer lab with bluetooth keyboards and would find it useful to cut off access to computers from time to time. Here's what I've got so far.
     tell application "System Preferences"
    	set current pane to pane ""
    	tell application "System Events"
    		tell process "System Preferences"
    			set isOnCheckbox to checkbox "On" of window "Bluetooth"
    			if value of isOnCheckbox is 1 then
    				click isOnCheckbox
    			end if
    		end tell
    	end tell
    end tell
    This turns off their bluetooth but i get a popup menu asking if I really want to turn off the bluetooth.
    The Question is: How do i add to this script to make it accept the changes?

    Thanks for your help.
  2. macrumors 6502a

    Mar 17, 2012
    Take a look at the Accessibility Inspector for how to click the button in the popup menu. That's what it is called on Leopard. Don't know what it is in SL or Lion. You'll find it by installing Xcode. Or you can use UI Browser found here :

Share This Page