Skip to content

Instantly share code, notes, and snippets.

@5731la
Created March 16, 2025 02:10
Show Gist options
  • Save 5731la/fad07d1794e7925fa39184fbdb5f391d to your computer and use it in GitHub Desktop.
Save 5731la/fad07d1794e7925fa39184fbdb5f391d to your computer and use it in GitHub Desktop.
Limit Discord CPU usage when not actively selected
#!/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