uv run iterm2_profile.py
Created
April 10, 2025 08:18
-
-
Save yakkle/707640b59fbb90ef5d672e59755abcc4 to your computer and use it in GitHub Desktop.
Save iterm2 profiles with python API
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
| # /// script | |
| # requires-python = ">=3.12" | |
| # dependencies = [ | |
| # "iterm2", | |
| # "pyobjc", | |
| # ] | |
| # /// | |
| import json | |
| import pathlib | |
| import AppKit | |
| import iterm2 | |
| async def main(connection): | |
| profiles = [] | |
| all_profile = await iterm2.Profile.async_get(connection) | |
| for profile in all_profile: | |
| profiles.append(profile.all_properties) | |
| iterm2_dir = pathlib.Path.home() / ".iterm2" | |
| iterm2_dir.mkdir(mode=0o755, exist_ok=True) | |
| with open(iterm2_dir / "Profiles.json", "w") as f: | |
| json.dump({"Profiles": profiles}, f, indent=2, sort_keys=True) | |
| bundle = "com.googlecode.iterm2" | |
| if not AppKit.NSRunningApplication.runningApplicationsWithBundleIdentifier_(bundle): | |
| AppKit.NSWorkspace.sharedWorkspace().launchApplication_("iTerm") | |
| iterm2.run_until_complete(main) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment