forked from vitorgalvao/custom-alfred-iterm-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustom_iterm_script.applescript
More file actions
62 lines (51 loc) · 1.33 KB
/
Copy pathcustom_iterm_script.applescript
File metadata and controls
62 lines (51 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
-- For the latest version:
-- https://github.com/vitorgalvao/custom-alfred-iterm-scripts
-- Set this property to true to always open in a new window
property open_in_new_window : false
-- Handlers
on new_window()
tell application "iTerm" to create window with default profile
end new_window
on new_tab()
tell application "iTerm" to tell the first window to create tab with default profile
end new_tab
on call_forward()
tell application "iTerm" to activate
end call_forward
on is_running()
application "iTerm" is running
end is_running
on has_windows()
if not is_running() then return false
if windows of application "iTerm" is {} then return false
true
end has_windows
on send_text(custom_text)
tell application "iTerm" to tell the first window to tell current session to write text custom_text
end send_text
-- Main
on alfred_script(query)
-- Make sure iTerm is running first
repeat until is_running()
call_forward()
delay 0.01
end repeat
if has_windows() then
if open_in_new_window then
new_window()
else
new_tab()
end if
else
-- If iTerm is running but has no windows create one
if is_running() then
new_window()
end if
end if
-- Make sure a window exists before we continue, or the write may fail
repeat until has_windows()
delay 0.01
end repeat
send_text(query)
call_forward()
end alfred_script