Last active
July 16, 2025 22:15
-
-
Save NextdoorPsycho/013ad83455c8492888c9c424d7695dd7 to your computer and use it in GitHub Desktop.
This script enables Apple’s Game Mode by launching the Chess app in fullscreen mode, which triggers Game Mode. It then deprioritizes the Chess process to minimize its resource usage, keeping the performance boost of Game Mode active without significant CPU/GPU drain from Chess. After making Chess fullscreen, the script switches focus back to the…
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 | |
LOG_FILE="chess_script.log" | |
log() { | |
echo "$(date '+%Y-%m-%d %H:%M:%S') - $1" | tee -a "$LOG_FILE" | |
} | |
# Requesting sudo privileges at the start | |
log "Requesting sudo privileges..." | |
sudo -v | |
if [ $? -ne 0 ]; then | |
log "Error: Failed to obtain sudo privileges." | |
exit 1 | |
fi | |
# Keep sudo privileges alive while the script runs | |
while true; do sudo -n true; sleep 60; kill -0 "$$" || exit; done 2>/dev/null & | |
# Log the start of the script | |
log "Starting Chess script..." | |
# Launch Chess if it's not running | |
sleep 1 | |
if ! pgrep -x "Chess" > /dev/null; then | |
log "Chess is not running. Launching Chess..." | |
open -a Chess | |
sleep 2 # Give it a moment to open | |
if pgrep -x "Chess" > /dev/null; then | |
log "Chess launched successfully." | |
else | |
log "Error: Failed to launch Chess." | |
exit 1 | |
fi | |
else | |
log "Chess is already running." | |
fi | |
sleep 1 | |
# Make Chess fullscreen by simulating the keystroke Command + Control + F | |
osascript -e 'tell application "System Events" to keystroke "f" using {command down, control down}' | |
if [ $? -eq 0 ]; then | |
log "Chess set to fullscreen successfully." | |
else | |
log "Error: Failed to set Chess to fullscreen." | |
fi | |
sleep 1 | |
# Switch to desktop space by simulating the keystroke Control + Left Arrow | |
osascript -e 'tell application "System Events" to key code 123 using {control down}' | |
if [ $? -eq 0 ]; then | |
log "Switched focus to desktop successfully." | |
else | |
log "Error: Failed to switch focus to desktop." | |
fi | |
sleep 1 | |
# Get the process ID of Chess | |
chess_pid=$(pgrep -x "Chess") | |
# Lower the priority of Chess to give more CPU to other processes (-n 20 makes it the lowest priority) | |
if [ ! -z "$chess_pid" ]; then | |
log "Setting Chess process priority to lowest (nice value 20)..." | |
sudo renice 20 -p $chess_pid | |
if [ $? -eq 0 ]; then | |
log "Chess priority set successfully." | |
else | |
log "Error: Failed to set Chess priority." | |
fi | |
else | |
log "Error: Unable to retrieve Chess process ID." | |
exit 1 | |
fi | |
sleep 1 | |
# List all active window processes and allow the user to pick one to change its priority | |
log "Listing active window processes..." | |
active_processes=$(osascript -e 'tell application "System Events" to get the name of every application process whose visible is true') | |
IFS=", " read -r -a process_array <<< "$active_processes" | |
echo "Active window processes:" | |
for i in "${!process_array[@]}"; do | |
echo "[$i] ${process_array[$i]}" | |
done | |
read -p "Enter the number of the process you want to change the priority for: " process_number | |
if [[ $process_number -ge 0 && $process_number -lt ${#process_array[@]} ]]; then | |
selected_process="${process_array[$process_number]}" | |
selected_pid=$(pgrep -x "$selected_process") | |
if [ -z "$selected_pid" ]; then | |
log "Error: Unable to retrieve process ID for $selected_process." | |
exit 1 | |
fi | |
read -p "Enter the new priority for $selected_process (-20 for max, 0 for average, 20 for lowest): " new_priority | |
if [[ $new_priority =~ ^-?[0-9]+$ && $new_priority -ge -20 && $new_priority -le 20 ]]; then | |
log "Setting priority of $selected_process (PID: $selected_pid) to $new_priority..." | |
sudo renice $new_priority -p $selected_pid | |
if [ $? -eq 0 ]; then | |
log "$selected_process priority set to $new_priority successfully." | |
else | |
log "Error: Failed to set priority for $selected_process." | |
fi | |
else | |
log "Invalid priority value: $new_priority. Please enter a value between -20 and 20." | |
exit 1 | |
fi | |
else | |
log "Invalid selection. Please enter a number between 0 and $((${#process_array[@]} - 1))." | |
exit 1 | |
fi | |
sleep 1 | |
log "Chess script completed." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello, I’ve tried out a new version. Jules from Google created this custom version. He mentions that this commit "significantly refactors and improves the chess_script.sh."