0

Assuming I am opening an iTerm window with the following AppleScript:

tell application "iTerm"
            set win1 to (create window with default profile)
        repeat until exists win1
            delay 0.01
        end repeat
        tell current session of current tab of current window
            write text "watch -n1 " & "'"  & "kubectl get pods | grep -i " & input & "'"
            split horizontally with default profile
            split vertically with default profile
        end tell

What code snippet should I use so that win1 gets maximized (as in clicking on the green window button)?

edit: regarding the proposed solution indicated in the question that is supposed to be duplicate, I have changed my snippet as follows:

    tell application "iTerm"
            set win1 to (create window with default profile)
        repeat until exists win1
            delay 0.01
        end repeat
        tell application "System Events"
            perform action "AXZoomWindow" of (first button whose subrole is "AXFullScreenButton") of (first window whose subrole is "AXStandardWindow") of (first process whose frontmost is true)
        end tell
        tell current session of current tab of current window
            write text "watch -n1 " & "'"  & "kubectl get pods | grep -i " & input & "'"
            split horizontally with default profile
            split vertically with default profile
        end tell

However this now opens a new terminal window and no further command executes.

4
  • The proposed solution does not work, I have edited my initial question to indicate this – pkaramol Nov 29 '19 at 17:55
  • 1
    When requesting help involving code, please provide proper samples. Your code does not compile and input is not defined. We can not test incomplete code! That said, the perform action command is going to go the the frontmost window that meets the criteria of the the given command. As such, you need to use the activate command after tell application "iTerm" so win1 will be frontmost when the perform action command is triggered. – user3439894 Nov 29 '19 at 18:33
  • I don’t know the answer, but if I was looking for iTerm help, the place I’d go is the excellent Google Group where lots of helpful users hang out, as well as the developer <groups.google.com/forum/#!forum/iterm2-discuss>. – TJ Luoma Dec 1 '19 at 5:22
1

The perform action command is going to go the the frontmost window that meets the criteria of the the given command. As such, you need to use the activate command after tell application "iTerm" so win1 will be frontmost when the perform action command is triggered.

tell application "iTerm"
        activate
        set win1 to (create window with default profile)
    repeat until exists win1
        delay 0.01
    end repeat
    tell application "System Events"
        perform action "AXZoomWindow" of (first button whose subrole is "AXFullScreenButton") of (first window whose subrole is "AXStandardWindow") of (first process whose frontmost is true)
    end tell
...

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .