0

When running tell application "System Events" click button "Turn Bluetooth Off" of window 1 of application process "System Preferences" end tell

I get the error: error "System Events got an error: Can’t get application process \"System Preferences\"." number -1728 from application process "System Preferences”

I’ve also tried 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” Didn’t give me any errors, but it didn’t work

I’m running macOS Sierra. This is supposed to turn my bluetooth off (I’m planning to have this run when I login)

enter image description here

0

This works for me using the latest version of macOS Mojave. This code may need to be adjusted To work with the current version of your operating system;

try
    if application "System Preferences" is running then do shell script "killall 'System Preferences'"
end try
repeat until application "System Preferences" is not running
    delay 0.1
end repeat
tell application "System Preferences"
    reveal anchor "Main" of pane id "com.apple.preferences.Bluetooth"
end tell

tell application "System Events" to tell application process "System Preferences"
    repeat while not (exists of UI element "Turn Bluetooth Off" of window "Bluetooth")
        delay 0.1
    end repeat
    click UI element "Turn Bluetooth Off" of window "Bluetooth"
    repeat while not (exists of UI element "Turn Bluetooth On" of window "Bluetooth")
        delay 0.1
    end repeat
end tell

try
    if application "System Preferences" is running then do shell script "killall 'System Preferences'"
end try
  • @Sam . I'm just curious if my solution was able to solve your problem? – wch1zpink Feb 26 at 17:15
  • This (imgur.com/gallery/BRdA6Z2) happened to my computer a bit before your answer, it took a while to fix but I’ll try it now – Sam Feb 26 at 17:17
  • just added try if application "Script Editor" is running then do shell script "killall 'Script Editor'" end try to the end – Sam Feb 26 at 17:34
  • Why? If you save the code in script editor as an application. All you need to do is add that new application to your login items. When the application is launched, it has nothing to do with the script editor – wch1zpink Feb 26 at 17:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .