![]() ![]() The script then first finds out the pid of the frontmost window, with the command: xdotool getactivewindow getwindowpid Wmctrl does ask what to do however, similar to Ctrl+ Q. Tested on a gedit window with unsaved changes, all of them closed the window happily however, without any interaction. I tried the various kill options ( kill -2, kill -HUP, kill -s TERM etc), which are mentioned in several posts to close an application gracefully. Now the shortcut can be used to gracefully close all windows of the frontmost window. don't use ~ or $HOME in a shortcut key, but use absolute paths instead. Click the "+" and add the command: python3 /path/to/stop_active.py Subprocess.call(])Īdd the following command to a shortcut key: python3 /path/to/stop_active.pyĬhoose: System Settings > "Keyboard" > "Shortcuts" > "Custom Shortcuts". ![]() Return subprocess.check_output(cmd).decode("utf-8").strip() Install both xdotool and wmctrl sudo apt-get install wmctrl xdotoolĬopy the script below into an empty file, save it as stop_active.py #!/usr/bin/env python3 To use it in a script to close all windows of an application: The safest way to close an application's window gracefully, and make sure you will not lose data, is using wmctrl (not installed by default): wmctrl -ic How to safely close all windows of a gui application with a shortcut key ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |