2

I have a 15" MacBook Pro from May 2019 with a Radeon Pro 555X 4 GB graphics card. I would like to change the Automatic Graphics Switching setting with a terminal command.

0

I did some googling, and I do not know of a native command line utility, or a third-party command line utility, that can toggle the state of automatic graphics switching; however it can be done from the command line by utilizing AppleScript to toggle the [√] Automatic graphics switching checkbox on the Energy Saver pane in System Preferences.

In lieu of finding a native command line utility, or a third-party command line utility, or until a better answer is posted, the following will allow you to toggle it from the command line in e.g. Terminal.

  1. In Terminal, use the following compound command to create the file and open it:

    touch togags; open togags
    
  2. Copy and paste the example AppleScript code, shown further below, into the opened togags file.

  3. Save and close the file.

  4. Make the file executable:

    chmod u+x togags
    

I used togags for: [tog]gle [a]utomatic [g]raphics [s]witching

You can now use it from the directory it's in using ./togags otherwise /path/to/togags; however, it's best if you place in into a directory that's within your PATH statement. Then it can be used from anywhere by just togags, (or whatever you actually named the executable).

NOTE: This will also require giving Terminal accessibility privileges for this to work properly.

Running the command twice, to show its output:

$ togags
   Automatic Graphics Switching is: OFF
$ togags
   Automatic Graphics Switching is: ON
$ 

The following example AppleScript code, was tested and works me as coded on macOS High Sierra. A minor change may be needed for macOS Mojave; however, I'm not able to test at the present time. The same goes for older versions of OS X/macOS.

Example AppleScript code:

#!/usr/bin/osascript

if running of application "System Preferences" then
    try
        quit application "System Preferences"
    on error
        do shell script "killall 'System Preferences'"
    end try
end if

repeat while running of application "System Preferences" is true
    delay 0.1
end repeat

tell application "System Preferences"
    reveal pane id "com.apple.preference.energysaver"
    repeat until exists window "Energy Saver"
        delay 0.1
    end repeat
end tell

tell application "System Events" to tell ¬ 
    group 1 of window "Energy Saver" of application process "System Preferences"
    repeat until exists checkbox "Automatic graphics switching"
        delay 0.1
    end repeat
    click checkbox "Automatic graphics switching"
    set cbAGS to (value of checkbox "Automatic graphics switching") as boolean
end tell

quit application "System Preferences"

if cbAGS then
    return "   Automatic Graphics Switching is: ON"
else
    return "   Automatic Graphics Switching is: OFF"
end if

Note: The example AppleScript code is just that and other then what's already coded, it does not contain any additional error handling as may be appropriate. The onus is upon the user to add any error handling as may be appropriate, needed or wanted. Have a look at the try statement and error statement in the AppleScript Language Guide. See also, Working with Errors.

  • I put it into the /usr/local/bin directory and it works great! – Ryland Goldman Jun 18 '19 at 3:05
3

The command sudo pmset -a gpuswitch n will set the graphics switching, with the following values for n:

  • 2 is integrated gpu both on cable and battery

  • 1 is dedicated gpu only with power connected; integrated gpu on battery power

  • 0 is dedicated gpu on both ac and battery

pmset -g will show you the current configuration.

  • For me, running Catalina on a 2019 macbook pro 16", value 2 is AMD Radeon Pro on both cable and battery, 0 is Intel UHD Graphics on both cable and battery somehow reversed – Pencilcheck Dec 30 '19 at 8:55
  • The value 1 is acting weird, not sure what it is doing, seems to alternate between the graphics card randomly – Pencilcheck Dec 30 '19 at 9:32
  • It seems like 1 is true automatic graphics switching determined by the OS I think but it doesn't follow the power source. I used support.apple.com/en-us/HT202053 to figure out which graphics card it is using – Pencilcheck Dec 30 '19 at 9:38

You must log in to answer this question.

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