Automatic graphic switch via Apple Script

hi community,


I would like to change the "Automatic graphics switching" (tick on / tick off) via an Apple Script. I made the following script and it works, except with line "click chckbox 2". Here it ticks the box "Show battery status in menu bar". With "click checkbox 1" it takes the "Lock-Button".


I would be glad if anybode could tell me the right code for ticking the checkbox "automatic graphics switching" via Apple Script.


Thanks a lot


PS: Yes I know that tool gfx Status, but I wanna do this via Apple Script.



tell application "System Preferences"


activate

set current pane to pane "com.apple.preference.energysaver"

delay 0.5

tell application "System Events"

tell process "Systemeinstellungen"

tell window "Energie sparen"


clickcheckbox 2

delay 0.5

end tell

end tell

end tell


quit

end tell


quit

MacBook Pro (17-inch Early 2011), OS X Mountain Lion (10.8.2)

Posted on Oct 14, 2013 1:05 PM

Reply
4 replies

Oct 14, 2013 5:21 PM in response to Leschy

Hello


You may try this. It works with MacBook Pro 2010 under 10.6.5.


tell application "System Preferences"
    set current pane to pane id "com.apple.preference.energysaver"
end tell
tell application "System Events"
    tell process "System Preferences"
        tell window 1
            tell group 1 -- automatic graphics switching
                tell checkbox 1 -- automatic graphics switching
                    click
                end tell
            end tell
        end tell
    end tell
end tell


And the script below will set the option to the specified value.


set_automatic_graphics_switching(0)
on set_automatic_graphics_switching(i)
    (*
        integer i : status of automatic graphics switching
            0 : off (unchecked)
            1 : on    (checked)
    *)
    if i is not in {0, 1} then error "Invalid argument: " & i number 8000
    tell application "System Preferences"
        set _was_running to running
        set current pane to pane id "com.apple.preference.energysaver"
    end tell
    tell application "System Events"
        tell process "System Preferences"
            tell window 1
                tell group 1 -- automatic graphics switching
                    tell checkbox 1 -- automatic graphics switching
                        if value ≠ i then click
                    end tell
                end tell
            end tell
        end tell
    end tell
    if not _was_running then
        tell application "System Preferences" to quit
    end if
end set_automatic_graphics_switching


Hope this may help,

H

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Automatic graphic switch via Apple Script

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