Created
January 4, 2026 22:16
-
-
Save epakai/5a7a6cfc68447771bdc7ec9609d5a3d6 to your computer and use it in GitHub Desktop.
screenshot i3 workspaces
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
| #!/usr/bin/env python3 | |
| import datetime | |
| import json | |
| import subprocess | |
| import sys | |
| from time import sleep | |
| from pathlib import Path | |
| current_datetime = datetime.datetime.now().isoformat(timespec='minutes') | |
| output_dir = Path(Path.home() / ('images/screenshots/i3shot/' + current_datetime)) | |
| try: | |
| output_dir.mkdir(parents=True, exist_ok=True) | |
| except OSError: | |
| sys.exit() | |
| workspaces_json = subprocess.check_output(['i3-msg', '-t', 'get_workspaces']) | |
| workspaces = json.loads(workspaces_json) | |
| for workspace in workspaces: | |
| # Switch to the workspace | |
| subprocess.run(['i3-msg', 'workspace', workspace['name']]) | |
| # wait because drawing windows takes time | |
| sleep(0.2) | |
| # Screenshot | |
| subprocess.run(['import', '-window', 'root', '-crop', | |
| str(workspace['rect']['width']) + 'x' | |
| # i3 returns the height of the workspace not including | |
| # the i3bar, but I want to see the name | |
| # size depends on font, but it doesn't hurt to go bigger | |
| + str(workspace['rect']['height'] + 35) + '+' | |
| + str(workspace['rect']['x']) + '+' | |
| + str(workspace['rect']['y']), | |
| output_dir / (workspace['name'] + '.png')]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment