Using AppleScript with tmux to create new windows/tabs with sessions that are known to tmux
Thanks for filing an issue! Please answer the questions below so I can help you.
- iTerm2 version: 3.1.beta.4
- OS version: 10.12.5
- Attach ~/Library/Preferences/com.googlecode.iterm2.plist here (drag-drop from finder into this window)
- Attach a debug log, if possible. Instructions at https://iterm2.com/debuglog
- Are you reporting a performance issue or a hang? Please attach a sample. Instructions at https://gitlab.com/gnachman/iterm2/wikis/HowToSample
- Are you reporting a crash? Please attach the crash log. Instructions at https://gitlab.com/gnachman/iterm2/wikis/crash-logs
Detailed steps to reproduce the problem: I'm trying to use AppleScript to start a tmux session and create new windows that is known to tmux's session/window hierarchy, but also still able to be scripted in AppleScript to send commands.
use AppleScript version "2.4" -- Yosemite (10.10) or later use scripting additions
tell application "iTerm" activate
set tmux to (create window with profile "production")
--set tmux to (make new session at the end of sessions)
--set tmux to (create window)
tell tmux
set tmuxsession to current session
tell tmuxsession
write text "tmux -CC -L development"
--write text "tmux -CC attach"
end tell
tell tmuxsession
-- This creates a new window, but tmux doesn't know about it
--set myterm to (create window with profile "production")
tell application "System Events"
-- This will create a window that tmux has a reference to
-- but how can I get a reference to it in AppleScript?
keystroke "n" using {control down, shift down, command down}
--keystroke "d"
keystroke "echo 'new window'"
end tell
-- This gives this error:
-- iTerm got an error: Can’t get current window of session id "9B1CF226-DDE9-4D75-B485-BAEC71398BBE" of tab 1 of window id 68948.
--offending object:
-- current window of session id "9B1CF226-DDE9-4D75-B485-BAEC71398BBE" of tab 1 of window id 68948
set myterm to current window
tell myterm
write text "echo 'boo'"
end tell
tell application "System Events"
-- This will create a window that tmux has a reference to
-- but how can I get a reference to it in AppleScript?
keystroke "n" using {control down, shift down, command down}
--keystroke "d"
end tell
set myterm2 to current window
tell myterm2
write text "echo 'yaaa'"
end tell
end tell
end tell
end tell
What happened: I can use this to create a new window that tmux knows about:
keystroke "n" using {control down, shift down, command down}
But I can't get a reference to the window for continued operations.
When I use this:
tell tmuxsession
-- This creates a new window, but tmux doesn't know about it
set myterm to (create window with profile "production")
It will create a new window, but tmux doesn't know about it.
What should have happened:
I'd like to be able to do this:
set myterm to (create tmux window with profile "production")
or
set myterm to (create tmux tab with profile "production") -- Not sure if this is the syntax for working with tabs in AppleScript