Skip to content

Commit

Permalink
Fix for iTerm quiet opening config (#64)
Browse files Browse the repository at this point in the history
Co-authored-by: Vítor Galvão <info@vitorgalvao.com>
  • Loading branch information
luckman212 and vitorgalvao committed Sep 2, 2022
1 parent c082d89 commit 47969b6
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions custom_iterm_script.applescript
Expand Up @@ -7,6 +7,9 @@ property open_in_new_window : false
-- Set this property to false to reuse current tab
property open_in_new_tab : true

-- Set this property to true if iTerm is configured to launch without opening a new window
property iterm_opens_quietly : false

-- Handlers
on new_window()
tell application "iTerm" to create window with default profile
Expand Down Expand Up @@ -54,20 +57,25 @@ on alfred_script(query)
-- Reuse current tab
end if
else
-- If iTerm is not running and we tell it to create a new window, we get two
-- One from opening the application, and the other from the command
if is_running() then
-- If iTerm is not running and we tell it to create a new window, we get two:
-- one from opening the application, and the other from the command
if is_running() or iterm_opens_quietly then
new_window()
else
call_forward()
end if
end if

-- Make sure a window exists before we continue, or the write may fail
repeat until has_windows()
-- "with timeout" does not work with a "repeat"
-- Delay of 0.01 seconds repeated 500 times means a timeout of 5 seconds
repeat 500 times
if has_windows() then
send_text(query)
call_forward()
exit repeat
end if

delay 0.01
end repeat

send_text(query)
call_forward()
end alfred_script

0 comments on commit 47969b6

Please sign in to comment.