Skip to content

Commit

Permalink
Applescript builds json config file (#9)
Browse files Browse the repository at this point in the history
* Applescript to generate config file

* Start implementing extra setting for only one Qlab machine

* Update

* Get appropriate info from config

* Delete qlab-info-config.json
  • Loading branch information
bsmith96 committed Oct 26, 2021
1 parent d55b1a2 commit 1fe8649
Show file tree
Hide file tree
Showing 3 changed files with 150 additions and 33 deletions.
150 changes: 138 additions & 12 deletions open-stage-control-module/Get-IDs.applescript
Original file line number Diff line number Diff line change
@@ -1,29 +1,155 @@
-- @description Get Unique IDs for Open Stage Control monitoring
-- @author Ben Smith
-- @link bensmithsound.uk
-- @version 1.1
-- @version 2.0
-- @testedmacos 10.14.6
-- @testedqlab 4.6.10
-- @about Run this script on your Qlab mac, with Qlab open on the cue list you wish to monitor remotely. Paste the result into the "workspaceID" and "cueListID" fields of open-stage-control-config.json.
-- @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 to the root location
-- @separateprocess TRUE

-- @changelog
-- v1.1 + doesn't switch to Qlab to display confirmation dialog
-- v2.0 + writes config automatically


-- USER DEFINED VARIABLES -----------------

---------- END OF USER DEFINED VARIABLES --


-- VARIABLES FROM QLAB NOTES --------------

------------------ END OF QLAB VARIABLES --


property util : script "Applescript Utilities"


---- RUN SCRIPT ---------------------------

-- determine if this computer is MAIN or BACKUP
set thisMac to (choose from list {"Main", "Backup", "Only"} with title "Which QLab mac is this?") as string

-- get IP address of this computer
set listIPs to getIP()
set thisIP to chooseIP(listIPs)

-- get QLab and Cue List info
tell application id "com.figure53.Qlab.4" to tell front workspace

-- get unique IDs
set workspaceID to unique id
set cueListID to uniqueID of current cue list
set thisWorkspaceID to unique id
set thisCueListID to uniqueID of current cue list

end tell

-- write text to paste in config file
set jsonString to "\"workspaceID\":\"" & workspaceID & "\",
\"cueListID\": \"" & cueListID & "\""
-- format for JSON
if thisMac is "Main" then
set jsonString to " \"QlabCount\": 2,
\"QlabMain\": {
\"ip\": \"" & thisIP & "\",
\"workspaceID\": \"" & thisWorkspaceID & "\",
\"cueListID\": \"" & thisCueListID & "\"
},
"
else if thisMac is "Backup" then
set jsonString to "\"QlabBackup\": {
\"ip\": \"" & thisIP & "\",
\"workspaceID\": \"" & thisWorkspaceID & "\",
\"cueListID\": \"" & thisCueListID & "\"
}
}"
else if thisMac is "Only" then
set jsonString to " \"QlabCount\": 1,
\"QlabMain\": {
\"ip\": \"" & thisIP & "\",
\"workspaceID\": \"" & thisWorkspaceID & "\",
\"cueListID\": \"" & thisCueListID & "\"
}
}"
end if

-- write to config file
writeToConfig(jsonString)

-- FUNCTIONS ------------------------------

on getRootFolder()
set thePath to path to me

-- copy the text
set the clipboard to jsonString
tell application "Finder"
set thePath to parent of thePath
end tell
end getRootFolder

on getIP()
try
set theReturned to (do shell script "ifconfig | grep inet | grep -v inet6 | cut -d\" \" -f2")
set theIPs to util's splitString(theReturned, "")
on error
set theIPs to {"Can't get Local IP"}
end try
return theIPs
end getIP

on chooseIP(theIPs)
set theIP to (choose from list theIPs with prompt "Choose which IP to use") as string
return theIP
end chooseIP

on checkConfig()
set configFile to ((getRootFolder() as text) & "qlab-info-config.json")
set configContents to readFile(configFile)
if configContents is "error" then
set configPreface to ¬
"{
\"control\": {
\"address\": {
\"name\": \"/next/name\",
\"number\": \"/next/number\"
}
},
"

writeToFile(configPreface, configFile, false)
end if
return configFile
end checkConfig

on writeToConfig(theText)
set configFile to checkConfig()

-- confirm
display dialog jsonString with title "Copied to clipboard!"
writeToFile(theText, configFile, true)
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
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
Expand Down
15 changes: 12 additions & 3 deletions open-stage-control-module/get-cue-list-playhead.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,18 @@ var config = loadJSON("qlab-info-config.json");
var nameAddress = config.control.address.name;
var numAddress = config.control.address.number;

var qlabIP = config.QlabMain.ip;
var workspaceID = config.QlabMain.workspaceID;
var cueListID = config.QlabMain.cueListID;
if (config.QlabCount = 1) {
var qlabIP = config.QlabMain.ip;
var workspaceID = config.QlabMain.workspaceID;
var cueListID = config.QlabMain.cueListID;
} else if (config.QlabCount = 2) {
var qlabIP = config.QlabMain.ip;
var workspaceID = config.QlabMain.workspaceID;
var cueListID = config.QlabMain.cueListID;
var qlabIP_B = config.QlabBackup.ip;
var workspaceID_B = config.QlabBackup.workspaceID;
var cueListID_B = config.QlabBackup.cueListID;
};

// config includes data for Backup Qlab – this has not yet been implemented

Expand Down
18 changes: 0 additions & 18 deletions open-stage-control-module/qlab-info-config.json

This file was deleted.

0 comments on commit 1fe8649

Please sign in to comment.