Skip to content

Commit c560484

Browse files
authored
Wait when sending characters over input buffer support
1 parent 47969b6 commit c560484

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

custom_iterm_script.applescript

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ on is_running()
2727
application "iTerm" is running
2828
end is_running
2929

30+
on is_processing()
31+
tell application "iTerm" to tell the first window to tell current session to return is processing
32+
end is_processing
33+
3034
on has_windows()
3135
if not is_running() then return false
3236

@@ -66,9 +70,17 @@ on alfred_script(query)
6670
end if
6771
end if
6872

73+
-- macOS buffers TTY input to 1024 bytes, so if input is larger wait for session to be ready
74+
-- "with timeout" does not work with "repeat", so use a delay (0.01 * 500 means a timeout of 5 seconds)
75+
if length of query > 1024
76+
repeat 500 times
77+
if not is_processing() then exit repeat
78+
delay 0.01
79+
end repeat
80+
end if
81+
6982
-- Make sure a window exists before we continue, or the write may fail
70-
-- "with timeout" does not work with a "repeat"
71-
-- Delay of 0.01 seconds repeated 500 times means a timeout of 5 seconds
83+
-- "with timeout" does not work with "repeat", so use a delay (0.01 * 500 means a timeout of 5 seconds)
7284
repeat 500 times
7385
if has_windows() then
7486
send_text(query)

0 commit comments

Comments
 (0)