Timing issue in newly created Session in AppleScript
Thanks for filing an issue! Please answer the questions below so I can help you.
- iTerm2 version: 3.3.5beta2
- OS version: OS X 10.14.6 (18G95)
- Attach ~/Library/Preferences/com.googlecode.iterm2.plist here (drag-drop from finder into this window): com.googlecode.iterm2.plist
- Attach a debug log, if possible. Instructions at https://iterm2.com/debuglog: debuglog.txt
Detailed steps to reproduce the problem:
- Run the following AppleScript:
tell application "iTerm" tell current window set myTab to (create tab with default profile) tell current session of myTab write text "echo test" end tell end tell end tell
The tab is opened, however the
write text does not happen.
When I stepped through the script in Script Debugger, everything worked as expected. So it’s clearly a timing issue.
At first I thought the timing issue was in the
current session of myTab (that the session was perhaps not yet set up when requested). However, setting that to a variable and breaking below it:
tell application "iTerm" tell current window set myTab to (create tab with default profile) set mySession to (current session of myTab) tell mySession write text "echo test" end tell end tell end tell
… shows it’s in the
write text. If it happens too soon after the tab / session is created, it is ignored.
What should have happened:
The tab should be opened, and the text written to it (with a newline)