Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env python3
import asyncio
import iterm2
async def main(connection):
async def update(theme):
# Themes have space-delimited attributes, one of which will be light or dark.
parts = theme.split(" ")
if "dark" in parts:
@gnachman
gnachman / serial_alert.py
Created February 9, 2020 00:55
Register function to show one alert at a time
import asyncio
import iterm2
pending = False
last_coro = None
async def main(connection):
loop = asyncio.get_event_loop()
async def really_notify(message, window_id):
import iterm2
async def main(connection):
app = await iterm2.async_get_app(connection)
window = app.current_terminal_window
tab = window.tabs[0]
print(f'Before: {tab.sessions}')
await tab.sessions[0].async_split_pane()
print(f'After: {tab.sessions}')
<pre id="changelist7330916824228127372" style="display: none">The only change in version 3.2.9 vs 3.2.8 is that
it was built with libssh2 1.8.2 because of a
security vulnerability. iTerm2 version 3.2.8 was
built with libssh2 1.8.0.
More information on the vulnerability in libssh2
may be found here:
https://nvd.nist.gov/vuln/detail/CVE-2019-3855
@gnachman
gnachman / gist:4f51906834c8ac4b6921b451b161795a
Created April 21, 2019 05:49
iTerm2 Python script to increase font size
import re
async def main(connection):
app = await iterm2.async_get_app(connection)
# This regex splits the font into its name and size. Fonts always end with
# their size in points, preceded by a space.
r = re.compile(r'^(.* )(\d*)$')
@iterm2.RPC
async def increase_font_size(session_id):
@gnachman
gnachman / gist:2b31bbed2995f18ae9307339584db3ec
Created April 18, 2019 03:34
Prompt to enter tab title after creating a new tab
#!/usr/bin/env python3.7
import iterm2
async def main(connection):
app = await iterm2.async_get_app(connection)
def get_all_tab_ids():
result = []
for window in app.terminal_windows:
for tab in window.tabs:
[libssh2] 1.110621 Conn: Connection Established - ID: 0/0 win: 0/2097152 pack: 140630114205696/4295000064
[libssh2] 1.110646 Conn: starting request(exec) on channel 0/0, message=scp -f '~/test.txt'
=> libssh2_transport_write plain (18 bytes)
0000: 62 00 00 00 00 00 00 00 04 65 78 65 63 01 00 00 : b........exec...
0010: 00 14 : ..
=> libssh2_transport_write plain2 (20 bytes)
0000: 73 63 70 20 2D 66 20 27 7E 2F 74 65 73 74 2E 74 : scp -f '~/test.t
0010: 78 74 27 00 : xt'.
[libssh2] 1.110690 Socket: Sent 80/80 bytes at 0x7fe74da7a260
=> libssh2_transport_write send() (80 bytes)
- (void)drawRect:(NSRect)dirtyRect {
NSString *string = @"Hello world";
NSDictionary *attributes = @{ (NSString *)kCTForegroundColorAttributeName: (id)[[NSColor blackColor] CGColor],
NSFontAttributeName: [NSFont fontWithName:@"PragmataProMono-Regular" size:12],
NSLigatureAttributeName: @0,
NSUnderlineStyleAttributeName: @1 };
NSAttributedString *attributedString = [[NSAttributedString alloc] initWithString:string
attributes:attributes];
CGColorRef cgColor = (__bridge CGColorRef)attributes[(NSString *)kCTForegroundColorAttributeName];
#!/usr/bin/env python3
import asyncio
import iterm2
import sys
# This script was created with the "basic" environment which does not support adding dependencies
# with pip.
async def main(connection, argv):
app = await iterm2.async_get_app(connection)
@gnachman
gnachman / gist:3f3b78030e02b6949de9fe7f813ae47c
Created June 28, 2018 18:32
Get terminal geometry when stdin/stdout are not ttys.
#!/bin/bash
#@ Copyright: © 2011 Chris F.A. Johnson
#@ Released under the terms of the GNU General Public License V2
#@ See the file COPYING for the full license
# Originally from http://cfajohnson.com/shell/listing1.txt
# Hacked to be completely different by George Nachman
if [ ! -t 1 ] ; then
# WARNING * THIS IS A HACK * IT MIGHT BREAK * THERE BE DRAGONS HERE * DO NOT USE IF YOU CARE FOR CORRECTNESS
"$0" < /dev/tty > /dev/tty