Identifying a button for UI instructions

Hi. I’m trying to get applescript to switch off Bluetooth (amongst other things) for a setup program. This is working up to the last line and then I get a NSRecieverEvaluationScriptError: 4. I have UI Element Inspector but how do I identify the button properly?

tell application "System Events" to tell process "System Preferences"
  click the menu item "Bluetooth" of the menu "View" of menu bar 1
  delay 1
  click the radio button "Settings" of tab group 1 of window "Bluetooth"
  click the button "Turn Bluetooth Off" of window "Bluetooth"
end tell

Thanks for your time
Mosh

Model: Mac mini
Browser: Opera/9.10 (Windows NT 5.1; U; en)
Operating System: Mac OS X (10.4)

Something like this:

-- System Preferences must not be running... then:
-- add stuff to quit SP if it is
tell application "System Preferences" to reveal anchor "Settings" of pane id "com.apple.Preferences.Bluetooth"
delay 3 -- adjust this as low as possible.
try -- in case Bluetooth is already off
	tell application "System Events" to tell process "System Preferences" to click button "Turn Bluetooth Off" of tab group 1 of window 1
end try

Thanks Adam, that works nicely. :smiley: