Yes. Now I can finally script shell and terminal colors changes for day/night/late night. Tmux and status bar control API should let me get all the magic out of Zsh prompt.
Now I wonder if I could make Sublime Text / VS Code style command palette within iTerm... Probably requires Python shell script as front. I didn’t yet find mention of custom dialogs or the like in the API docs.
I was checking quick open actually for its possible extensions. It does mention /s to "run script" but didn't find it mentioned in the docs.
I'm looking to get:
- switch layout and run server/compile start commands and the like for given project
- call my own shell scripts and assorted helpers from terminal's context
- get Jupyter notebook running and console connected to it
- connect to tmux session on host or start one with given layout if it isn't there
- Kubernetes and Docker context in their own tabs
- Quick Open can probably take care of finding tabs and ssh sessions so need to learn to remember it's there
That's the first things I find myself constantly doing manually. Nothing that can't be done, say, with regular shell and TMUX stuff, but those have so low level control mechanisms. I'm hoping Python access to gives same power with less work.
> If you have lots of sessions you can quickly find the one you're looking for with Open Quickly. Select the View > Open Quickly menu item (cmd-shift-O) and then enter a search query. You can search by tab title, command name, host name, user name, profile name, directory name, badge label, and more. Queries are scored according to relevance and sorted by score. Open Quickly also lets you create new tabs, change the current session's profile, open arrangements, and change the color preset. If you start your query with a / then that gives you a shortcut to various commands. /a followed by an arrangement name restores the arrangement. /f restricts the query to existing sessions, excluding options to open new tabs, etc. /p restrics the query to profile names to switch the current session to. /t restricts the results to "open new tab" for matching profile names. /c restricts the results to color presets.
I think with /s and creating custom scripts you could wire up some of these use cases.
I've been really wanting to auto store declarative pane layouts and default run commands for each project in a file and be able to recreate them programmatically to open / close a "project", like the Projects feature in Sublime.
For example, re-create a layout of multiple tabs with specific split panes for each project.
Previous attempts before this API were a struggle:
- You could almost do this with Saved Window Arrangements but not quite and there was no association to a project.
- You could also hack something with profiles if you're willing to make a profile for each project, but it still doesn't get you there.
- Bury Session is the closest which pretty much does what I want but it keeps all of the tabs running in the background. This can be a lot when you have 5-10+ tabs open each across multiple projects. No way to "sleep" a buried session that I could find.
- I also tried implementing it via the previous AppleScript API and it turned out to be a lot harder than expected to open "2 tabs with 3x2 split panes each and run commands x, y, z, ... in them". Then I called the AppleScripts via Python so I could template them more easily. I got about halfway there.
I have a docker instance that I need to always be running. Whenever I start iTerm, I open an extra tab, start the docker, and bury the tab so it's just running in the background. I'm going to automate that first. This is something I've been waiting to be able to automate.
I also have some helpful triggers, which I currently have a wiki page explaining how others at my company can set up. It looks like I could replace those instructions with a single command using one of these scripts.
Those are the two things I've been wanting to automate for a while. After doing them, I imagine there will be plenty of things I never thought of before but will now that they're possible.
Does `docker run --detach ...` work for your use case?
I have a tangentially related Docker use case: I'd like Docker Desktop (and Kubernetes) to spin down automatically in the background anytime I haven't run a container for some period of time and am on battery. It drains so much power even when idle.
https://iterm2.com/python-api/
https://iterm2.com/python-api/tutorial/