Last active
July 19, 2025 19:13
-
-
Save SHi-ON/960bbf628947ec53e5baeca5172d87cb to your computer and use it in GitHub Desktop.
Gracefully restart PyCharm on macOS from your terminal, with fallback to force quit if needed.
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
# restart_pycharm.sh | |
# | |
# A shell function to gracefully restart PyCharm on macOS. | |
# Usage: source this file or copy the function into your ~/.zshrc or ~/.bashrc, | |
# then run `restartPyCharm` from your terminal. | |
# You may need to verify the Quit PyCharm shortcut key from the menu: Command + Shift + 9 | |
# | |
# Author: SHi-ON | |
restartPyCharm() { | |
echo "Quitting PyCharm..." | |
osascript -e 'tell application "PyCharm" to activate' \ | |
-e 'tell application "System Events" to keystroke "9" using {command down, shift down}' | |
t=0 | |
while pgrep -i PyCharm > /dev/null && [ $t -lt 30 ]; do | |
sleep 1 | |
t=$((t+1)) | |
done | |
if pgrep -i PyCharm > /dev/null; then | |
echo "PyCharm did not quit after 30 seconds, forcing quit..." | |
killall "PyCharm" | |
fi | |
echo "Restarting PyCharm..." | |
open -a "PyCharm" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment