QLab Scripts and Macros

Contents

Table of Contents

General tips

-Many of these scripts were written for QLab 2, and need some adjustments to run properly in QLab 3. If you need help with a script that doesn't run correctly in QLab 3, post to our Google Group or email us at support@figure53.com
-For a great collection of updated scripts from QLab user Rich Walsh, see this post.
-Another great resource for both scripting and other advanced QLab tricks is Mic Pool's QLab Cookbook.
- There are two ways to script QLab: with Script Cues, or by running a script externally (eg: as an application, in AppleScript Editor, in Automator or via the Script menulet - if enabled). NB: it's a very bad idea to run scripts in AppleScript Editor with the Event Log open (unless you are debugging), as it really slows things down…
- Scripts run from within QLab don't need a tell application "QLab" clause. If you are developing your scripts in the Snow Leopard version of AppleScript Editor then you can enable show "tell" application pop-up menu on the Editing tab of the Preferences, which allows you to work as if you were within QLab - but with the benefit of event logging and error reporting.
- Some scripts, such as level bumps, lend themselves to being called by a Hot Key to act on the currently selected cue in QLab; these scripts should exist in the workspace as Script Cues with Hot Keys to fire them. NB: because they are Hot Keys they will fire even if the workspace they are in isn't the current one!
- Other scripts are best run externally - either because you won't need to run them more than once on a workspace, or because they interact with many other applications.
- It's a good idea to put all your Hot Key scripts in a separate cue list that can be disarmed (and then eventually deleted) for show running.

Using the Script menulet

This is the most efficient way to run external scripts:

  1. In Snow Leopard, open the General tab of AppleScript Editor's Preferences; in Leopard, open AppleScript Utility (in /Applications/AppleScript/).
  2. Tick Show Script menu in menu bar.
  3. Next to Show application scripts at: select top.
  4. Create a folder called "Applications" in ~/Library/Scripts.
  5. Put your QLab scripts in a folder called "QLab" in ~/Library/Scripts/Applications.
  6. When QLab is the front application, you can run your scripts from the Script menu, ie: the icon that looks like an "S" (or a scroll) towards the top right of the screen.
  7. If nothing seems to happen (or you don't get the result you are expecting), hold down the alt key whilst selecting the script: this will open it in AppleScript Editor instead of running it. From here you can run the script again with event logging and error reporting to help troubleshoot the issue. A common cause is that "UI element scripting" has not been enabled (see below).

If that's still not efficient enough for you (it does involve the mouse, after all!), you could create a Script Cue in QLab on a Hot Key to call one of these long external scripts, eg:

-- Replace the name of the script as necessary:
run script (POSIX path of (path to scripts folder) & "/Applications/QLab/Batch adjust selected.scpt")

UI element scripting

Some aspects of QLab (and other applications) are not directly scriptable, but can be controlled by a script via "UI element scripting". This sends commands to an application as if the user were using the mouse/keyboard to select menus, click checkboxes, etc. It is not turned on by default - you need to turn it on:

The three main commands that won't work without this are "click", "perform" and "select". The complete AppleScript terminology for UI scripting is available from the "Processes Suite" entries in the System Events AppleScript dictionary.

A well-written script that relies on UI element scripting should check that "UI elements enabled" is true before attempting to run code that won't work if it isn't! For example:

-- NOTE: This script is for QLab 2. It will not work with QLab 3
-- Toggle status of "Use MIDI Show Control" preference
-- This script works best as a Hot Key script
-- This script won't work properly if there isn't a workspace open in QLab,
-- or if the Workspace Preferences window is already open!
 
tell application "System Events"
    if UI elements enabled then
        -- Without the "ignoring" command, the script won't run in QLab
        -- as the Script Cue locks up the application and prevents QLab responding.
        ignoring application responses
            tell application "QLab"
                activate
            end tell
            keystroke "," using {command down}
            delay 1 -- This gives you a chance to see the current state
            tell application process "QLab"
                tell front window
                    set selected of row 3 of table 1 of scroll area 1 to true
                    click checkbox "Use MIDI Show Control" of group "MIDI Show Control" of group 1
                end tell
            end tell
            delay 1 -- This gives you a chance to see what happened
            keystroke "," using {command down}
        end ignoring
    else
        tell application "System Preferences"
            activate
            set current pane to pane "com.apple.preference.universalaccess"
            display dialog "UI element scripting is not enabled. Check \"Enable access for assistive devices\"."
        end tell
    end if
end tell

Basics

Starting a cue

Super-simple example of starting cue 1 in the front workspace.

tell application "QLab"
    tell front workspace
        start cue "1"
    end tell
end tell

Boring technical stuff if you're interested: in the absence of any qualifying grammar, the "1" means the cue whose AppleScript name is "1"; for QLab, the AppleScript name of an object is its "q number" (as distinct from its "q name", ie: what appears in the "Q" column) - so, if you have a cue ''numbered'' "1" the above script will start it...

Setting levels

Set master to -10

Set the master volume of the selected Audio Cue(s) to -10dB:

tell application "QLab"
    set mySel to selected of workspace 1
    repeat with myCue in mySel
        if q type of myCue is "Audio" then
            myCue setLevel row 0 column 0 db -10
        end if
    end repeat
end tell

Level bump

Rich Walsh (Last tested with QLab 2.3.4 & Mac OS X 10.6.7)

Bump the Master on the Levels tab of the currently selected Audio, Video or Fade Cue(s) +2.5dB (it should be obvious how to change that number) [Hot Key]:

set userBump to 2.5
repeat with eachCue in (selected of front workspace as list)
    try
        set currentLevel to eachCue getLevel row 0 column 0
        eachCue setLevel row 0 column 0 db (currentLevel + userBump)
    end try
end repeat

Add/Subtract Levels

Sam Kusnetz (Tested in QLab 2.2.6; Mac OS X 10.6.2)

I use this script bound to a hotkey such as control-L (for "level") so that I can easily respond to the sound designer saying things like "bump up those last three cues by 2 db." I command-click to select the cues, then hit my hotkey, type in +2, and enter. Boom.

display dialog "Change the master level of selected cues by this much:" default answer "0" with title "Change Level" with icon 1 buttons {"Cancel", "OK"} default button "OK" cancel button "Cancel"
 
set changeAmount to text returned of result
 
set theSelection to selected of front workspace
repeat with eachCue in theSelection
    if q type of eachCue is "Audio" or q type of eachCue is "Fade" then
        tell front workspace
            set currentLevel to eachCue getLevel row 0 column 0
            set newLevel to currentLevel + changeAmount
            eachCue setLevel row 0 column 0 db newLevel
        end tell
    end if
end repeat

Update for Qlab 3
Rusty Wandall (Tested with Qlab 3.1.11)

tell application id "com.figure53.qlab.3" to tell front workspace
display dialog "Change the master level of selected cues by this much:" default answer "0" with title "Change Level" with icon 1 buttons {"Cancel", "OK"} default button "OK" cancel button "Cancel"

set changeAmount to text returned of result

set theSelection to selected
repeat with eachCue in theSelection
    if q type of eachCue is "Audio" or q type of eachCue is "Fade" then
        tell front workspace
            set currentLevel to eachCue getLevel row 0 column 0
            set newLevel to currentLevel + changeAmount
                eachCue setLevel row 0 column 0 db newLevel
            end tell
        end if
    end repeat
end tell

Fades

Create fade out

Chris Ashworth

Create a Fade Cue directly under the selected Audio Cue which fades the audio to silence over 10 seconds:

tell application "QLab"
    set mySel to selected of workspace 1
    set originalCue to last item of mySel
    if q type of originalCue is "Audio" then
        tell workspace 1
            make type "Fade"
            set mySel to selected -- (QLab will select the newly created cue.)
            set newCue to last item of mySel
            set cue target of newCue to originalCue
            set duration of newCue to 10
            newCue setLevel row 0 column 0 db -120
        end tell
    end if
end tell

NB: alternate syntax for getting the selected cue:

set originalCue to last item of (selected of workspace 1 as list)

Create fade out v2

Rich Walsh, Jeremy Lee (Last tested with QLab 2.3.4 & Mac OS X 10.6.7)

Create a 5s default fade out (and stop) of the currently selected Group, Audio or Video Cue (or target of currently selected Fade Cue) as the next cue in the cue list (the script does not stop (targeted) Video Cues) [Hot Key]:

set userDuration to 5
tell front workspace
    set originalCue to last item of (selected as list)
    set originalCueType to q type of originalCue
    if originalCueType is in {"Group", "Audio", "Video"} then
        make type "Fade"
        set newCue to last item of (selected as list)
        set cue target of newCue to originalCue
        set duration of newCue to userDuration
        newCue setLevel row 0 column 0 db -120
        if originalCueType is not "Video" then
            set stop target when done of newCue to true
        end if
        set q name of newCue to "Fade out: " & q name of originalCue
    else if originalCueType is "Fade" then
        set originalCueTarget to cue target of originalCue
        make type "Fade"
        set newCue to last item of (selected as list)
        set cue target of newCue to originalCueTarget
        set duration of newCue to userDuration
        newCue setLevel row 0 column 0 db -120
        if q type of originalCueTarget is not "Video" then
            set stop target when done of newCue to true
        end if
        set q name of newCue to "Fade out: " & q name of originalCueTarget
    end if
end tell

Create fade in

Rich Walsh (Last tested with QLab 2.3.4 & Mac OS X 10.6.7)

Create a 5s default fade in of the currently selected Audio Cue as the next cue in the cue list (also set the Master on the Levels tab of the Audio Cue to -INF and create a follow-on) [Hot Key]:

set userDuration to 5
tell front workspace
    set originalCue to last item of (selected as list)
    if q type of originalCue is "Audio" then
        set originalCueLevel to originalCue getLevel row 0 column 0
        originalCue setLevel row 0 column 0 db -120
        set continue mode of originalCue to auto_continue
        make type "Fade"
        set newCue to last item of (selected as list)
        set cue target of newCue to originalCue
        set duration of newCue to userDuration
        newCue setLevel row 0 column 0 db originalCueLevel
        set q name of newCue to "Fade in: " & q name of originalCue
    end if
end tell

Create fade in (no follow-on)

Rich Walsh (Last tested with QLab 2.3.4 & Mac OS X 10.6.7)

Create a 5s default fade in of the currently selected Audio Cue as the next cue in the cue list (also set the Master on the Levels tab of the Audio Cue to -INF and copy the Pre Wait time from the Audio Cue - for use in a "Fire all children simultaneously" Group Cue) [Hot Key]:

set userDuration to 5
tell front workspace
    set originalCue to last item of (selected as list)
    if q type of originalCue is "Audio" then
        set originalCueLevel to originalCue getLevel row 0 column 0
        originalCue setLevel row 0 column 0 db -120
        set originalPreWait to pre wait of originalCue
        make type "Fade"
        set newCue to last item of (selected as list)
        set cue target of newCue to originalCue
        set pre wait of newCue to originalPreWait
        set duration of newCue to userDuration
        newCue setLevel row 0 column 0 db originalCueLevel
        set q name of newCue to "Fade in: " & q name of originalCue
    end if
end tell

Build/dip

Rich Walsh, Jeremy Lee (Last tested with QLab 2.3.4 & Mac OS X 10.6.7)

Create a 5s default fade of the currently selected Group, Audio or Video Cue (or target of currently selected Fade Cue) as the next cue in the cue list, adding 5dB to the Master on the Levels tab (the script does nothing if the selected Fade Cue targets a Group Cue) [Hot Key]:

set userDuration to 5
set userLevel to 5 -- Change this to -5 for a dip
set kindString to "Build: " -- Change this to "Dip: "
tell front workspace
    set originalCue to last item of (selected as list)
    set originalCueType to q type of originalCue
    if originalCueType is "Group" then
        make type "Fade"
        set newCue to last item of (selected as list)
        set cue target of newCue to originalCue
        set duration of newCue to userDuration
        newCue setLevel row 0 column 0 db userLevel
        set q name of newCue to kindString & q name of originalCue
    else if originalCueType is in {"Audio", "Video"} then
        make type "Fade"
        set newCue to last item of (selected as list)
        set cue target of newCue to originalCue
        set duration of newCue to userDuration
        set currentLevel to originalCue getLevel row 0 column 0
        newCue setLevel row 0 column 0 db (currentLevel + userLevel)
        set q name of newCue to kindString & q name of originalCue
    else if originalCueType is "Fade" then
        set originalCueTarget to cue target of originalCue
        if q type of originalCueTarget is not "Group" then
            make type "Fade"
            set newCue to last item of (selected as list)
            set cue target of newCue to originalCueTarget
            set duration of newCue to userDuration
            set currentLevel to originalCue getLevel row 0 column 0
            newCue setLevel row 0 column 0 db (currentLevel + userLevel)
            set q name of newCue to kindString & q name of originalCueTarget
        end if
    end if
end tell

Crash fades

Rich Walsh (Last tested with QLab 2.3.4 & Mac OS X 10.6.7)

Crash selected Fade Cue(s) to just before completion, starting their target cues (the script will start the target Audio Cue(s) for the selected Fade Cue(s), load the Fade Cue(s) to just before completion and start them) [Hot Key]:

set userDuration to 1 -- This is the time remaining to which to load the Fade Cue(s) before starting them
repeat with eachCue in (selected of front workspace as list)
    if q type of eachCue is "Fade" then
        if running of cue target of eachCue is false then
            start cue target of eachCue
        end if
        stop eachCue -- In case the Fade Cue is a follow-on from its target
        set eachDuration to ((pre wait of eachCue) + (duration of eachCue)) -- Include the Pre Wait for effective duration!
        if eachDuration > userDuration then
            load eachCue time eachDuration - userDuration
        end if
        start eachCue
    end if
end repeat

Force fades

Rich Walsh (Last tested with QLab 2.3.4 & Mac OS X 10.6.7)

Force selected Fade Cue(s) to completion (the script will also act on Fade Cues within selected Group Cues) [Hot Key]:

set userDuration to 1 -- This is the time the fade(s) will be forced to complete in
set userEnterIntoGroups to true -- Set this to false if you don't want the script to act on Fade Cues within selected Group Cues
tell front workspace
    set cuesToProcess to (selected as list)
    set processedIDs to {}
    set fadeCues to {}
    set originalPreWaits to {}
    set originalDurations to {}
    set originalContinueModes to {}
    set countCues to count cuesToProcess
    set i to 0
    repeat until i = countCues -- Extract just the Fade Cues
        set eachCue to item (i + 1) of cuesToProcess
        set eachType to q type of eachCue
        if eachType is "Fade" then
            set eachID to uniqueID of eachCue
            if eachID is not in processedIDs then
                set end of fadeCues to eachCue
                set end of processedIDs to eachID
            end if
        else if userEnterIntoGroups is true and eachType is "Group" then
            set cuesToProcess to cuesToProcess & cues of eachCue
            set countCues to count cuesToProcess
        end if
        set i to i + 1
    end repeat
    repeat with eachCue in fadeCues
        stop eachCue
        set end of originalPreWaits to pre wait of eachCue
        set end of originalDurations to duration of eachCue
        set end of originalContinueModes to continue mode of eachCue
        set pre wait of eachCue to 0
        set duration of eachCue to userDuration
        set continue mode of eachCue to do_not_continue
        start eachCue
    end repeat
    delay userDuration + 0.1 -- Give the cue(s) time to complete before resetting to the original variables
    repeat with i from 1 to count fadeCues
        set eachCue to item i of fadeCues
        stop eachCue -- In case of Post Wait…
        set pre wait of eachCue to item i of originalPreWaits
        set duration of eachCue to item i of originalDurations
        set continue mode of eachCue to item i of originalContinueModes
    end repeat
end tell

Force running fades

Rich Walsh (Last tested with QLab 2.3.4 & Mac OS X 10.6.7)

Force running Fade Cue(s) to completion [Hot Key]:

set userDuration to 1 -- This is the time the fade(s) will be forced to complete in
tell front workspace
    set fadeCues to {}
    set originalPreWaits to {}
    set originalDurations to {}
    set originalContinueModes to {}
    repeat with eachCue in (active cues as list) -- Extract just the Fade Cues
        if q type of eachCue is "Fade" then
            set end of fadeCues to eachCue
        end if
    end repeat
    repeat with eachCue in fadeCues
        stop eachCue
        set end of originalPreWaits to pre wait of eachCue
        set end of originalDurations to duration of eachCue
        set end of originalContinueModes to continue mode of eachCue
        set pre wait of eachCue to 0
        set duration of eachCue to userDuration
        set continue mode of eachCue to do_not_continue
        start eachCue
    end repeat
    delay userDuration + 0.1 -- Give the cue(s) time to complete before resetting to the original variables
    repeat with i from 1 to count fadeCues
        set eachCue to item i of fadeCues
        stop eachCue -- In case of Post Wait…
        set pre wait of eachCue to item i of originalPreWaits
        set duration of eachCue to item i of originalDurations
        set continue mode of eachCue to item i of originalContinueModes
    end repeat
end tell

Audio Cues

Edit target file

Rich Walsh (Last tested with QLab 2.3.4 & Mac OS X 10.6.7)

Edit selected Audio Cue's target (in Audacity); if Audacity takes more than 60s to open, the script will time out before switching to it; remember to "Refresh Files" after you've edited [Hot Key]:

set userApplication to application "Audacity" -- This can be changed to the editor of your choice
tell front workspace
    set selectedCue to last item of (selected as list)
    if q type of selectedCue is "Audio" then
        set fileTarget to file target of selectedCue
        ignoring application responses
            tell userApplication
                open fileTarget
                activate
            end tell
        end ignoring
    end if
end tell

Open target file

Rich Walsh (Last tested with QLab 2.3.4 & Mac OS X 10.6.7)

Open selected Audio Cue's target (it will open the audio file in whichever application it is set to "Open with" - in the Finder's Get Info window) [Hot Key]:

tell front workspace
    set selectedCue to last item of (selected as list)
    if q type of selectedCue is "Audio" then
        set fileTarget to file target of selectedCue
        tell application "Finder"
            open fileTarget
        end tell
    end if
end tell

Reveal target file

Rich Walsh (Last tested with QLab 2.3.4 & Mac OS X 10.6.7)

Reveal selected Audio Cue's target in Finder [Hot Key]:

tell front workspace
    set selectedCue to last item of (selected as list)
    if q type of selectedCue is "Audio" then
        set fileTarget to file target of selectedCue
        tell application "Finder"
            reveal fileTarget
            activate
        end tell
    end if
end tell

Edit target of video or audio cues (alternate)

permalink

Edit target of video or audio cues

-- Edit target audio or image file for selected cue
-- Tim Rogers <timmrogers@gmail.com>
-- Original script by Rich Walsh at 
https://figure53.hostedwiki.co/pages/QLab%20Scripts%20and%20Macros
-- TODO - Extend to edit other file types

-- Set audio editor (Audacity or Ocenaudio should work nicely as well)
set myAudioApplication to application "Fission"
-- Set image editor 
set myImageApplication to application "Pixelmator"

tell application id "com.figure53.qlab.3" to tell front workspace

    set selectedCue to last item of (selected as list)

    if q type of selectedCue is "Audio" then
        set fileTarget to file target of selectedCue
        ignoring application responses
            tell myAudioApplication
                open fileTarget
                activate
            end tell
        end ignoring
    end if

    if q type of selectedCue is "Video" then
        set fileTarget to file target of selectedCue
        tell application "Finder" to set {myFileType, myNameExt} 
to ({file type, name extension} of file fileTarget)
        if (myNameExt is "gif") or (myNameExt is "jpg") 
or (myNameExt is "png") then
            ignoring application responses
                tell myImageApplication
                    open fileTarget
                    activate
                end tell
            end ignoring
        end if
    end if

end tell

Make mono

Rich Walsh (Last tested with QLab 2.3.4 & Mac OS X 10.6.7)

Set crosspoints of selected Audio Cue(s) for mono routing (crosspoints will be set at 0dB for mono files and -6dB for stereo files) [Hot Key]:

repeat with eachCue in (selected of front workspace as list)
    try
        if audio input channels of eachCue is 1 then
            repeat with i from 1 to 48
                setLevel eachCue row 1 column i db 0
            end repeat
        else if audio input channels of eachCue is 2 then
            repeat with i from 1 to 48
                setLevel eachCue row 1 column i db -6
                setLevel eachCue row 2 column i db -6
            end repeat
        end if
    end try
end repeat

Change target

Rich Walsh (Last tested with QLab 2.3.4 & Mac OS X 10.6.7)

Change selected Audio Cue's target (keeping times; it will also keep the cue's name) [Hot Key]:

set selectedCue to last item of (selected of front workspace as list)
if q type of selectedCue is "Audio" then
    set currentStart to start time of selectedCue
    set currentLoopStart to loop start time of selectedCue
    set currentLoopEnd to loop end time of selectedCue
    set currentEnd to end time of selectedCue
    set currentFileTarget to file target of selectedCue
    if currentFileTarget is not missing value then
        tell application "System Events"
            set whereToLook to POSIX path of container of (currentFileTarget as alias)
        end tell
        set newFileTarget to choose file of type "public.audio" with prompt "Please select the new File Target:" default location (whereToLook as POSIX file) ¬
            without invisibles
    else
        set newFileTarget to choose file of type "public.audio" with prompt "Please select the new File Target:" without invisibles
    end if
    set file target of selectedCue to newFileTarget
    set start time of selectedCue to currentStart
    set loop start time of selectedCue to currentLoopStart
    set loop end time of selectedCue to currentLoopEnd
    set end time of selectedCue to currentEnd
end if

Convert to wav for QLab 2

Rich Walsh (Last tested with QLab 2.3.4 & Mac OS X 10.6.7)

Convert selected Audio Cue's target to wav, if it isn't one already (using the "afconvert" command line utility: can be modified to convert to aiff instead; the script keeps times but resets the cue's name; bit depth and sample rate are user-defined within the script) [Hot Key]:

set userFormat to item 1 of {"wav", "aif"} -- Change this to "item 2" to convert to aiff
set userBitDepth to 16
set userBitRate to 44100
 
-- Declarations
 
global dialogTitle
set dialogTitle to "Convert to " & userFormat
 
-- Prepare some variables
 
if userFormat is "wav" then
    set acceptableTypes to {"com.microsoft.waveform-audio"}
    set formatString to "WAVE -d LEI"
else if userFormat is "aif" then
    set acceptableTypes to {"public.aifc-audio", "public.aiff-audio"}
    set formatString to "AIFF -d BEI"
else
    return -- Protection against erroneous user modification
end if
 
-- Convert the cue
 
set selectedCue to last item of (selected of front workspace as list)
if q type of selectedCue is "Audio" then
    try
        set currentFileTarget to file target of selectedCue as alias
        tell application "System Events"
            set currentType to type identifier of currentFileTarget
        end tell
        if currentType is not in acceptableTypes then
            set currentStart to start time of selectedCue
            set currentLoopStart to loop start time of selectedCue
            set currentLoopEnd to loop end time of selectedCue
            set currentEnd to end time of selectedCue
            tell application "System Events"
                set theContainer to path of container of currentFileTarget
                set theExtension to name extension of currentFileTarget
                if theExtension is "" then
                    set theName to name of currentFileTarget
                else
                    set theFullName to name of currentFileTarget
                    set theName to text 1 through (-1 - (length of theExtension)) of theFullName
                end if
                set newFileTarget to theContainer & theName & userFormat
                set fileExists to exists file newFileTarget
            end tell
            if fileExists is true then
                display dialog "The destination file for the conversion already exists. What now?" with title dialogTitle ¬
                    with icon 0 buttons {"Cancel", "Replace"} default button "Replace" cancel button "Cancel"
            end if
            display dialog "Preparing to convert..." with title dialogTitle with icon 1 ¬
                buttons {"Cancel", "OK"} default button "OK" cancel button "Cancel" giving up after 3 -- You have 3s to change your mind
            do shell script "afconvert -f " & formatString & userBitDepth & "@" & userBitRate & " " & ¬
                quoted form of POSIX path of currentFileTarget & " " & quoted form of POSIX path of newFileTarget
            set file target of selectedCue to newFileTarget
            set start time of selectedCue to currentStart
            set loop start time of selectedCue to currentLoopStart
            set loop end time of selectedCue to currentLoopEnd
            set end time of selectedCue to currentEnd
            set q name of selectedCue to theName & userFormat -- Remove this line if you don't want to reset the cue name too
            display dialog "Done." with title dialogTitle with icon 1 buttons {"OK"} default button "OK" giving up after 5
        end if
    end try
end if

Convert to wav for QLab 3

originally by Rich Walsh, minor adjustments by Freddy Komp (Last tested with QLab 3.1.22 & Mac OS X 10.8.5)

Convert selected Audio Cue targets to wav, if it isn't one already (using the "afconvert" command line utility: can be modified to convert to aiff instead; the script keeps times but resets the cue's name; bit depth and sample rate are user-defined within the script) [Hot Key]:

-- I have merely updated his original script from Rich Walsh in order to be compatible with QLab 3
-- I have copied all available properties apart from levels etc - some of these might not be required or operate in unexpected ways,
-- but I currently lack time or inclination to test :)
set userFormat to item 1 of {"wav", "aif"} -- Change this to "item 2" to convert to aiff
set userBitDepth to 16
set userBitRate to 44100

-- Declarations

global dialogTitle
set dialogTitle to "Convert to " & userFormat

-- Prepare some variables

if userFormat is "wav" then
    set acceptableTypes to {"com.microsoft.waveform-audio"}
    set formatString to "WAVE -d LEI"
else if userFormat is "aif" then
    set acceptableTypes to {"public.aifc-audio", "public.aiff-audio"}
    set formatString to "AIFF -d BEI"
else
    return -- Protection against erroneous user modification
end if

-- Convert the cue
set createdCues to {} as list

set allCues to (selected of front workspace as list)
repeat with selectedCue in allCues
    if q type of selectedCue is "Audio" then
        try
            set currentFileTarget to file target of selectedCue as alias
            tell application "System Events"
                set currentType to type identifier of currentFileTarget
            end tell
            if currentType is not in acceptableTypes then
                set currentPatch to patch of selectedCue
                set currentStart to start time of selectedCue
                set currentEnd to end time of selectedCue
                set currentPlayCount to play count of selectedCue
                set currentinfLoop to infinite loop of selectedCue
                set currentRate to rate of selectedCue
                set currentIntegratedFade to integrated fade of selectedCue
                set currentPitchShift to pitch shift of selectedCue
                tell application "System Events"
                    set theContainer to path of container of currentFileTarget
                    set theExtension to name extension of currentFileTarget
                    if theExtension is "" then
                        set theName to name of currentFileTarget
                    else
                        set theFullName to name of currentFileTarget
                        set theName to text 1 through (-1 - (length of theExtension)) of theFullName
                    end if
                    set newFileTarget to theContainer & theName & userFormat
                    set fileExists to exists file newFileTarget
                end tell
                if fileExists is true then
                    display dialog "The destination file for the conversion already exists. What now?" with title dialogTitle ¬
                        with icon 0 buttons {"Cancel", "Replace"} default button "Replace" cancel button "Cancel"
                end if
                do shell script "afconvert -f " & formatString & userBitDepth & "@" & userBitRate & " " & ¬
                    quoted form of POSIX path of currentFileTarget & " " & quoted form of POSIX path of newFileTarget
                set file target of selectedCue to newFileTarget
                set patch of selectedCue to currentPatch
                set start time of selectedCue to currentStart
                set end time of selectedCue to currentEnd
                set play count of selectedCue to currentPlayCount
                set infinite loop of selectedCue to currentinfLoop
                set rate of selectedCue to currentRate
                set integrated fade of selectedCue to currentIntegratedFade
                set pitch shift of selectedCue to currentPitchShift
                set q name of selectedCue to theName & userFormat -- Remove this line if you don't want to reset the cue name too
            end if
        end try
    end if
end repeat
display dialog "Done." with title dialogTitle with icon 1 buttons {"OK"} default button "OK" giving up after 5

Times

Total Time

Michael Portrie (Last tested with Qlab 3.1.2 & Mac OS X 10.10.2)

Adds together the total durations of the selected cues, and displays the total in a pop-up window.

--Created Mar 2, 2015 by Michael Portrie
--mportrie@gmail.com
--This script was written for Qlab 3, last tested with Mac OS X 10.10.2

tell application id "com.figure53.qlab.3" to tell front workspace
    set appTime to 0
    set thisTime to 0
    repeat with eachCue in (selected as list)
        try
            set thisTime to (duration of eachCue)
            set appTime to thisTime + appTime
        end try

    end repeat
    set appHours to (appTime div 3600)
    set appHoursRemainder to (appTime mod 3600)
    set appMinutes to (appHoursRemainder div 60)
    set appSeconds to (round (appHoursRemainder mod 60))
    display dialog "The total time of the selected cues is 
 " & appHours & ":" & appMinutes & ":" & appSeconds & "
(h)(m)(s)" with title "Total Time - by Michael Portrie" with icon 1
end tell

Show total time for selected cues (updated)

permalink

No more estimating the total length of the audio files for pre-show or intermission music. Just select them and press the hot-key that you have associated with this script!

--Created by Michael Portrie <mportrie@gmail.com>
-- Updated by Tim Rogers <timmrogers@gmail.com>

tell application id "com.figure53.qlab.3" to tell front workspace
    set totalSeconds to 0
    set thisSeconds to 0
    repeat with eachCue in (selected as list)
        try
            set thisSeconds to (duration of eachCue)
            set totalSeconds to thisSeconds + totalSeconds
        end try
    end repeat

    set h to totalSeconds div 3600
    set s to totalSeconds - h * 3600
    set m to s div 60
    set s to s - m * 60

    if h < 10 then
        set h to text -2 thru -1 of ("00" & h)
    else
        set h to h as text
    end if

    if m < 10 then set m to text -2 thru -1 of ("00" & m)
    if s < 10 then set s to text -2 thru -1 of ("00" & s)

    set prettySeconds to (h & ":" & m & ":" & s)

    display dialog "The total time of the selected cues is " 
& prettySeconds with title "Total Time" with icon 1
end tell

Show total time for selected cues (Alternate)

Another option for seeing total length of the audio files but through notifications so you never loose control of your workspace.

--Created by Michael Portrie <mportrie@gmail.com>
-- Updated by Tim Rogers <timmrogers@gmail.com>
-- Altered by Jason Jensen <jsonjensen@gmail.com>

tell application id "com.figure53.qlab.3" to tell front workspace
    set totalSeconds to 0.0
    set thisSeconds to 0.0
    repeat with eachCue in (selected as list)
        try
            set thisSeconds to (duration of eachCue)
            set totalSeconds to thisSeconds + totalSeconds
        end try
    end repeat
    set h to totalSeconds div 3600
    set s to totalSeconds - h * 3600
    set m to s div 60
    set s to s - m * 60
    set s to (round (s * 100)) / 100
    set h to h as text
    if h < 10 then
        set h to text -2 thru -1 of ("00" & h)
    else
        set h to h as text
    end if
    if m < 10 then
        set m to text -2 thru -1 of ("00" & m)
    else
        set m to m as text
    end if
    if s < 10 then
        set s to ("0" & s)
    else
        set s to s as text
    end if
    set prettySeconds to (h & ":" & m & ":" & s)
    display notification prettySeconds with title "Total Time"

end tell

Adjust Pre Wait

Rich Walsh (Last tested with QLab 2.3.4 & Mac OS X 10.6.7)

Add 1s to the Pre Wait of the currently selected cue(s) [Hot Key]:

set userDelta to 1
repeat with eachCue in (selected of front workspace as list)
    try
        set currentPreWait to pre wait of eachCue
        set pre wait of eachCue to (currentPreWait + userDelta)
    end try
end repeat

Adjust Duration

Rich Walsh (Last tested with QLab 2.3.4 & Mac OS X 10.6.7)

Add 1s to the Duration of the currently selected cue(s) [Hot Key]:

set userDelta to 1
repeat with eachCue in (selected of front workspace as list)
    try
        set currentDuration to duration of eachCue
        set duration of eachCue to (currentDuration + userDelta)
    end try
end repeat

Adjust Post Wait

Rich Walsh (Last tested with QLab 2.3.4 & Mac OS X 10.6.7)

Add 1s to the Post Wait of the currently selected cue(s) [Hot Key]:

set userDelta to 1
repeat with eachCue in (selected of front workspace as list)
    try
        set currentPostWait to post wait of eachCue
        set post wait of eachCue to (currentPostWait + userDelta)
    end try
end repeat

Effective duration

Rich Walsh (Last tested with QLab 2.3.4 & Mac OS X 10.6.7)

Set Post Wait(s) of selected Group Cue(s) to effective duration (for those times when a countdown display is useful...) [Hot Key]:

-- The effective duration of a Group Cue is the time it will take for the longest of its children to complete, ie: the longest effective duration of one of its children
-- Each child cue has an effective Pre Wait, which is the cumulative time that must elapse before this child's Pre Wait is triggered
-- In a "Fire all children simultaneously" Group Cue this effective Pre Wait is 0
-- In a "Fire first child and go to next cue" Group Cue this effective Pre Wait is the sum of all the Pre Waits and Post Waits that have come before
-- Note that auto-follow cues use their Durations as Post Waits (the actual Post Wait property is ignored); this is the value that must be added to the sum above
-- The effective duration of a single cue that does not auto-follow is the sum of its effective Pre Wait, Duration & Post Wait
-- The effective duration of a single cue that does auto-follow is the sum of its effective Pre Wait & Duration
 
repeat with eachCue in (selected of front workspace as list)
    try
        set eachMode to mode of eachCue
        set longestChildEffectiveDuration to 0
        if eachMode is fire_all then
            repeat with eachChild in cues of eachCue
                set eachChildEffectiveDuration to (pre wait of eachChild) + (duration of eachChild) + (post wait of eachChild)
                if eachChildEffectiveDuration > longestChildEffectiveDuration then
                    set longestChildEffectiveDuration to eachChildEffectiveDuration
                end if
            end repeat
        end if
        if eachMode is fire_first_go_to_next_cue then
            set effectivePreWait to 0
            repeat with eachChild in cues of eachCue
                set eachPre to pre wait of eachChild
                set effectivePreWait to effectivePreWait + eachPre
                set eachContinueMode to continue mode of eachChild
                if eachContinueMode is auto_follow then
                    set eachPost to duration of eachChild
                    set eachChildEffectiveDuration to effectivePreWait + eachPost
                else
                    set eachPost to post wait of eachChild
                    set eachChildEffectiveDuration to effectivePreWait + (duration of eachChild) + eachPost
                end if
                set effectivePreWait to effectivePreWait + eachPost
                if eachChildEffectiveDuration > longestChildEffectiveDuration then
                    set longestChildEffectiveDuration to eachChildEffectiveDuration
                end if
                if eachContinueMode is do_not_continue then
                    exit repeat -- No point looking at any further children that aren't part of the sequence
                end if
            end repeat
        end if
        set post wait of eachCue to longestChildEffectiveDuration
    end try
end repeat

Create adjustable auto-follow

Rich Walsh (Last tested with QLab 2.3.4 & Mac OS X 10.6.7)

Set a cue to auto-continue, but with the Post Wait preset to be the same as its Duration (or, optionally, a fixed amount more/less for gaps/overlaps) - like an auto-follow cue, but one where you can change the auto-follow time [Hot Key]:

set userDelta to 0 -- Change this to a negative value to have cues overlap
repeat with eachCue in (selected of front workspace as list)
    set post wait of eachCue to ((duration of eachCue) + userDelta)
    set continue mode of eachCue to auto_continue
end repeat

Batch adjusting

Reset names

Rich Walsh (Last tested with QLab 2.3.4 & Mac OS X 10.6.7)

Reset name of selected cue(s) (the script will reset the name of an Audio, Video or MIDI File Cue to its File Target, name other types of cue based on their type and Cue Target, or name MIDI Cues based on their parameters; other cues that have neither File nor Cue Target are unaffected) [Hot Key]:

-- This script can optionally convert note numbers in MIDI Cues to note names: use the variable below to set the behaviour
 
set userNote60Is to item 1 of {"", "C3", "C4"} -- Use this to set which note name corresponds to note 60; "item 1" will mean note numbers are not converted
 
-- Declarations
 
global userNote60Is, noteNames
set noteNames to {"C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"}
 
-- Main routine
 
repeat with eachCue in (selected of front workspace as list)
    try -- Audio, Video or MIDI File Cues
        set eachFile to file target of eachCue as alias -- This line will log an exception innocuously in the Console if it throws an error, despite the try block
        tell application "System Events"
            set eachName to name of eachFile
        end tell
        set q name of eachCue to eachName
    on error
        try -- Fade, Animation, Start, Stop, Pause, Reset, Devamp, Load, Goto, Target, Arm or Disarm Cues
            set eachTarget to q name of cue target of eachCue
            set eachType to q type of eachCue
            if eachType is "Fade" then
                if stop target when done of eachCue is true then
                    set q name of eachCue to "Fade out: " & eachTarget
                else
                    set q name of eachCue to "Fade: " & eachTarget
                end if
            else
                set q name of eachCue to eachType & ": " & eachTarget
            end if
        on error
            try -- MIDI Cues
                set eachChannel to channel of eachCue
                set eachCommand to command of eachCue
                if eachCommand is note_on then
                    set byteOne to byte one of eachCue
                    set byteTwo to byte two of eachCue
                    set q name of eachCue to "Channel " & eachChannel & " | Note On | " & my configureNoteNameString(byteOne) & " @ " & byteTwo
                else if eachCommand is note_off then
                    set byteOne to byte one of eachCue
                    set byteTwo to byte two of eachCue
                    set q name of eachCue to "Channel " & eachChannel & " | Note Off | " & my configureNoteNameString(byteOne) & " @ " & byteTwo
                else if eachCommand is program_change then
                    set byteOne to byte one of eachCue
                    set q name of eachCue to "Channel " & eachChannel & " | Program Change | " & byteOne
                else if eachCommand is control_change then
                    set byteOne to byte one of eachCue
                    set byteTwo to byte two of eachCue
                    set q name of eachCue to "Channel " & eachChannel & " | Control Change | " & byteOne & " @ " & byteTwo
                else if eachCommand is key_pressure then
                    set byteOne to byte one of eachCue
                    set byteTwo to byte two of eachCue
                    set q name of eachCue to "Channel " & eachChannel & " | Key Pressure | " & my configureNoteNameString(byteOne) & " @ " & byteTwo
                else if eachCommand is channel_pressure then
                    set byteOne to byte one of eachCue
                    set q name of eachCue to "Channel " & eachChannel & " | Channel Pressure | " & byteOne
                else if eachCommand is pitch_bend then
                    set byteCombo to (byte combo of eachCue) - 8192
                    set q name of eachCue to "Channel " & eachChannel & " | Pitch Bend | " & byteCombo
                end if
            end try
        end try
    end try
end repeat
 
-- Subroutines
 
on configureNoteNameString(noteNumber)
    if userNote60Is is "" then
        return noteNumber
    else if userNote60Is is "C3" then
        set octaveConvention to -2
    else
        set octaveConvention to -1
    end if
    set theOctave to (noteNumber div 12) + octaveConvention
    set theNote to item (noteNumber mod 12 + 1) of noteNames
    set noteNameString to theNote & theOctave
    return noteNameString
end configureNoteNameString

Update filenames

Rich Walsh (Last tested with QLab 2.3.4 & Mac OS X 10.6.7)

Update filename of File Target for selected cue(s) (the script will change the name of the File Target on disk for an Audio, Video or MIDI File Cue to be the same as the name of the cue; QLab's display won't update until you change the selection) [Hot Key]:

repeat with eachCue in (selected of front workspace as list)
    try
        set eachName to q name of eachCue
        set eachTarget to file target of eachCue as alias -- This line will log an exception innocuously in the Console if it throws an error, despite the try block
        tell application "System Events"
            set eachExtension to name extension of eachTarget
            if eachName does not end with eachExtension then
                set name of eachTarget to eachName & "." & eachExtension
            else
                set name of eachTarget to eachName
            end if
        end tell
    end try
end repeat

Toggle arming

Rich Walsh (Last tested with QLab 2.3.4 & Mac OS X 10.6.7)

Toggle arming of selected cue(s) (the script will arm/disarm the current cue list if no cues are selected) [Hot Key]:

tell front workspace
    set selectedCues to (selected as list)
    if (count selectedCues) is 0 then -- If no cues are selected arm/disarm the current cue list
        set armed of current cue list to not armed of current cue list
    else
        repeat with eachCue in reverse of selectedCues -- Reversed so as to do a Group Cue's children before it
            set armed of eachCue to not armed of eachCue
        end repeat
    end if
end tell

Toggle arming of all MSC Cues

Rich Walsh (Last tested with QLab 2.3.4 & Mac OS X 10.6.7)

Toggle arming of all MSC Cues in the workspace [Hot Key]:

tell front workspace
    set foundCues to every cue whose q type is "MSC"
    set foundCuesRef to a reference to foundCues
    repeat with eachCue in foundCuesRef
        set armed of eachCue to not armed of eachCue
    end repeat
end tell

Updated version for QLab 3:

tell front workspace
    set foundCues to every cue whose message type is msc
    set foundCuesRef to a reference to foundCues
    repeat with eachCue in foundCuesRef
        set armed of eachCue to not armed of eachCue
    end repeat
end tell

Batch disarm

Rich Walsh (Last tested with QLab 2.3.4 & Mac OS X 10.6.7)

Arm, disarm or toggle arming of all cues in the workspace whose name contains the string you enter (not case-sensitive); the string is copied to the Clipboard for you to paste in next time [Hot Key]:

set userDefaultSearchString to "REHEARSAL" -- Use this to specify the default search string
 
-- Declarations
 
global dialogTitle
set dialogTitle to "Batch disarm"
 
-- Get the search string
 
set {theText, theButton} to {text returned, button returned} of (display dialog ¬
    "Arm/disarm cues whose name contains (return an empty string to cancel):" with title dialogTitle with icon 1 ¬
    default answer userDefaultSearchString buttons {"Toggle", "Arm", "Disarm"} default button "Disarm")
 
-- Check for cancel
 
if theText is "" then
    error number -128
end if
 
-- Copy the search string to the Clipboard and arm/disarm the cues
 
set the clipboard to theText
 
tell front workspace
    set foundCues to every cue whose q name contains theText
    set foundCuesRef to a reference to foundCues
    repeat with eachCue in reverse of foundCuesRef -- Reversed so as to do a Group Cue's children before it
        if theButton is "Arm" then
            set armed of eachCue to true
        else if theButton is "Disarm" then
            set armed of eachCue to false
        else
            set armed of eachCue to not armed of eachCue
        end if
    end repeat
end tell

Batch adjust continue mode

Rich Walsh (Last tested with QLab 2.3.4 & Mac OS X 10.6.7)

Batch adjust continue mode of selected cue(s) (the script presents a dialog for you to choose the continue mode to apply) [Hot Key]:

-- Declarations
 
global dialogTitle
set dialogTitle to "Batch adjust continue mode"
 
-- Get the continue mode required
 
set {theText, theButton} to {text returned, button returned} of (display dialog ¬
    "Set continue mode of selected cues to (return a non-empty string to cancel):" with title dialogTitle with icon 1 ¬
    default answer "" buttons {"Do not continue", "Auto-continue", "Auto-follow"} default button "Do not continue")
 
-- Check for cancel
 
if theText is not "" then
    error number -128
end if
 
-- Adjust the cues
 
repeat with eachCue in (selected of front workspace as list)
    if theButton is "Do not continue" then
        set continue mode of eachCue to do_not_continue
    else if theButton is "Auto-continue" then
        set continue mode of eachCue to auto_continue
    else if theButton is "Auto-follow" then
        set continue mode of eachCue to auto_follow
    end if
end repeat

Turn on infinite loop

Rich Walsh (Last tested with QLab 2.3.4 & Mac OS X 10.6.7)

Turn on infinite loop in selected Audio or Video Cue(s): [Hot Key]:

repeat with eachCue in (selected of front workspace as list)
    try
        set infinite loop of eachCue to true
    end try
end repeat

Renumber cues with letter names

''Sean Dougall, John Kundert-Gibbs''

This script changes the Q # of each selected cue to A, B, C, ..., Z, AA, AB, AC, etc. '''Note:''' This script can take a while, so it's best run from Automator rather than from a Script Cue in QLab.

tell application "QLab"
    set allCues to selected of workspace 1
    set qNumber to 1
    set alphabet to "ZABCDEFGHJKLMPRSTVWXYZ"
    repeat with myCue in allCues
        set qNumber to qNumber + 1
        set tempNumber to qNumber
        set qLetter to ""
        repeat while tempNumber > 1
            set tempNumber to tempNumber - 1
            set qLetter to (character (tempNumber mod 21 + 1) of alphabet) & qLetter
            set tempNumber to round (tempNumber / 21) rounding up
        end repeat
        set q number of myCue to qLetter
    end repeat
end tell

Patch selected cues

permalink

-- Patch selected cues
-- Tim Rogers <timmrogers@gmail.com>
-- Updated to use OSC /cue/selected syntax

tell application id "com.figure53.qlab.3" to tell front workspace

    display dialog "Type new patch number (1-16 for OSC cues, 1-8 for 
Audio, Mic, MIDI, and Video cues)" with title "New Patch Number" with icon 1 
default answer ""

    try
        set myPatch to (text returned of result) as number
    on error
        display alert "Invalid patch number" message "Please enter a 
valid patch number."
        return
    end try

    set myOSC to "/cue/selected/patch " & myPatch
    do shell script "echo " & myOSC & " | nc -u -w 0 127.0.0.1 53535"

end tell

Mark/Jump

Rich Walsh (Last tested with QLab 2.3.4 & Mac OS X 10.6.7)

Mark selected cue, or jump to previously marked cue (the script uses the Notes field of the Script Cue to store information about the marked cue: if there is no selection, the script will jump to the marked cue; if no cue has been marked, the script will mark the selected cue; if there is a selection and a cue has previously been marked, the script will ask what to do next) [Hot Key]:

-- This script only works if "Playback position is always the selected cue" is ON!
 
-- Declarations
 
global dialogTitle, thisCue
set dialogTitle to "Mark/Jump"
 
-- Main routine
 
tell front workspace
    set thisCue to last item of (active cues as list) -- This should identify this Script Cue
    if q type of thisCue is "Script" then -- Slight error protection
        set myNotes to notes of thisCue
        set selectedCues to (selected as list)
        if (count selectedCues) is 0 then -- There is no selected cue: we are jumping
            if myNotes is not "" then -- Just in case there is no stored cue either
                my jumpToCue(myNotes)
            end if
        else
            if myNotes is "" then -- There is no stored cue: we are marking
                my markCue(last item of selectedCues)
            else if myNotes begins with "This script uses the Notes field" then -- This cue still contains the template text: we are marking
                my markCue(last item of selectedCues)
            else -- There is a stored cue, but we'll check what is required
                set theButton to button returned of (display dialog "Jump to stored cue?" with title dialogTitle ¬
                    with icon 1 buttons {"Mark", "OK"} default button "OK")
                if theButton is "OK" then -- We are jumping
                    my jumpToCue(myNotes)
                else -- We are marking
                    my markCue(last item of selectedCues)
                end if
            end if
        end if
    end if
end tell
 
-- Subroutines
 
on markCue(cueToMark)
    set notes of thisCue to uniqueID of cueToMark
end markCue
 
on jumpToCue(jumpToID)
    tell front workspace
        set notes of thisCue to ""
        try
            set jumpCue to cue id jumpToID
            set theContainer to parent of jumpCue
            repeat until mode of theContainer is cue_list
                set theContainer to parent of theContainer
            end repeat
            set current cue list to theContainer
            set playback position of current cue list to jumpCue
        end try
    end tell
end jumpToCue

Jump to Cue Target

Rich Walsh (Last tested with QLab 2.3.4 & Mac OS X 10.6.7)

Jump to selected cue's target cue [Hot Key]:

-- This script only works if "Playback position is always the selected cue" is ON!
 
tell front workspace
    set selectedCue to last item of (selected as list)
    try
        set cueTarget to cue target of selectedCue
        set theContainer to parent of cueTarget
        repeat until mode of theContainer is cue_list
            set theContainer to parent of theContainer
        end repeat
        set current cue list to theContainer
        set playback position of current cue list to cueTarget
    end try
end tell

Go to next Video Cue

''Chris Ashworth''

Move playback position to next Video Cue [Hot Key]:

tell front workspace
        set currentCue to playback position of current cue list
        set currentCue to cue after currentCue
        repeat while q type of currentCue is not "Video"
                set currentCue to cue after currentCue
        end repeat
        set playback position of current cue list to currentCue
end tell

Go to next broken cue

Rich Walsh (Last tested with QLab 2.3.4 & Mac OS X 10.6.7)

Go to next broken cue in current cue list [Hot Key] - this is considerably faster in a large workspace than the above approach (and can be adjusted to search for other properties; only scrolls down ("next"), not up ("previous")!):

-- This script only works if "Playback position is always the selected cue" is ON!
 
tell front workspace
 
    try
 
        set currentCue to uniqueID of playback position of current cue list -- This will throw an error if there is no selection
 
        set allCues to uniqueID of cues
        set allCuesRef to a reference to allCues
        set countCues to count allCuesRef
        set foundCues to uniqueID of cues whose broken is true -- Change this line to search for different properties, eg: q type is "Audio"
        set foundCuesRef to a reference to foundCues
        set currentIndex to countCues - 1
 
        -- Find where we are in the list
 
        repeat with i from 1 to countCues
            if item i of allCuesRef is currentCue then
                set currentIndex to i
                exit repeat
            end if
        end repeat
 
        -- Find the next "found" cue in the list
 
        repeat with j from currentIndex + 1 to countCues
            set foundIndex to item j of allCuesRef
            if foundIndex is in foundCuesRef then
                set playback position of current cue list to cue id foundIndex
                exit repeat
            end if
        end repeat
 
    end try
 
end tell

Loading

Load to time

Rich Walsh (Last tested with QLab 2.3.4 & Mac OS X 10.6.7)

Load selected cue(s) to a time you enter [Hot Key]:

-- Declarations
 
global dialogTitle
set dialogTitle to "Load to time"
 
-- Check the clipboard for a previous time
 
set currentTIDs to AppleScript's text item delimiters
set AppleScript's text item delimiters to "" -- Can't assume this
 
try
    set clipboardContents to the clipboard -- The time requested previously will have been copied to the Clipboard, and may still be on there
on error
    set clipboardContents to ""
end try
 
if (count paragraphs of clipboardContents) > 1 or (count words of clipboardContents) > 2 or ¬
    ((count words of clipboardContents) > 1 and clipboardContents does not contain ":") then -- Slight protection against spurious Clipboard contents
    set clipboardContents to ""
end if
 
-- Prompt to get the time
 
set theText to ""
repeat until theText is not ""
    set {theText, theButton} to {text returned, button returned} of (display dialog ¬
        "Load selected cues to this time (seconds or minutes:seconds):" with title dialogTitle with icon 1 ¬
        default answer clipboardContents buttons {"Start the cues too", "Cancel", "OK"} default button "OK" cancel button "Cancel")
    set clipboardContents to ""
    try
        set theTime to theText as number
        if theTime < 0 then
            set theText to ""
        end if
    on error
        if theText contains ":" then
            try
                set AppleScript's text item delimiters to ":"
                set theMinutes to word 1 of theText
                set theSeconds to rest of words of theText as string
                set theTime to (theMinutes as number) * 60 + (theSeconds as number)
            on error
                set theText to ""
            end try
        else
            set theText to ""
        end if
    end try
end repeat
 
set AppleScript's text item delimiters to currentTIDs
 
-- Copy the time to the Clipboard
 
set the clipboard to theText
 
-- Load (and start) the cues
 
tell front workspace
    load selected time theTime
    if theButton is "Start the cues too" then
        start selected
    end if
end tell

Jump into a string of cues

Rich Walsh (Last tested with QLab 2.3.4 & Mac OS X 10.6.7)

Jump into a string of cues; the script rather assumes that you are working in such a way that every cue that is triggered by a manual GO is a Group Cue (either "Fire all children simultaneously" or "Fire first child and go to next cue"). In addition to Group Cues, it will also process any selected Memo Cues - but it will ignore all other cue types. For best results, select the first Group Cue that should still be playing and all intervening cues up to and including the last Group Cue you wish to jump into, but not any of its children. [Hot Key]

-- Declarations
 
global dialogTitle
set dialogTitle to "Jump into a string of cues"
 
-- Main routine
 
tell front workspace
 
    -- Check more than one cue selected
 
    try
        set selectedCues to items 1 thru -2 of (selected as list)
    on error
        display dialog "You need to select more than one cue!" with title dialogTitle with icon 0 buttons {"OK"} default button "OK" giving up after 5
        return
    end try
 
    -- Check the clipboard for a previous time
 
    set currentTIDs to AppleScript's text item delimiters
    set AppleScript's text item delimiters to "" -- Can't assume this
 
    try
        set clipboardContents to the clipboard -- The time requested previously will have been copied to the Clipboard, and may still be on there
    on error
        set clipboardContents to ""
    end try
    if (count paragraphs of clipboardContents) > 1 or (count words of clipboardContents) > 2 or ¬
        ((count words of clipboardContents) > 1 and clipboardContents does not contain ":") then -- Slight protection against spurious Clipboard contents
        set clipboardContents to ""
    end if
 
    -- Prompt to get the time
 
    set theText to ""
    repeat until theText is not ""
        set theText to text returned of (display dialog "This script will load the last selected cue to the time you enter below and attempt " & ¬
            "to load any other Group Cues selected so that any fades will effectively have completed when you start the selected cues." & return & return & ¬
            "THIS IS NOT GUARANTEED TO WORK!" & return & return & ¬
            "Enter the load time (seconds or minutes:seconds):" with title dialogTitle with icon 1 ¬
            default answer clipboardContents buttons {"Cancel", "OK"} default button "OK" cancel button "Cancel")
        set clipboardContents to ""
        try
            set theTime to theText as number
            if theTime < 0 then
                set theText to ""
            end if
        on error
            if theText contains ":" then
                try
                    set AppleScript's text item delimiters to ":"
                    set theMinutes to word 1 of theText
                    set theSeconds to rest of words of theText as string
                    set theTime to (theMinutes as number) * 60 + (theSeconds as number)
                on error
                    set theText to ""
                end try
            else
                set theText to ""
            end if
        end try
    end repeat
 
    set AppleScript's text item delimiters to currentTIDs
 
    -- Copy the time to the Clipboard
 
    set the clipboard to theText
 
    -- Clean out cues that won't be processed, and prepare a list for checking to see if remaining selection contains its own children…
 
    set selectedCuesClean to {}
    set childrenIDs to {}
    repeat with eachCue in selectedCues
        if q type of eachCue is in {"Group", "Memo"} then
            set end of selectedCuesClean to eachCue
            try
                set childrenIDs to childrenIDs & uniqueID of cues of eachCue
            end try
        end if
    end repeat
 
    -- Exit if no cues left to process
 
    if (count selectedCuesClean) is 0 then
        display dialog "Not enough Group or Memo Cues selected to proceed." with title dialogTitle ¬
            with icon 0 buttons {"OK"} default button "OK" giving up after 5
        return
    end if
 
    -- Work out the total time to which to load, and temporarily set each Group/Memo Cue to auto-continue
 
    set longestGroupTime to 0
    set summedWaits to 0
    set processedCues to {}
    set continueModes to {}
    repeat with eachCue in selectedCuesClean
        try
            set groupTime to 0
            try
                set eachMode to mode of eachCue
            on error -- Memo Cue
                set eachMode to ""
            end try
 
            -- Skip cues that are children of selected Group Cues
 
            if uniqueID of eachCue is in childrenIDs then
                error
            end if
 
            (* The total time of a "Fire all children simultaneously" Group Cue - the time to which to load it to "complete" -
            is the sum of the Pre Wait and Duration of the Fade Cue that will take longest to complete *)
 
            if eachMode is fire_all then
                set fadeCues to (every cue of eachCue whose q type is "Fade")
                set longestChildFadeTime to 0
                repeat with eachChild in fadeCues
                    set eachChildFadeTime to (pre wait of eachChild) + (duration of eachChild)
                    if eachChildFadeTime > longestChildFadeTime then
                        set longestChildFadeTime to eachChildFadeTime
                    end if
                end repeat
                set groupTime to longestChildFadeTime
            end if
 
            (* The total time of a "Fire first child and go to next cue" Group Cue - the time to which to load it to "complete" -
            is the sum of all the Pre Waits and Post Waits of cues that continue, plus the Duration of the longest Fade Cue *)
 
            if eachMode is fire_first_go_to_next_cue then
                set longestChildFadeTime to 0
                repeat with eachChild in cues of eachCue
                    set groupTime to groupTime + (pre wait of eachChild)
                    set eachContinueMode to continue mode of eachChild
                    if eachContinueMode is auto_continue then
                        set groupTime to groupTime + (post wait of eachChild)
                        if q type of eachChild is "Fade" then
                            set eachChildFadeTime to duration of eachChild
                            if eachChildFadeTime > longestChildFadeTime then
                                set longestChildFadeTime to eachChildFadeTime
                            end if
                        end if
                    else if eachContinueMode is auto_follow then
                        set groupTime to groupTime + (duration of eachChild)
                    else
                        exit repeat -- No point looking at children that aren't part of the sequence; Pre Wait of next child is counted though
                    end if
                end repeat
                set groupTime to groupTime + longestChildFadeTime
            end if
 
            -- Since the Group Cues are being set to auto-continue, loading to the longest of their total times will load them all to "completion"
 
            if groupTime > longestGroupTime then
                set longestGroupTime to groupTime
            end if
 
            (* If any of the Group/Memo Cues have non-zero Pre or Post Waits then these will effectively extend the time to which we have to load,
            so these are summed too *)
 
            set end of processedCues to eachCue
            set end of continueModes to continue mode of eachCue
            set continue mode of eachCue to auto_continue
            set summedWaits to summedWaits + (pre wait of eachCue)
            if contents of eachCue is not last item of selectedCuesClean then
                (* Don't include the penultimate cue's Post wait in the sum as it will be set temporarily to 0 *)
                set summedWaits to summedWaits + (post wait of eachCue)
            end if
 
        end try
    end repeat
 
    -- Temporarily change Post Wait of penultimate Group/Memo Cue in selection so that when the string is loaded all other cues will "complete"
 
    set lastPost to post wait of last item of selectedCuesClean
    set post wait of last item of selectedCuesClean to longestGroupTime + summedWaits
 
    -- Load the cue string and prompt to start it
 
    load first item of selectedCuesClean time longestGroupTime + summedWaits + theTime -- This includes the load to time specified by the user in the dialog
 
    try -- This try means that the rest of the script will complete even if the user cancels
        display dialog "Ready to go?" with title dialogTitle with icon 1 buttons {"Cancel", "OK"} default button "OK" cancel button "Cancel"
        start first item of selectedCuesClean
    end try
 
    -- Reset the cues
 
    repeat with i from 1 to count processedCues
        set continue mode of item i of processedCues to item i of continueModes
    end repeat
    set post wait of last item of selectedCuesClean to lastPost
 
end tell

View

Switch cue lists

''David Bibby, Rich Walsh'' (Last tested with QLab 2.3.4 & Mac OS X 10.6.7)

Switch to the cue list called "Main Cue List" [Hot Key]:

set userCueList to "Main Cue List" -- Use this to specify the name of the cue list
tell front workspace
    set current cue list to first cue list whose q name is userCueList
end tell

General

Stop all playing cues

''Sean Dougall''

This script will immediately stop all running (not necessarily selected) cues in the current workspace, skipping Script Cues so that it can auto-continue to a new cue:

tell application "QLab"
    set cueList to current cue list of workspace 1
    set mySel to cues of cueList
    repeat with myCue in mySel
        if running of myCue and q type of myCue is not "Script" then
            stop myCue
        end if
    end repeat
end tell

Stop All but Group

Some dudes (Last tested with QLab 3.1.9 & Mac OS X 10.10.3)

This script is meant to be placed as the first child in a group, if you target the group and click go, it will run everything in the group but stop anything outside the group. A self-contained stop. It is meant to function with mode: "Start first child and go to next cue"

tell application "QLab"
    tell front workspace
        set activeCues to active cues
        repeat with eachCue in activeCues
            if q type of eachCue is not "Script" and q type of eachCue is not "Group" then
                stop eachCue
            end if
        end repeat
        set activeCues to active cues
        repeat with eachCue in activeCues
            if q type of eachCue is "Script" then
                set thisScript to eachCue
            end if
        end repeat
        set cueToStart to cue after thisScript
        start cueToStart
    end tell
end tell

Add files from iTunes

Rich Walsh (Last tested with QLab 2.3.4 & Mac OS X 10.6.7)

Take selected files in iTunes, add them to the cue list and set the names to match (the script will also attempt to remove track numbers from the start of the names); remember to bundle the workspace at some point to get the audio files in the right place [Hot Key]:

set userAttemptToRemoveTrackNumbers to true -- Set this to false if you don't mind having track numbers in your cue descriptions
 
-- Declarations
 
global dialogTitle
set dialogTitle to "Add files from iTunes"
 
-- Check iTunes is running
 
tell application "System Events"
    set iTunesIsOpen to count (every process whose name is "iTunes")
end tell
if iTunesIsOpen is 0 then
    display dialog "iTunes is not running." with title dialogTitle with icon 0 buttons {"OK"} default button "OK" giving up after 5
    return
end if
 
-- Test for a selection
 
tell application "iTunes"
    set iTunesHasSelection to count (selection as list)
end tell
if iTunesHasSelection is 0 then
    display dialog "There is no selection in iTunes." with title dialogTitle with icon 0 buttons {"OK"} default button "OK" giving up after 5
    return
end if
 
-- Offer escape hatch
 
display dialog "Adding selected files from iTunes..." with title dialogTitle with icon 1 ¬
    buttons {"Cancel", "OK"} default button "OK" cancel button "Cancel" giving up after 3 -- You have 3s to change your mind
 
-- Get the files
 
tell application "iTunes"
    set selectedFiles to (location of selection) as list
end tell
 
-- Get the names
 
set selectedNames to {}
tell application "System Events"
    repeat with eachItem in selectedFiles
        set end of selectedNames to name of eachItem
    end repeat
end tell
 
-- Attempt to remove track numbers, as necessary
 
set cleanedNames to {}
set currentTIDs to AppleScript's text item delimiters
set AppleScript's text item delimiters to "" -- Can't assume this
repeat with eachName in selectedNames
    if userAttemptToRemoveTrackNumbers is true and first character of eachName is in characters of "0123456789" then
        set eachName to (characters ((offset of space in eachName) + 1) thru end of eachName) as text
        (* In Snow Leopard, changes to Scripting Addition security result in double sending if, for example, "offset" is put inside a tell block *)
    end if
    set end of cleanedNames to eachName
end repeat
set AppleScript's text item delimiters to currentTIDs
 
-- Add the files
 
tell front workspace
    repeat with i from 1 to count selectedFiles
        make type "Audio"
        set newCue to last item of (selected as list)
        set file target of newCue to item i of selectedFiles
        set q name of newCue to item i of cleanedNames
    end repeat
end tell
 
display dialog "Done." with title dialogTitle with icon 1 buttons {"OK"} default button "OK" giving up after 5

Add files from iTunes v2

''Oliver Waring''

I have added an option for the selected files to Auto Continue:

display dialog "Adding selected files from iTunes..." with title "QLab script" with icon 0 buttons {"Cancel", "OK"} default button "OK" cancel button "Cancel" giving up after 3 -- You have 3s to change your mind
tell application "iTunes"
    set selectedFiles to (location of selection) as list
end tell
set selectedNames to {}
tell application "System Events"
    repeat with eachItem in selectedFiles
        set selectedNames to selectedNames & name of eachItem
    end repeat
end tell
 
set autocontinue to the button returned of (display dialog "Would you like these cues to Auto Follow?" with title "Auto Continue" with icon 1 buttons {"No", "Yes"} default button "Yes")
 
repeat with i from 1 to count of selectedFiles
    make front workspace type "Audio"
    set newCue to last item of (selected of front workspace as list)
    set file target of newCue to item i of selectedFiles
    set q name of newCue to item i of selectedNames
 
        if autocontinue = "Yes" then
        set continue mode of newCue to auto_follow
    end if
 
end repeat

Make slideshow from selected cues

permalink

-- Create slideshow from selected cues
-- Tim Rogers <timmrogers@gmail.com>

tell application id "com.figure53.qlab.3" to tell front workspace

    display dialog "Enter the number of seconds between cues:" with title "Cues"
 with icon 1 default answer "10"

    try
        set myPostWait to (text returned of result) as number
    on error
        display alert "Invalid number" message "Please enter a valid number."
        return
    end try

    set mySelected to (selected as list)
    set myCount to (count mySelected)

    repeat with myCurrentCue in mySelected

        -- Get the uniqueID of the current cue
        set myID to uniqueID of myCurrentCue

        -- Move the selection to the current cue        
        tell the current cue list
            set playback position to cue id myID
        end tell

        -- Set opacity and continue mode of the current cue
        set opacity of myCurrentCue to 0
        set continue mode of myCurrentCue to auto_continue

        -- If first selected cue        
        if myCurrentCue's contents is the first item of mySelected then
            -- Make new fade cue
            make type "Fade"
            -- and find its name
            set myNewCueList to selected
            set myNewCue to last item of myNewCueList
            -- and set its target, opacity, and post wait
            set cue target of myNewCue to myCurrentCue
            set opacity of myNewCue to 100
            set do opacity of myNewCue to true
            set post wait of myNewCue to myPostWait
            set continue mode of myNewCue to auto_continue
            -- Set previous cue
            set myPreviousCue to myCurrentCue
        -- Otherwise
        else
            -- Make new fade cue
            make type "Fade"
            -- and find its name
            set myNewCueList to selected
            set myNewCue to last item of myNewCueList
            -- and set its target and opacity
            set cue target of myNewCue to myCurrentCue
            set opacity of myNewCue to 100
            set do opacity of myNewCue to true
            set continue mode of myNewCue to auto_continue
            -- Make new fade-and-stop cue
            make type "Fade"
            -- and find its name
            set myNewCueList to selected
            set myNewCue to last item of myNewCueList
            -- and set its target, opacity, post wait, and stop
            set cue target of myNewCue to myPreviousCue
            set opacity of myNewCue to 0
            set do opacity of myNewCue to true
            set post wait of myNewCue to myPostWait
            set stop target when done of myNewCue to true
            set continue mode of myNewCue to auto_continue
            -- Set previous cue
            set myPreviousCue to myCurrentCue
        end if

    end repeat

end tell

Start QAutoSaver

Rich Walsh (Last tested with QLab 2.3.4 & Mac OS X 10.6.7)

A bit of a bodge to start Jason Tratta's rather excellent [http://jasontratta.com/qautosaver QAutoSaver], if it is installed [Hot Key]:

tell application "System Events"
    if (count (every process whose name is "QAutoSaver")) is 0 then
        considering application responses
            launch application "QAutoSaver"
        end considering
    end if
    activate application "QAutoSaver"
    delay 0.5 -- Without this, triggering the script via a Hot Key doesn't work in Snow Leopard if QAutoSaver is already open
    keystroke return
    delay 3 -- Let you see it
    activate application "QLab"
end tell

Preview selected & move down

Rich Walsh (Last tested with QLab 2.3.4 & Mac OS X 10.6.7)

Preview selected and move down (for stepping through cues without waiting for follow-ons) [Hot Key]:

tell application "System Events"
    activate application "QLab"
    delay 0.25 -- Wait for Double GO Protection to pass
    keystroke "v" -- The default key to preview a cue
    keystroke (ASCII character 31) -- Down arrow
end tell

Prevent GO while a sound cue is playing

Stephen Swift

A powerful little script which, used carefully, can help prevent disaster in situation where multiple overlapping sound cues would cause trouble.

set activeCues to count (every cue of workspace 1 whose running is true and q type is "Audio")
 if activeCues = 0 then
     tell workspace 1 to go
 end if

Label files in use

Sam Kusnetz updated January 17, 2009

This script will let you choose a color label and then label all files in your workspace with that color in the Finder. Useful for tracking down exactly which files are or are not being used in a workspace.

property defaultColor : "Red"
 
set theColors to {"No color", "Orange", "Red", "Yellow", "Blue", "Purple", "Green", "Gray"}
 
set userColor to choose from list theColors with title "Which color?" with prompt "Label files with this color:" default items {defaultColor}
repeat with n from 1 to (count theColors)
    if ((item n of theColors) as string) is equal to (userColor as string) then
        set labelColor to n - 1
    end if
end repeat
 
set mySel to cues of front workspace
repeat with myCue in mySel
    if q type of myCue is "Audio" or q type of myCue is "Video" then
        set theFile to file target of myCue
        tell application "Finder"
            set the label index of item theFile to labelColor
        end tell
    end if
end repeat

Set color for selected cues

permalink

This script allows you to select multiple cues and quickly set the color for all of them.

Notice that there are two colors that are not included in the standard QLab choices. Qlab seems to offer yellow in addition to the familiar orange. And it colors anything that it doesn't recognize as grey - so I made that a choice as well.

This script uses a hack to send plain text OSC to QLab itself. OSC allows you to do things that are either more difficult or - as far as I know, impossible - with AppleScript alone. It works perfectly, even if it is a little less than elegant!

-- Set color for selected cues
-- Tim Rogers <timmrogers@gmail.com>
-- Help and inspiration from https://figure53.hostedwiki.co/pages/QLab%20Scripts%20and%20Macros
-- Updated to use OSC /cue/selected syntax

tell application id "com.figure53.qlab.3" to tell front workspace

    set myColor to choose from list {"none", "blue", "green", "grey", 
"orange", "purple", "red", "yellow"} with title "Color" with prompt "Select 
color for selected cues" default items "none"

    set myOSC to "/cue/selected/colorName " & myColor   
    do shell script "echo " & myOSC & " | nc -u -w 0 127.0.0.1 53535"

end tell

Add Start Cue(s)

Rich Walsh (Last tested with QLab 2.3.4 & Mac OS X 10.6.7)

Add triggers to the end of the Main Cue List for cues you have selected in another cue list, and then switch back [Hot Key]:

tell front workspace
    set originalCueList to q name of current cue list
    if originalCueList is not "Main Cue List" then
        set selectedCues to selected as list
        set current cue list to first cue list whose q name is "Main Cue List"
        repeat with eachCue in selectedCues
            make type "Start"
            set newCue to last item of (selected as list)
            set cue target of newCue to eachCue
            set nameString to "Start"
            if originalCueList is not "" then
                set nameString to nameString & " | " & originalCueList
            end if
            set eachNumber to q number of eachCue
            if eachNumber is not "" then
                set nameString to nameString & " | Q " & eachNumber
            end if
            set eachName to q name of eachCue
            if eachName is not "" then
                set nameString to nameString & " | " & eachName
            end if
            set q name of newCue to nameString
        end repeat
        delay 1 -- Let you see it
        set current cue list to first cue list whose q name is originalCueList
        set playback position of current cue list to last item of selectedCues
        (* This will maintain the selection (more or less) if "Playback position is always the selected cue" is ON *)
    end if
end tell

Set target

Rich Walsh (Last tested with QLab 2.3.4 & Mac OS X 10.6.7)

Set target of selected cue to cue above (for a selected Fade Cue, the script will find the closest preceding Audio Cue (rather than just the cue above); likewise, Animation, Devamp & Target Cues will look for the closest Video/Audio/Goto Cue respectively) [Hot Key]:

-- Declarations
 
set simpleCases to {"Start", "Stop", "Pause", "Reset", "Load", "Goto", "Arm", "Disarm"}
set specialCases to {"Fade", "Animation", "Devamp", "Target"}
set acceptableTargets to {"Audio", "Video", "Audio", "Goto"}
 
-- Main routine
 
tell front workspace
    set originalCue to last item of (selected as list)
    set originalType to q type of originalCue
    if originalType is in simpleCases then
        moveSelectionUp
        set targetCue to last item of (selected as list)
        try
            set cue target of originalCue to targetCue
            set targetName to q name of targetCue
            set q name of originalCue to originalType & ": " & targetName
        end try
        moveSelectionDown
    else if originalType is in specialCases then
        repeat with i from 1 to count specialCases
            if originalType is item i of specialCases then
                set acceptableType to item i of acceptableTargets
                exit repeat
            end if
        end repeat
        set foundType to ""
        set moveCounter to 0
        repeat while foundType is not acceptableType
            moveSelectionUp
            set moveCounter to moveCounter + 1
            set targetCue to last item of (selected as list)
            set foundType to q type of targetCue
            if targetCue is first item of cues of current cue list then -- Protect against infinite loop if no acceptable target found
                exit repeat
            end if
        end repeat
        if foundType is acceptableType then -- Don't change the target if we've gone all the way up the cue list without finding one
            set cue target of originalCue to targetCue
            set targetName to q name of targetCue
            set q name of originalCue to originalType & ": " & targetName
        end if
        repeat moveCounter times
            moveSelectionDown
        end repeat
    end if
end tell

Group selected cue(s)

Rich Walsh (Last tested with QLab 2.3.4 & Mac OS X 10.6.7)

Put selected cue(s) in a new Group Cue [Hot Key]:

'''WARNING!!!!''' This script will move selected cues out of any Group Cues they are in and into the new Group Cue. If you want a Group Cue to remain intact when it is moved, DO NOT include its children in the selection! Also, remember that new cues are inserted into the cue list after the last cue that was selected (which is not always the same as the cue at the bottom of the selection); this will dictate where the new Group Cue is made, and hence what is moved into it - as the script can't move an existing Group Cue inside the new Group Cue if the new Group Cue is made within the existing Group Cue... The new Group Cue's settings will follow the Workspace Preferences, by the way.

tell front workspace
    set selectedCues to selected as list
    if (count selectedCues) is not 0 then
 
        make type "Group"
        set groupCue to last item of (selected as list)
        set groupCueIsIn to parent of groupCue
 
        repeat with eachCue in selectedCues
            if contents of eachCue is not groupCueIsIn then -- Skip a Group Cue that contains the new Group Cue
                set eachCueID to uniqueID of eachCue
                move cue id eachCueID of parent of eachCue to end of groupCue
            end if
        end repeat
 
    end if
end tell

Import files

Rich Walsh (Last tested with QLab 2.3.4 & Mac OS X 10.6.7)

Choose multiple audio, video and MIDI files and add them to the workspace as new cues; the original files will be copied to the appropriate subfolder next to the workspace, unless they already exist there (in which case the existing files will be used); the script can be adjusted to enforce copying only for non-local files, eg: those on network servers [Hot Key]:

set userCopyOnImport to true -- Set this to false if you do not want the files to be copied to the workspace folder
set userForceCopyFromNetwork to true -- Set this to false if you do not want files that aren't on local drives to be copied automatically
set userReassuranceThreshold to 5 -- When the number of files imported is greater than this variable, a "Done" dialog will let you know that the process is complete

-- ###BUG TBC### Should audioFileTypes include "public.ulaw-audio"?
-- ###BUG TBC### Is videoFileTypes a sufficiently exhaustive list? Are any of the file types not supported by QLab?

-- Declarations

global dialogTitle, sharedPath
set dialogTitle to "Import files"

set audioFileTypes to {"com.apple.coreaudio-format", "com.microsoft.waveform-audio", ¬
    "public.aifc-audio", "public.aiff-audio", "public.audio", "public.mp3", "public.mpeg-4-audio"}
(* This list deliberately excludes "com.apple.protected-mpeg-4-audio" to protect against old DRM-restricted iTunes files *)
set videoFileTypes to {"com.apple.icns", "com.apple.macpaint-image", "com.apple.pict", "com.apple.quicktime-image", "com.apple.quicktime-movie", ¬
    "public.3gpp", "public.3gpp2", "public.avi", "public.camera-raw-image", "public.image", "public.jpeg", "public.jpeg-2000", "public.movie", "public.mpeg", ¬
    "public.mpeg-4", "public.png", "public.tiff", "public.video", "public.xbitmap-image"}
set midiFileTypes to {"public.midi-audio"}

(* cf: http://developer.apple.com/library/mac/#documentation/Miscellaneous/Reference/UTIRef/Articles/System-DeclaredUniformTypeIdentifiers.html *)

set theFileTypes to {audioFileTypes, videoFileTypes, midiFileTypes}
set foldersExist to {null, null, null}
set theSubfolders to {"audio", "video", "midi file"}
set theCueTypes to {"Audio", "Video", "MIDI File"}

-- Main routine

tell front workspace

    -- Establish the path to the current workspace

    set workspacePath to path
    if workspacePath is missing value then
        display dialog "The current workspace has not yet been saved anywhere." with title dialogTitle ¬
            with icon 0 buttons {"OK"} default button "OK" giving up after 5
        return
    end if

    -- Get the path that should prefix all media file paths

    tell application "System Events"
        set sharedPath to path of container of file workspacePath
    end tell

    -- Choose the files to import

    set newTargets to choose file of type {"public.image", "public.audiovisual-content"} ¬
        with prompt "Please select one or more audio, video or MIDI files:" with multiple selections allowed without invisibles

    -- Import them

    repeat with eachFile in newTargets

        tell application "System Events"
            set eachType to type identifier of eachFile
            set eachName to name of eachFile
            if userForceCopyFromNetwork is true then -- Only check file's locality if it will be relevant
                set fileIsLocal to local volume of disk (volume of eachFile)
            else
                set fileIsLocal to true
            end if
        end tell

        set eachTarget to eachFile -- This variable will be updated if the file is copied

        -- Work through the three types of cues that will be processed

        repeat with i from 1 to 3

            if eachType is in contents of item i of theFileTypes then

                if (userCopyOnImport is true) or (userForceCopyFromNetwork is true and fileIsLocal is false) then

                    -- If copying is specified by the user definitions then…

                    -- Check for appropriate subfolder next to workspace and make it if it doesn't exist

                    if item i of foldersExist is null then
                        set item i of foldersExist to my checkForFolder(item i of theSubfolders)
                        if item i of foldersExist is false then
                            my makeFolder(item i of theSubfolders)
                        end if
                    end if

                    -- If the file is not already in place, copy it to the appropriate subfolder

                    if my checkForFile(item i of theSubfolders, eachName) is false then
                        my copyFile(item i of theSubfolders, eachFile)
                    end if

                    set eachTarget to sharedPath & item i of theSubfolders & ":" & eachName

                end if

                -- Make an appropriate cue

                make type item i of theCueTypes
                set newCue to last item of (selected as list)
                set file target of newCue to eachTarget
                set q name of newCue to eachName

                exit repeat

            end if

        end repeat

    end repeat

end tell

if (count newTargets) > userReassuranceThreshold then
    display dialog "Done." with title dialogTitle with icon 1 buttons {"OK"} default button "OK" giving up after 5
end if

-- Subroutines

on checkForFolder(theSuffix)
    tell application "System Events"
        return exists folder (sharedPath & theSuffix)
    end tell
end checkForFolder

on makeFolder(theFolder)
    tell application "Finder"
        make new folder at sharedPath with properties {name:theFolder}
    end tell
end makeFolder

on checkForFile(theSuffix, theName)
    tell application "System Events"
        return exists file (sharedPath & theSuffix & ":" & theName)
    end tell
end checkForFile

on copyFile(theSuffix, theFile)
    (* NB: by using the Finder the usual file-copy progress window is invoked, which may be more reassuring than the faceless
    'do shell script "cp -p " & quoted form of POSIX path of theFile & " " & quoted form of POSIX path of (sharedPath & theSuffix & ":" & theName)'
    - which may look like a freeze (the -p flag copies every property of a file) *)
    tell application "Finder"
        duplicate theFile to folder (sharedPath & theSuffix)
    end tell
end copyFile

Convert Group Cue

Rich Walsh (Last tested with QLab 2.3.4 & Mac OS X 10.6.7)

Convert Group Cues between "fire first go to next cue" sequences (SFX 5.6 style) and "fire all" with independent Pre Waits; IT IS NOT GUARANTEED TO COVER EVERY POSSIBLE SCENARIO SO USE IT '''AT YOUR OWN RISK'''! In particular, it will not work if the children of a "fire all" Group Cue are not in the order in which their Pre Waits will cause them to fire (ie: with each child's Pre Wait greater than or equal to that of the previous child)... [Hot Key]:

tell front workspace
    set selectedCue to last item of (selected as list)
    if q type of selectedCue is "Group" then
        if mode of selectedCue is fire_first_go_to_next_cue then
            set theCues to cues of selectedCue
            set deltaTime to 0
            set mode of selectedCue to fire_all
            repeat with eachCue in theCues
                set eachPre to pre wait of eachCue
                set deltaTime to deltaTime + eachPre
                set pre wait of eachCue to deltaTime
                if continue mode of eachCue is auto_follow then
                    set eachPost to duration of eachCue
                else
                    set eachPost to post wait of eachCue
                end if
                set deltaTime to deltaTime + eachPost
                set post wait of eachCue to 0
                set continue mode of eachCue to do_not_continue
            end repeat
        else if mode of selectedCue is fire_all then
            set theCues to cues of selectedCue
            set previousPre to 0
            set mode of selectedCue to fire_first_go_to_next_cue
            repeat with eachCue in theCues
                set eachPre to pre wait of eachCue
                set deltaTime to eachPre - previousPre
                set previousPre to eachPre
                set pre wait of eachCue to deltaTime
                if contents of eachCue is not last item of theCues then
                    set continue mode of eachCue to auto_continue
                end if
            end repeat
        end if
    end if
end tell

Delete

Rich Walsh (Last tested with QLab 2.3.4 & Mac OS X 10.6.7)

Delete selected cue(s) including their File Targets (target files will be moved to the Trash):

tell front workspace
    repeat with eachCue in (selected as list)
        try
            set eachTarget to file target of eachCue
            tell application "Finder"
                if POSIX path of eachTarget does not contain ".Trash" then
                    delete eachTarget
                end if
            end tell
        end try
        set eachCueID to uniqueID of eachCue
        delete cue id eachCueID of parent of eachCue
    end repeat
end tell

Arm

Rich Walsh (Last tested with QLab 2.3.4 & Mac OS X 10.6.7)

Create Arm Cue targeting selected cue as previous cue:

tell front workspace
    set originalCue to last item of (selected as list)
    make type "Arm"
    set newCue to last item of (selected as list)
    set cue target of newCue to originalCue
    set q name of newCue to "Arm: " & q name of originalCue
    set originalCueIsIn to parent of originalCue
    if parent of newCue is originalCueIsIn then -- Only reorder the cues if they are in the same group/cue list
        set originalCueID to uniqueID of originalCue
        set newCueID to uniqueID of newCue
        move cue id originalCueID of originalCueIsIn to after cue id newCueID of originalCueIsIn
    end if
end tell

Disarm

Rich Walsh (Last tested with QLab 2.3.4 & Mac OS X 10.6.7)

Create Disarm Cue targeting selected cue as next cue:

tell front workspace
    set originalCue to last item of (selected as list)
    make type "Disarm"
    set newCue to last item of (selected as list)
    set cue target of newCue to originalCue
    set q name of newCue to "Disarm: " & q name of originalCue
end tell

Add a crashable wait cue

Rich Walsh (Last tested with QLab 2.3.4 & Mac OS X 10.6.7)

Adds some ugly cues to make it possible to crash ahead before the next domino has toppled:

set userDuration to 5
tell front workspace
    set originalCue to last item of (selected as list)
    set continue mode of originalCue to auto_continue
    make type "Start"
    set newStartCue to last item of (selected as list)
    set cue target of newStartCue to current cue list
    set pre wait of newStartCue to userDuration
    set q name of newStartCue to " stop..."
    make type "Stop"
    set newStopCue to last item of (selected as list)
    set cue target of newStopCue to newStartCue
    set q name of newStopCue to " ...carry on"
    set continue mode of newStopCue to auto_continue
end tell

Fire Cues on another Qlab machine

Bill Rios (Last tested with QLab 2.3.6 & Mac OS X 10.6.8)

NOTE: This script is obsolete as of QLab 3; QLab 3 supports network control natively using OSC cues

This script allows you to send a start cue signal to another computer on the same network. I used it to tie a video macbook and an audio macbook together across my theatre.

tell application "Qlab" of machine "eppc://ip.adress.0.1"
    tell front workspace
              start cue "1"
    end tell
end tell

Using Qlab to generate midi command change cues

This script allows you to create a series of command change cues (With incremental control change values) developed specifically for use on DiGiCo consoles, but will work on any console that accepts midi control change. When paired with a desk macro that creates a desk snapshot whilst triggering this script. It makes programing much quicker

tell application id "com.figure53.qlab.3" to tell front workspace

    -- VARIABLES —
    -- SET MIDI CHANNEL —
    set SSCh to 16

    -- SET MIDI CC —
    set SSCC to 16

    -- SEARCH FOR HIGHEST CC VALUE, AND SET CC VALUE TO NEXT INTEGER —
    set SSNo to -1
    set midiCues to every cue whose q type is "MIDI"
    set midiCuesRef to a reference to midiCues
    repeat with eachCue in midiCuesRef
        if channel of eachCue is SSCh and byte one of eachCue is SSCC then
            set SSNoTest to byte two of eachCue
            if SSNoTest is greater than SSNo then
                set SSNo to SSNoTest
            end if
        end if
    end repeat
    set SSNo to SSNo + 1


    -- ACTUAL SCRIPT —
    display dialog "Insert Cue Name:" default answer "Cue Name" with title "Cue Name" with icon 1 buttons {"Cancel", "OK"} default button "OK" cancel button "Cancel"

    set changeAmount to text returned of result

    make type "MIDI"
    set newCue to last item of (selected as list)
    set q number of newCue to SSNo
    set q name of newCue to changeAmount
    set channel of newCue to SSCh
    set command of newCue to control_change
    set byte one of newCue to SSCC
    set byte two of newCue to SSNo


end tell


External scripts

These scripts should all be run from the Script menulet. As they are quite long, they've all got their own pages now...

General

Search cues for text

Adjusting

Batch adjust selected

Update all instances

Making

Make cues from a text file

Make a soundcheck sequence

Make a fade group

Stopwatch fade maker

MIDI

Bodging a MIDI player

Go ahead make MIDI

Make it go faster

Reporting

All purpose enquiry

Make a list of audio files

Make a text file from cues

Path checker

QLab reporter with levels


Third-party utilities

These scripts rely on third-party applications:

MIDIPipe

Capture MIDI with MIDIPipe

Set cue levels with MIDIPipe