Created
March 16, 2025 02:10
-
-
Save 5731la/fad07d1794e7925fa39184fbdb5f391d to your computer and use it in GitHub Desktop.
Limit Discord CPU usage when not actively selected
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# This isn't something I use much anymore but the concept can be useful I guess | |
export cpulimitpid | |
while true; do | |
export curwindow=`xprop -id $(xprop -root | awk '/_NET_ACTIVE_WINDOW\(WINDOW\)/{print $NF}') | | |
awk '/WM_CLASS\(STRING\)/{print $NF}'|grep discord|wc -l` | |
if [ "$curwindow" -eq "1" ] | |
then | |
if [[ "$cpulimitpid" -ne "" ]] | |
then | |
echo "Killing $cpulimitpid" | |
kill $cpulimitpid | |
cpulimitpid="" | |
fi | |
else | |
if [[ "$cpulimitpid" -eq "0" ]] | |
then | |
echo "Starting cpulimit" | |
cpulimit -l 1 -c 1 -p `ps -ef | | |
grep 'DiscordCanary --type=renderer' | grep -v grep | awk '{print $2}'` & | |
export cpulimitpid=$! | |
fi | |
fi | |
sleep 1 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment