Skip to content

Commit 319e250

Browse files
committed
Move repeat loop to Main
1 parent b78818a commit 319e250

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

custom_iterm_script.applescript

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,6 @@ on has_windows()
2525
end has_windows
2626

2727
on send_text(custom_text)
28-
-- iTerm may try to write text before a window exists, so wait for it
29-
repeat until has_windows()
30-
delay 0.1
31-
end repeat
32-
3328
tell application "iTerm" to tell the first window to tell current session to write text custom_text
3429
end send_text
3530

@@ -42,13 +37,20 @@ on alfred_script(query)
4237
new_tab()
4338
end if
4439
else
40+
-- If iTerm is not running and we tell it to create a new window, we get two
41+
-- One from opening the application, and the other from the command
4542
if is_running() then
4643
new_window()
4744
else
4845
call_forward()
4946
end if
5047
end if
51-
48+
49+
-- Make sure a window exists before we continue, or the write may fail
50+
repeat until has_windows()
51+
delay 0.01
52+
end repeat
53+
5254
send_text(query)
5355
call_forward()
5456
end alfred_script

0 commit comments

Comments
 (0)