Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Toggle keyboard backlight ON/OFF using applescript.

I'm trying to find a way to toggle my MBP keyboard backlight on and off that doesn't involve repeated presses of the F5/F6 key or opening of the system preferences pane. Ideally, it'd be an applescript, but I'm new to applescript, and I can't figure out what the correct names are for the window and tabgroup.


If someone could help me, I just need to figure out how to click the 'Illuminate keyboard in low light conditions' box using an applescript. I tried this one, but the names have changed in snow leopard, and I couldn't make it work.


Thanks!

MacBook Pro, Mac OS X (10.6.8)

Posted on Oct 11, 2011 3:42 PM

Reply
Question marked as Best reply

Posted on Oct 12, 2011 9:21 AM

So it's kind of messy, but I've got it done. here is the script:


tell application "System Preferences"
  activate
          set current pane to pane "com.apple.preference.keyboard"
end tell

tell application "System Events"
  -- If we don't have UI Elements enabled, then nothing is really going to work.
          if UI elements enabled then
                    tell application process "System Preferences"
                              get properties

                              click radio button "Keyboard" of tab group 1 of window "Keyboard"
                              click checkbox "Illuminate keyboard in low light conditions" of tab group 1 of window "Keyboard"
                    end tell
                    tell application "System Preferences" to quit
          else
  -- GUI scripting not enabled.  Display an alert
                    tell application "System Preferences"
  activate
                              set current pane to pane "com.apple.preference.universalaccess"
                              display dialog "UI element scripting is not enabled. Please activate \"Enable access for assistive devices\""
                    end tell
          end if
end tell


Now if only I could figure out a way to do it from the command line, to keep that window out of the way.....

1 reply
Question marked as Best reply

Oct 12, 2011 9:21 AM in response to Bicykyle

So it's kind of messy, but I've got it done. here is the script:


tell application "System Preferences"
  activate
          set current pane to pane "com.apple.preference.keyboard"
end tell

tell application "System Events"
  -- If we don't have UI Elements enabled, then nothing is really going to work.
          if UI elements enabled then
                    tell application process "System Preferences"
                              get properties

                              click radio button "Keyboard" of tab group 1 of window "Keyboard"
                              click checkbox "Illuminate keyboard in low light conditions" of tab group 1 of window "Keyboard"
                    end tell
                    tell application "System Preferences" to quit
          else
  -- GUI scripting not enabled.  Display an alert
                    tell application "System Preferences"
  activate
                              set current pane to pane "com.apple.preference.universalaccess"
                              display dialog "UI element scripting is not enabled. Please activate \"Enable access for assistive devices\""
                    end tell
          end if
end tell


Now if only I could figure out a way to do it from the command line, to keep that window out of the way.....

Toggle keyboard backlight ON/OFF using applescript.

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.