CodySchrank / gSwitch

macOS menu bar app that allows control over the gpu on dual gpu macbooks
MIT License
886 stars 46 forks source link

Feature Request: switching based on power source #73

Open mosemizrahi opened 3 years ago

mosemizrahi commented 3 years ago

Hello,

I want to use Dynamic Switching when I'm on battery, and Discrete Only when I'm charging my laptop. I'd like it if gSwitch had a feature that let me do this automatically. In theory, I could run the line "sudo pmset -c gpuswitch 1 && sudo pmset -b gpuswitch 2" in terminal to get what I want, but that doesn't work consistently.

The bash script below implements what I ask for in a "hacky" way. I'm currently using a different script that works similarly using the app BetterTouchTool.

#!/bin/bash
OLDSOURCE=""
while true
do
    CURSOURCE=`pmset -g batt | head -n 1 | cut -d \' -f2`
    if [ "$OLDSOURCE" != "$CURSOURCE" ]
    then
        OLDSOURCE=$CURSOURCE
        killall gSwitch
        if [ "$CURSOURCE" == "AC Power" ]
        then
            open -a /Applications/gSwitch.app/Contents/MacOS/gSwitch --args --discrete
        else
            open -a /Applications/gSwitch.app/Contents/MacOS/gSwitch --args --dynamic
        fi
    fi
    sleep 5
done
CodySchrank commented 3 years ago

I have considered this before, and unfortunately Apple does not provide a very good API in swift to know when the computer has switched to a different power source. I will leave the issue open if anyone wants to open a PR for this though.

zzonderr commented 3 years ago

I don't know how much this will help, but i hope it may be useful. The Turbo Boost Switcher Pro program has an option, which when switching to the battery turns off Turbo Boost for the Intel processor. Can try to contact the author and find out how he did it?

Screenshot 2020-10-01 at 18 32 21
CodySchrank commented 3 years ago

Looks like this might be easier than I thought when I looked this up a few years ago.

Yea I can probably add this in.

ref

pencilcheck commented 3 years ago

Would be nice to see because right now the default dynamic switching behavior is reversed for me (discrete on battery, and integrated on power for some reason derp), this tells me that mac internally tried to switch based on power source.

robertocaldas commented 3 years ago

Having that would be great. I have a 16" 2019 MBP and I can feel it's a little sluggish on Safari when on integrated.

JeffFlowerday commented 3 years ago

Just to chime in, this would be an awesome feature. I use discrete when plugged in for the same reason as @robertocaldas.

alexander-potemkin commented 3 years ago

Please! I'm already paying for Turbo Boost to disable extra CPU power (that I don't really need), would love to pay for automatic switching in here - to increase battery time and a cooler laptop :)

Off-topic: it's a wonderful new world - you pay to get less power, but for a longer time... :)

natjsbelza commented 3 years ago

This app is awesome, the idea is awesome and it's real awesome in application. But it will be a leap more awesome if this feature is added. OMG! I'd love to have this. My MBP 16 would drain really fast with discreet GPU when on battery. Please! 🙏