iTerm AppleScript to maximize all windows on the main screen

151 views
Skip to first unread message

Osho

unread,
Jul 11, 2019, 5:29:00 PM7/11/19
to iterm2-discuss
Could someone please help how can I create an AppleScript to tell iTerm to move all windows to the main screen (where the MacOS main bar at the top is) and maximize all iTerm windows?

Perhaps something along this line?

tell application "iTerm"

repeat with aWindow in windows

... something here??? ....

end repeat

end tell


Thanks,

Osho

George Nachman

unread,
Jul 13, 2019, 2:08:24 PM7/13/19
to iterm2-...@googlegroups.com
I'm not sure how to do it with Applescript, but the new Python API in 3.3.0 (now in beta) can do it pretty easily. Use "brew install python3 && pip3 install iterm2" to install the dependencies, and then run the script below:

#!/usr/bin/env python3.7

import iterm2

async def main(connection):
    app = await iterm2.async_get_app(connection)
    desired_frame = iterm2.Frame(iterm2.Point(0, 0), iterm2.Size(1024, 768))
    for window in app.terminal_windows:
        await window.async_set_frame(desired_frame)

iterm2.run_until_complete(main)

You'll need to set the size and origin to fit your screen. If you want to discover it automatically, you can do that using PyObjC (pip3 install pyobjc) to get the visibleFrame of the NSScreen.mainScreen.


--
You received this message because you are subscribed to the Google Groups "iterm2-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to iterm2-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/iterm2-discuss/ddb34229-b7c6-4f1e-9892-02da77545067%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Osho

unread,
Sep 3, 2019, 11:02:49 AM9/3/19
to iterm2-discuss
Sorry for the delayed reply.. I just upgraded to iTerm with Python API support (I don't usually get beta version of iTerms).

This worked great. Thanks George!!

Osho


On Saturday, July 13, 2019 at 11:08:24 AM UTC-7, George Nachman wrote:
I'm not sure how to do it with Applescript, but the new Python API in 3.3.0 (now in beta) can do it pretty easily. Use "brew install python3 && pip3 install iterm2" to install the dependencies, and then run the script below:

#!/usr/bin/env python3.7

import iterm2

async def main(connection):
    app = await iterm2.async_get_app(connection)
    desired_frame = iterm2.Frame(iterm2.Point(0, 0), iterm2.Size(1024, 768))
    for window in app.terminal_windows:
        await window.async_set_frame(desired_frame)

iterm2.run_until_complete(main)

You'll need to set the size and origin to fit your screen. If you want to discover it automatically, you can do that using PyObjC (pip3 install pyobjc) to get the visibleFrame of the NSScreen.mainScreen.


On Thu, Jul 11, 2019 at 2:29 PM Osho <osh...@gmail.com> wrote:
Could someone please help how can I create an AppleScript to tell iTerm to move all windows to the main screen (where the MacOS main bar at the top is) and maximize all iTerm windows?

Perhaps something along this line?

tell application "iTerm"

repeat with aWindow in windows

... something here??? ....

end repeat

end tell


Thanks,

Osho

--
You received this message because you are subscribed to the Google Groups "iterm2-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to iterm2-...@googlegroups.com.

Jeff Shepherd

unread,
Oct 7, 2024, 9:34:38 PM10/7/24
to iterm2-discuss
This was answered in a previous question (oops. Missed it at the time). Thank you George Nachman!

https://groups.google.com/g/iterm2-discuss/c/K4W9p9pE_uI/m/chff1ha2AwAJ

The simple answer is you change the number of columns rather than the number of pixels

tell application "iTerm2"

set columns of current session of current window to 100

end tell


Reply all
Reply to author
Forward
0 new messages