Skip to content

Instantly share code, notes, and snippets.

@yakkle
Created April 10, 2025 08:18
Show Gist options
  • Select an option

  • Save yakkle/707640b59fbb90ef5d672e59755abcc4 to your computer and use it in GitHub Desktop.

Select an option

Save yakkle/707640b59fbb90ef5d672e59755abcc4 to your computer and use it in GitHub Desktop.
Save iterm2 profiles with python API

Run this script

uv run iterm2_profile.py
# /// 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