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.
Toggle Automatic Graphics Switching via Terminal – How to
gpu
Related Question
- MacOS – update to OS X Mavericks if I get a new graphics card
- MacOS – Switching graphics cards with the screen asleep makes WindowServer freeze
- macOS – How Does macOS Decide When to Switch Graphics Processors?
- Macbook Pro Display – Green Flicker only when Photoshop etc is open
- MacBook Pro – Graphics Cards in Retina 15-inch Mid 2014 Model
Best Answer
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.
In Terminal, use the following compound command to create the file and open it:
Copy and paste the example AppleScript code, shown further below, into the opened
togags
file.Save and close the file.
Make the file executable:
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 yourPATH
statement. Then it can be used from anywhere by justtogags
, (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:
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:
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.