-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path00 Import scripts to cues.applescript
233 lines (172 loc) · 7.53 KB
/
00 Import scripts to cues.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
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
-- @description Import scripts to cues
-- @author Ben Smith
-- @link bensmithsound.uk
-- @version 1.2
-- @testedmacos 10.13.6
-- @testedqlab 4.6.10
-- @about Run this script in MacOS's "Script Editor" to quickly create script cues using the scripts in this repository. As of Qlab 4.6.9 you cannot set "run in separate process" through applescript. Input your default, and the script will alert you if you need to change it.
-- @separateprocess TRUE
-- @changelog
-- v1.2 + updated console logging to log all available information when not all metadata tags are provided
-- + non-tagged scripts now import into cues named without ".applescript" extension
-- + updated trimLine function formatting (replaced snake_case with camelCase)
-- USER DEFINED VARIABLES -----------------
set defaultSeparateProcess to "TRUE" -- your Qlab default for script cues as a string, either "TRUE" or "FALSE"
set versionWarnings to true -- set to false if you do not with to be notified about version differences between your system and the system the scripts have been tested on
---------- END OF USER DEFINED VARIABLES --
-- RUN SCRIPT -----------------------------
-- Get user input: scripts to generate cues for
set scriptFiles to choose file with prompt "Please select the scripts to import" of type {"public.text"} with multiple selections allowed
-- Repeat with each selected script
repeat with eachScript in scriptFiles
-- Create a list of each line of the script
set eachScriptContents to paragraphs of (read eachScript)
set scriptContents to ""
log "-----------"
repeat with eachLine in eachScriptContents
-- Get tags
if eachLine contains "@description" then
set eachScriptDescription to trimLine(eachLine, "-- @description ", 0)
log "Description: " & eachScriptDescription
else if eachLine contains "@author" then
set eachScriptAuthor to trimLine(eachLine, "-- @author ", 0)
log "Author: " & eachScriptAuthor
else if eachLine contains "@source" then
set eachScriptSource to trimLine(eachLine, "-- @source ", 0)
log "Source: " & eachScriptSource
else if eachLine contains "@version" then
set eachScriptVersion to trimLine(eachLine, "-- @version ", 0)
log "Version: " & eachScriptVersion
else if eachLine contains "@testedmacos" then
set eachScriptMacOS to trimLine(eachLine, "-- @testedmacos ", 0)
log "MacOS: " & eachScriptMacOS
else if eachLine contains "@testedqlab" then
set eachScriptQlab to trimLine(eachLine, "-- @testedqlab ", 0)
log "Qlab: " & eachScriptQlab
else if eachLine contains "@about" then
set eachScriptAbout to trimLine(eachLine, "-- @about ", 0)
log "About: " & eachScriptAbout
else if eachLine contains "@separateprocess" then
set eachScriptSeparateProcess to trimLine(eachLine, "-- @separateprocess ", 0)
log "Separate Process: " & eachScriptSeparateProcess
end if
-- Get script source
if eachLine does not contain "-- @" and eachLine does not contain "-- " then
set scriptContents to scriptContents & "
" & eachLine
end if
set scriptContents to my trimLine(scriptContents, "
", 0)
end repeat
tell application id "com.figure53.Qlab.4" to tell front workspace
-- Get cue to write, or create cue
set selectedCues to (selected as list)
if (length of scriptFiles is 1) and (length of selectedCues is 1) and (q type of item 1 of selectedCues is "Script") then
set scriptCue to last item of (selected as list)
else
make type "Script"
set scriptCue to last item of (selected as list)
end if
-- Set cue name
try
set q name of scriptCue to eachScriptDescription
on error
tell application "System Events"
set cueName to name of eachScript
set cueName to my trimLine(cueName, ".applescript", 1)
end tell
set q name of scriptCue to cueName
end try
-- Set cue note
try
set cueNote to eachScriptAbout
try
set cueNote to cueNote & " (" & eachScriptAuthor
try
set cueNote to cueNote & " // " & eachScriptSource & ")"
on error
set cueNote to cueNote & ")"
end try
end try
set notes of scriptCue to cueNote
end try
-- Set script source
try
set script source of scriptCue to "-- @version " & eachScriptVersion & "
" & scriptContents
on error
set script source of scriptCue to scriptContents
end try
-- Alert user if "run in separate process" should be off
try
if eachScriptSeparateProcess is not defaultSeparateProcess then
display dialog "The script \"" & eachScriptDescription & "\" requires you to change the state of \"Run in separate process\" in the script tab of the inspector"
end if
end try
-- Get current version of Qlab
set currentQlabVersion to version of application id "com.figure53.Qlab.4"
log "Current Qlab Version: " & currentQlabVersion
-- Get current version of MacOS
set currentMacOSVersion to system version of (system info)
log "Current MacOS Version: " & currentMacOSVersion
-- Warn user of version differences
if versionWarnings is true then
try
if currentMacOSVersion is not eachScriptMacOS then
set versionIssueMacOS to true
else
set versionIssueMacOS to false
end if
if currentQlabVersion is not eachScriptQlab then
set versionIssueQlab to true
else
set versionIssueQlab to false
end if
if versionIssueMacOS is true and versionIssueQlab is false then
-- Issue with MacOS version
display notification "Be aware that this script has not been tested with your version of MacOS" with title eachScriptDescription
log "The script \"" & eachScriptDescription & "\" has not been tested with your current version of MacOS. TESTED: " & eachScriptMacOS & ", CURRENT: " & currentMacOSVersion
else if versionIssueMacOS is false and versionIssueQlab is true then
-- Issue with Qlab version
display notification "Be aware that this script has not been tested with your version of Qlab" with title eachScriptDescription
log "The script \"" & eachScriptDescription & "\" has not been tested with your current version of Qlab. TESTED: " & eachScriptQlab & ", CURRENT: " & currentQlabVersion
else if versionIssueMacOS is true and versionIssueQlab is true then
-- Issue with MacOS and Qlab versions
display notification "Be aware this this script has not been tested with your version of MacOS or your version of Qlab" with title eachScriptDescription
log "The script \"" & eachScriptDescription & "\" has not been tested with your current version or MacOS or your current version of Qlab. MACOS TESTED: " & eachScriptMacOS & ", CURRENT: " & currentMacOSVersion & ". QLAB TESTED: " & eachScriptQlab & ", CURRENT: " & currentQlabVersion
end if
end try
end if
end tell
end repeat
-- FUNCTIONS ------------------------------
on trimLine(theText, trimChars, trimIndicator)
-- trimIndicator options:
-- 0 = beginning
-- 1 = end
-- 2 = both
set x to the length of the trimChars
---- Trim beginning
if the trimIndicator is in {0, 2} then
repeat while theText begins with the trimChars
try
set theText to characters (x + 1) thru -1 of theText as string
on error
-- if the text contains nothing but the trim characters
return ""
end try
end repeat
end if
---- Trim ending
if the trimIndicator is in {1, 2} then
repeat while theText ends with the trimChars
try
set theText to characters 1 thru -(x + 1) of theText as string
on error
-- if the text contains nothing but the trim characters
return ""
end try
end repeat
end if
return theText
end trimLine