CAPTAIN SLOG

[Updated with new version that calculates duration NOV17]

A simple workspace with cues you can cut and paste into your cue lists to log times to a text file. Creates or opens a file on the desktop, called SHOW LOGGER. Here it is in action:

How it Works:

Adapted from script at http://www.macosxautomation.com/

set themessage to “Intermission”
set this_data to ((current date) as string) & space & themessage & return
set target_file to (((path to desktop folder) as string) & “SHOW LOGGER”)
set append_data to true
try
set the target_file to the target_file as string
set the open_target_file to open for access file target_file with write permission
if append_data is false then set eof of the open_target_file to 0
write this_data to the open_target_file starting at eof
close access the open_target_file
return true
on error
try
close access file target_file
end try
return false
end try

You can download the workspace here

Log with Calculations

You can build on the above workspace to add calculated running times to the log.

If you are going to include running times in your report then the best solution is probably going to be writing the epoch time when a log cue is triggered into the cue’s notes field.  That way if you panic the workspace you are not going to lose any running timers.
Unix Epoch time is defined as the number of seconds since midnight at the start of January 1, 1970
As you are going to refer to those notes fields you need to have a numbering convention for the Log cues e.g LOG1 LOG2 etc. so you will be able to retrieve these values when you come to do the calculations.
When you want to calculate the total running times, or the running time of any section, you simply subtract the value of the beginning of section  notes field from  the end of section notes field, e.g
((notes of cue “LOG2”) – (notes of cue “LOG1”))
will give you the duration of act 1.
 ((notes of cue “LOG2”) – (notes of cue “LOG1”)) + ((notes of cue“LOG4”) – (notes of cue “LOG3”))
will give you the playing time of a 2 act play without interval.
You then just need to convert from epoch seconds to a HH:MM:SS string.
Here’s the workspace:
logging workspace
And here’s a sample output:
showlogger

Show File Name

The Show file name is taken from the workspace file name

using terms from application “Finder”
set themessage to “———————————————————–” & return & “SHOW FILE: ” & name of front document of application id “com.figure53.qlab.3” as string
end using terms from

Tbe data is written to the logging file with this

set this_data to themessage & return & return
set target_file to (((path to desktop folder) as string) & “SHOW LOGGER”)
set append_data to true
try
set the target_file to the target_file as string
set the open_target_file to open for access file target_file with write permission
if append_data is false then set eof of the open_target_file to 0
write this_data to the open_target_file starting at eof
close access the open_target_file
return true
on error
try
close access file target_file
end try
return false
end try

Log Cues

The log cue scripts are all identical with the exception of the  text to be logged and cues they reference:

set themessage to “Curtain Up”
set thedate to current date
set this_data to (thedate as string) & space & themessage & return
set target_file to (((path to desktop folder) as string) & “SHOW LOGGER”)
set append_data to true
try
set the target_file to the target_file as string
set the open_target_file to open for access file target_file with write permission
if append_data is false then set eof of the open_target_file to 0
write this_data to the open_target_file starting at eof
close access the open_target_file
tell application id “com.figure53.qlab.3” to tell front workspace
set notes of cue “LOG1” to (do shell script “date +%s”) as integer
end tell
return true
on error
try
close access file target_file
end try
return false
end try
end

In the above example themessage is set to “Curtain up”. The time as a string is appended to this and the whole string is written to the log file.

Then the epoch seconds are obtained by running a shell script

set notes of cue “LOG1” to (do shell script “date +%s”) as integer

Which gets the epoch seconds  and writes them to the notes cue.

Adding Log Cues

If we wanted to modify this script to log the House Open time we would:

Copy and paste cue LOG1 in the cue list to create a new cue which we number LOG0

Change the first line of the script to: set themessage to “House Open”

and the shell script line to: set notes of cue “LOG0” to (do shell script “date +%s”) as integer

Report Cues

The report cues are again, similar

tell application id “com.figure53.qlab.3” to tell front workspace
try
set thesecs to (notes of cue “LOG2”) – (notes of cue “LOG1”)
set theHours to (thesecs div 3600)
set theRemainderSeconds to (thesecs mod 3600) as integer
set theMinutes to (theRemainderSeconds div 60)
set theRemainderSeconds to (theRemainderSeconds mod 60)
if length of (theHours as text) = 1 then
set theHours to “0” & (theHours as text)
end if
if length of (theMinutes as text) = 1 then
set theMinutes to “0” & (theMinutes as text)
end if
if length of (theRemainderSeconds as text) = 1 then
set theRemainderSeconds to “0” & theRemainderSeconds as text
end if
set notes of cue “LOGA” to (theHours & “:” & theMinutes & “:” & theRemainderSeconds)
end try
set this_data to return & ” ACT1 Running Time: ” & notes of cue “LOGA” & return
set target_file to (((path to desktop folder) as string) & “SHOW LOGGER”)
set append_data to true
try
set the target_file to the target_file as string
set the open_target_file to open for access file target_file with write permission
if append_data is false then set eof of the open_target_file to 0
write this_data to the open_target_file starting at eof
close access the open_target_file
return true
on error
try
close access file target_file
end try
return false
end try
end tell

A variable, thesecs, is set to the value of the calculation. In the above example, (notes of cue “LOG2”) – (notes of cue “LOG1”), to get the act 1 running time in seconds by subtracting the value of the notes field of cue “LOG1” from the value of the notes of cue “LOG2”,

The result in seconds is then converted to a string to give the duration in a more readable format, HH:MM:SS

This is then put into a data string with a string identifying what the duration refers to, and written to the log file

Adding Report Cues

Again, these scripts are easily modified to report other durations e.g to create a cue which logged the length of the pre show, from house open to curtain up you could:

Copy and paste cue LOGA in the cue list to create a new cue which we could number LOGZ

change the calculation line to:

set thesecs to (notes of cue “LOG1”) – (notes of cue “LOG0”)

set the 2 instances of  cue “LOGA” in the script to cue “LOGZ”

Change the text,  ”      ACT1 Running Time: ” to ”   PRESHOW Running Time: ”

Wait times

To enable the log and report cues to be cut and pasted to anywhere in the cue list, every cue contains the script instructions to write the data to the show log file. This means that you could, for instance,  write the interval time duration straight after you logged the curtain up act 2 time. Because each cue will open and close the log file for writing you need to leave time for this to happen before sending another cue that writes to the file. This is best achieved by putting any multiple log cues into a group and using predates to separate them by a second or so.

You can download the v2 workspace with the calculate and report additions here

Refining The Scripts

The flexibility of every cue being self contained and capable of doing everything it needs to within its own script is useful. In certain circumstances e.g where we had a lot of log cues and complex reports, there would be a lot of duplicated code in the scripts. If we wanted to amend something in all the scripts, e.g change the path or name of the file that cues logged to, or even send email notifications with durations as soon as they are logged, then there would be a considerable amount of changes to duplicate scripts.

If we were writing our workspace as a conventional computer programme, we would, as far as possible, only have one instance of code for each task, e.g writing to a file, converting seconds to an hh:mm:ss string etc. We would achieve this by calling subroutines  and functions. Because in QLab variables are only preserved within their own cues, there is no straightforward way to have blocks of script shared between cues.

However, in the same way we used cue’s notes fields to hold variables we can also use these fields to pass variables from  script cues to  other script cues containing subroutines, and back again.

This has the disadvantage that, without the cues containing the subroutines being present in the workspace, the main script cues would be unable to function, but this has many potential uses so we will explore another version of this workspace which uses this idea.

We will also refine the log and report cues so that any information that needs to be changed in duplicated cues, e.g. to change the report structure to  3 act play with 2 intervals is put at the top of the scripts, and is clearly annotated, so it is not necessary to hunt through the script to find variables and strings that need to be changed for the new use.

The new cue list with the added subroutine cues now looks like this:

sub routine cues

The new cues can be anywhere in the workspace. You could create a new cue list called something like logging helpers if you didn’t want them in your main cue list. If you were going to use this extensively then you could put the whole of this list in a logging cue list in your template file, and then just cut and paste the LOG cues in to the main cue list as needed., or use start cues in the main list to trigger them.

The cue CALC 1 contains the script to convert seconds to a string in HH:MM:SS format

set mycue to “CALC1”
tell application id “com.figure53.qlab.3” to tell front workspace
try
set thesecs to notes of cue mycue
set theHours to (thesecs div 3600)
set theRemainderSeconds to (thesecs mod 3600) as integer
set theMinutes to (theRemainderSeconds div 60)
set theRemainderSeconds to (theRemainderSeconds mod 60)
if length of (theHours as text) = 1 then
set theHours to “0” & (theHours as text)
end if
if length of (theMinutes as text) = 1 then
set theMinutes to “0” & (theMinutes as text)
end if
if length of (theRemainderSeconds as text) = 1 then
set theRemainderSeconds to “0” & theRemainderSeconds as text
end if
set notes of cue mycue to (theHours & “:” & theMinutes & “:” & theRemainderSeconds)
end try
end tell

It uses the notes field to receive the value from the cue which triggers it (the calling cue) and returns the value to this field.

The cue WRITE works in the same way using the notes field for the message it is going to write

set mycue to “WRITE”
tell application id “com.figure53.qlab.3” to tell front workspace
set this_data to notes of cue mycue & return
set target_file to (((path to desktop folder) as string) & “SHOW LOGGER”)
set append_data to true
try
set the target_file to the target_file as string
set the open_target_file to open for access file target_file with write permission
if append_data is false then set eof of the open_target_file to 0
write this_data to the open_target_file starting at eof
close access the open_target_file
return true
on</ span> error
try
close access file target_file
end try
return false
end try
end tell

Here’s the much shorter script for one of the logging cues:

set mycue to “LOG1”
set themessage to “Curtain Up”
tell application id “com.figure53.qlab.3” to tell front workspace
set notes of cue mycue to (do shell script “date +%s”) as integer
set thedate to current date
set this_data to (thedate as string) & space & themessage & return
set the notes of cue “WRITE” to this_data
start cue “WRITE”
end tell

It formats the data it wants to write into a string and  sets the notes of cue “WRITE” to that string. It then starts the cue “WRITE”

The report scripts look like this:

set mycue to “LOGA”
tell application id “com.figure53.qlab.3” to tell front workspace
try
set mystring to q name of cue mycue
repeat while the length of mystring is less than 50
set mystring to ” ” & mystring
end repeat
set thesecs to (notes of cue “LOG2”) – (notes of cue “LOG1”)
set the notes of cue “CALC1” to thesecs
start cue “CALC1”
delay 0.2
set the notes of cue mycue to the notes of cue “CALC1”
set the notes of cue “WRITE” to return & mystring & “: ” & notes of cue mycue & return
start cue “WRITE”
end try
end tell

 

 

This performs the calculation of duration as in our previous examples and sets the notes field of cue “CALC1” t the result

cue “CALC 1” is then started and that cue returns the HH:MM:SS string by setting its notes field to the result

The cues name field as the name of the duration in the message (padded with leading spaces by the repeat loop near the top of the script) and includes this together with the calculation of duration result in the string that the notes field of cue “WRITE” is set to.

You can download this workspace here

Cover Image:photo taken by Georges Jansoone on 26 May 2005 distributed under a Creative Commons Attribution Share Alike Unported license. Modified image by Mic Pool distributed under the same license.

MenuGraphic