forked from vitorgalvao/custom-alfred-iterm-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustom_iterm_script_iterm_2.1.1.applescript
46 lines (43 loc) · 1.49 KB
/
custom_iterm_script_iterm_2.1.1.applescript
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
-- This is v0.3 of the custom script for AlfredApp for iTerm 2.1.1
-- Please see https://github.com/stuartcryan/custom-iterm-applescripts-for-alfred/
-- for the latest changes.
on is_running(app_name)
tell application "System Events" to (name of processes) contains app_name
end is_running
-- Please note, if you store the iTerm binary in any other location than the Applications Folder
-- please ensure you update the two locations below (in the format of : rather than / for folder dividers)
-- this gets around issues with AppleScript not handling things well if you have two iTerm binaries on your system... which can happen :D
on alfred_script(q)
if is_running("iTerm") then
run script "
on run {q}
tell application \":Applications:iTerm.app\"
activate
try
-- set myterm to the first terminal
-- Ideally, we would open an existing terminal in the current workspace and if none, open a new terminal.
-- But I dont know how to do that.
set myterm to (make new terminal)
on error
set myterm to (make new terminal)
end try
tell myterm
set mysession to (launch session \"Default Session\")
tell mysession to write text q
end tell
end tell
end run
" with parameters {q}
else
run script "
on run {q}
tell application \":Applications:iTerm.app\"
activate
tell the first terminal
tell the last session to write text q
end tell
end tell
end run
" with parameters {q}
end if
end alfred_script