-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1-generate-module-config.applescript
223 lines (184 loc) · 6.7 KB
/
1-generate-module-config.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
-- @description Get Unique IDs for Open Stage Control monitoring
-- @author Ben Smith
-- @link bensmithsound.uk
-- @version 3.2
-- @about
-- Store this script in the directory you will be running the Open Stage Control custom module from, on that computer
-- Using remote file accesss over the network, open and run the script in script editor on your Main and Backup Qlab macs
-- Ensure QLab is open, and the current cue list is the one you wish to monitor
-- It will write to a config file in the root location
-- @separateprocess TRUE
-- @changelog
-- v3.2 + add setting for separate trigger and playback cue lists
---- RUN SCRIPT ---------------------------
-- determine if this computer is MAIN or BACKUP
set thisMac to (choose from list {"Main", "Backup"} with title "Which QLab mac is this?") as string
checkMain(thisMac)
-- get the cue list to display playhead of
set theCueLists to getCueLists()
set thisCueList to chooseOption(theCueLists, "trigger cue list")
-- get the cue list to display running cues of
set thisCueListPlaying to chooseOption(theCueLists, "playback cue list")
-- get IP address of this computer
set listIPs to getIP()
set thisIP to chooseOption(listIPs, "IP address")
-- get TCP or UDP from the user
if thisMac is "Main" then
set useProtocol to button returned of (display dialog "Would you like to use TCP or UDP to connect to Qlab? TCP is recommended" with title "Please select protocol" buttons {"TCP", "UDP", "Cancel"} default button "TCP" cancel button "Cancel")
set displayTransport to button returned of (display dialog "Would you like to display transport controls?" with title "Transport controls" buttons {"Full", "Next/Prev", "No"} default button "No")
else
set useProtocol to "not needed"
set displayTransport to "not needed"
end if
-- get QLab and Cue List info
tell application id "com.figure53.Qlab.4" to tell front workspace
-- get unique IDs
set thisWorkspaceID to unique id
set thisCueListID to uniqueID of (first cue list whose q name is thisCueList)
set thisCueListPlayingID to uniqueID of (first cue list whose q name is thisCueListPlaying)
end tell
-- format for JSON
if thisMac is "Main" then
set jsonString to " \"QlabMain\": {
\"ip\": \"" & thisIP & "\",
\"workspaceID\": \"" & thisWorkspaceID & "\",
\"cueListID\": \"" & thisCueListID & "\",
\"cueListPlayingID\": \"" & thisCueListPlayingID & "\"
},
\"QlabCount\": 1
}"
else if thisMac is "Backup" then
set jsonString to "\"QlabBackup\": {
\"ip\": \"" & thisIP & "\",
\"workspaceID\": \"" & thisWorkspaceID & "\",
\"cueListID\": \"" & thisCueListID & "\",
\"cueListPlayingID\": \"" & thisCueListPlayingID & "\"
},
\"QlabCount\": 2
}"
end if
-- write to config file
writeToConfig(jsonString, thisMac, useProtocol, displayTransport)
-- FUNCTIONS ------------------------------
on getRootFolder()
set thePath to path to me
tell application "Finder"
set thePath to parent of thePath
end tell
end getRootFolder
on getCueLists()
tell application id "com.figure53.Qlab.4" to tell front workspace
set theCueLists to every cue list
set theCueListNames to {}
repeat with eachList in theCueLists
set end of theCueListNames to q display name of eachList
end repeat
return theCueListNames
end tell
end getCueLists
on getIP()
try
set theReturned to (do shell script "ifconfig | grep inet | grep -v inet6 | cut -d\" \" -f2")
set theIPs to splitString(theReturned, "")
on error
set theIPs to {"Can't get Local IP"}
end try
return theIPs
end getIP
on chooseOption(theList, theName)
set theOption to (choose from list theList with prompt "Choose " & theName) as string
return theOption
end chooseOption
on checkConfig(thisMac, useProtocol, displayTransport)
set configFile to ((getRootFolder() as text) & "qlab-info-config.json")
if thisMac is "Main" then
set configPreface to ¬
"{
\"control\": {
\"address\": {
\"name\": \"/next/name\",
\"number\": \"/next/number\"
},
\"useTCP\": "
if useProtocol is "TCP" then
set configPreface to configPreface & "true"
else if useProtocol is "UDP" then
set configPreface to configPreface & "false"
end if
set configPreface to configPreface & ",
\"displayTransport\": "
if displayTransport is "Full" then
set configPreface to configPreface & "\"full\""
else if displayTransport is "Next/Prev" then
set configPreface to configPreface & "\"reduced\""
else if displayTransport is "No" then
set configPreface to configPreface & "\"false\""
end if
set configPreface to configPreface & "
},
"
writeToFile(configPreface, configFile, false)
end if
return configFile
end checkConfig
on checkMain(thisMac)
set configFile to ((getRootFolder() as text) & "qlab-info-config.json")
set configContents to readFile(configFile)
if configContents is "error" and thisMac is "Backup" then
display dialog "Please run this script on the Main Qlab first" with title "Alert" with icon stop
error -128
else if item -2 of configContents is " \"QlabCount\": 2" and thisMac is "Backup" then
display dialog "Please run this script on the Main Qlab first, to generate an updated config file" with title "Alert" with icon stop
error -128
end if
log item -2 of configContents
end checkMain
on writeToConfig(theText, thisMac, useProtocol, displayTransport)
set configFile to checkConfig(thisMac, useProtocol, displayTransport)
if thisMac is "Main" then
writeToFile(theText, configFile, true)
else if thisMac is "Backup" then
writeToFile(theText, configFile, "backup")
end if
end writeToConfig
on writeToFile(thisData, targetFile, appendData) -- (string, file path as string, boolean)
try
set the targetFile to the targetFile as text
set the openTargetFile to ¬
open for access file targetFile with write permission
if appendData is false then ¬
set eof of the openTargetFile to 0
if appendData is "backup" then ¬
set eof of the openTargetFile to ((get eof of the openTargetFile) - 16)
write thisData to the openTargetFile starting at eof
close access the openTargetFile
return true
on error
try
close access file targetFile
end try
return false
end try
end writeToFile
on readFile(theFile)
try
set theFile to theFile as text
set fileContents to paragraphs of (read file theFile)
return fileContents
on error
return "error"
end try
end readFile
on splitString(theString, theDelimiter)
-- save delimiters to restore old settings
set oldDelimiters to AppleScript's text item delimiters
-- set delimiters to delimiter to be used
set AppleScript's text item delimiters to theDelimiter
-- create the array
set theArray to every text item of theString
-- restore old setting
set AppleScript's text item delimiters to oldDelimiters
-- return the array
return theArray
end splitString