This repository was archived by the owner on Jan 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquicklaunch.applescript
More file actions
161 lines (149 loc) · 5.41 KB
/
quicklaunch.applescript
File metadata and controls
161 lines (149 loc) · 5.41 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# The tabs to create. Each tab can either run a command, or
# split (v)ertically/(h)orizontally and run a command in that split
set termCommands to {¬
{command:"workon simpleloop"}, ¬
{command:"workon simpleloop && gulp serve"}, ¬
{splits:{¬
{command:"postgres -D /usr/local/var/postgres", splitType:"v"}, ¬
{command:"redis-server /usr/local/etc/redis.conf", splitType:"v"}, ¬
{command:"rabbitmq-server", splitType:"h"} ¬
} ¬
} ¬
}
# You shouldn't need to change anything below this line
# --------------------------------------------------------
# Taken from http://stackoverflow.com/questions/13653358/how-to-log-objects-to-a-console-with-applescript
#
# Converts the specified object - which may be of any type - into a string representation for logging/debugging.
# Tries hard to find a readable representation - sadly, simple conversion with `as text` mostly doesn't work with non-primitive types.
# An attempt is made to list the properties of non-primitive types (does not always work), and the result is prefixed with the type (class) name
# and, if present, the object's name and ID.
# EXAMPLE
# toString(path to desktop) # -> "[alias] Macintosh HD:Users:mklement:Desktop:"
# To test this subroutine and see the various representations, use the following:
# repeat with elem in {42, 3.14, "two", true, (current date), {"one", "two", "three"}, {one:1, two:"deux", three:false}, missing value, me, path to desktop, front window of application (path to frontmost application as text)}
# log my toString(contents of elem)
# end repeat
on toString(anyObj)
local i, txt, errMsg, orgTids, oName, oId, prefix
set txt to ""
repeat with i from 1 to 2
try
if i is 1 then
if class of anyObj is list then
set {orgTids, AppleScript's text item delimiters} to {AppleScript's text item delimiters, {", "}}
set txt to ("{" & anyObj as string) & "}"
set AppleScript's text item delimiters to orgTids # '
else
set txt to anyObj as string
end if
else
set txt to properties of anyObj as string
end if
on error errMsg
# Trick for records and record-*like* objects:
# We exploit the fact that the error message contains the desired string representation of the record, so we extract it from there. This (still) works as of AS 2.3 (OS X 10.9).
try
set txt to do shell script "egrep -o '\\{.*\\}' <<< " & quoted form of errMsg
end try
end try
if txt is not "" then exit repeat
end repeat
set prefix to ""
if class of anyObj is not in {text, integer, real, boolean, date, list, record} and anyObj is not missing value then
set prefix to "[" & class of anyObj
set oName to ""
set oId to ""
try
set oName to name of anyObj
if oName is not missing value then set prefix to prefix & " name=\"" & oName & "\""
end try
try
set oId to id of anyObj
if oId is not missing value then set prefix to prefix & " id=" & oId
end try
set prefix to prefix & "] "
end if
return prefix & txt
end toString
# Create a split to run commands in or simply run a command in a tab
on splitOrRun(aSession, commandRecord)
# default value ----v
set shellCmd to (command of (commandRecord & ({command:""})))
set splitsCmds to (splits of (commandRecord & ({splits:{}})))
if shellCmd is not "" then
tell application "iTerm"
tell aSession
write text shellCmd
end tell
end tell
else if splitsCmds is not {} then
repeat with j from 1 to count of splitsCmds
set splitRecord to item j of splitsCmds
set splitType to (splitType of (splitRecord & ({splitType:""})))
set splitCmd to (command of (splitRecord & ({command:""})))
if j = 1 then
# The tab itself doesn't need to be split.
tell application "iTerm"
tell aSession
write text splitCmd
end tell
end tell
else
if splitType = "v" then
tell application "iTerm"
tell aSession
set splitSession to split vertically with default profile
tell splitSession
write text splitCmd
end tell
end tell
end tell
else if splitType = "h" then
tell application "iTerm"
tell aSession
set splitSession to split horizontally with default profile
tell splitSession
write text splitCmd
end tell
end tell
end tell
else
display dialog "Invalid or no splitType defined in " & toString(splitRecord) ¬
with icon caution
end if
end if
end repeat
else
display dialog "We couldn't find a 'command' or 'splits' key in " & toString(commandRecord) ¬
with icon caution
end if
end splitOrRun
# Launch or bring to front
if application "iTerm" is running then
tell application "iTerm"
create window with default profile
end tell
else
activate application "iTerm"
end if
# Main Entry Point
tell application "iTerm"
repeat with i from 1 to count of termCommands
set termCommand to item i of termCommands
# since a new window already has a new tab
# the first command gets sent into this tab
if i = 1 then
set mySession to current session of current window
# applescript wants to send this to iTerm, "my" cancels that.
my splitOrRun(mySession, termCommand)
else
tell current window
set termTab to create tab with default profile
set mySession to current session of termTab
# applescript wants to send this to iTerm, "my" cancels that.
my splitOrRun(mySession, termCommand)
end tell
end if
end repeat
end tell