-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdo-script-in-terminal.applescript
62 lines (52 loc) · 1.59 KB
/
do-script-in-terminal.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
load script "/Users/scott/github/iconify/ai-scripts/_string.scpt"
set this_node to ""
tell application "Terminal"
if not (exists window 1) then
reopen
end if
do script with command "which node | /usr/bin/awk '{ print " & "\"RESULT:\"" & " $1}'"
delay 0.5
set the_content to (contents of window 1) as string
set n to (count of every paragraph of the_content)
close window 1
end tell
repeat with i from 1 to n
try
set test_str to (characters 1 thru 7 of paragraph i of the_content) as string
log test_str
if test_str is equal to "RESULT:" then
set this_line to paragraph i of the_content as string
set this_node to trim_line(this_line, test_str, 0)
end if
on error err_str number err_number
-- log err_str & "[" & err_number & "]"
end try
end repeat
log this_node
on trim_line(this_text, trim_chars, trim_indicator)
-- 0 = beginning, 1 = end, 2 = both
set x to the length of the trim_chars
-- TRIM BEGINNING
if the trim_indicator is in {0, 2} then
repeat while this_text begins with the trim_chars
try
set this_text to characters (x + 1) thru -1 of this_text as string
on error
-- the text contains nothing but the trim characters
return ""
end try
end repeat
end if
-- TRIM ENDING
if the trim_indicator is in {1, 2} then
repeat while this_text ends with the trim_chars
try
set this_text to characters 1 thru -(x + 1) of this_text as string
on error
-- the text contains nothing but the trim characters
return ""
end try
end repeat
end if
return this_text
end trim_line