[QLab] Q Numbers to Notes script

250 views
Skip to first unread message

Gareth Fry

unread,
May 24, 2010, 1:58:23 PM5/24/10
to ql...@lists.figure53.com
Hi all,

I've written the following script that i thought i'd share with the group. It takes the Q number of selected cues, and adds - SQ x - to the start of the Notes file. It'll update any cue numbers that have changed so long as they are in that format too.

If anyone has any mod's, improvements feel free to develop upon! It's a little clunky in places, for example, the detection of an empty notes field, but works. Tested in 10.5 and 10.6 with 2.2.8 and 2.3

cheers
g

Gareth Fry Sound Designer Phone: +44 (0)7973 352669 Web: http://www.garethfry.co.uk


-- Takes the Q number from the column on the main cue list of the selected cues, and adds that to the start of the Notes section. If a Q Number already exists in the format "- SQ x -", it will be replaced, if not it won't

-- by Gareth Fry


tell application "QLab"

tell front workspace

repeat with currentCue in (selected as list)

--try

set currentNotes to notes of currentCue as string

if ((q number of currentCue) as string) is not "" then -- if no q number then skip

if currentNotes is "missing value" then

set currentNotes to ""

else -- skip if no notes

if ((first character of currentNotes) as text) is "-" then -- if existing number,remove SQ number

set AppleScript's text item delimiters to {"-"}

set noteParts to (every text item in currentNotes) as list

set notes of currentCue to (items 3 through -1 of noteParts as string)

set currentNotes to notes of currentCue

-- set AppleScript's text item delimiters to ""

end if

end if

set notes of currentCue to ("- SQ " & q number of currentCue & " -" & (ASCII character 13) & currentNotes) -- add SQ number to notes

end if

--end try

end repeat

end tell

end tell


Rich Walsh

unread,
May 24, 2010, 8:21:49 PM5/24/10
to Discussion and support for QLab users.
On 24 May 2010, at 18:58, Gareth Fry wrote:

> Hi all,
>
> I've written the following script that i thought i'd share with the
> group. It takes the Q number of selected cues, and adds - SQ x - to
> the start of the Notes file. It'll update any cue numbers that have
> changed so long as they are in that format too.
>
> If anyone has any mod's, improvements feel free to develop upon!
> It's a little clunky in places, for example, the detection of an
> empty notes field, but works. Tested in 10.5 and 10.6 with 2.2.8 and
> 2.3
>
This is how I would do it:

tell application "QLab"
tell front workspace
repeat with currentCue in (selected as list)
set currentNumber to q number of currentCue
(* No need to coerce text to a string; setting a variable saves
getting q number twice *)
if currentNumber is not "" then
set currentNotes to notes of currentCue
(* No point getting this value before the if... *)
if currentNotes is missing value then
set currentNotes to ""
else if currentNotes starts with "- SQ" then
(* Might as well make this as specific as possible *)
set currentNotes to paragraphs 2 thru -1 of currentNotes
(* No need to send two additional Apple Events to set & get notes
from the cue *)
(* Text item delimiters version was adding an extra carriage
return each time *)
end if
set notes of currentCue to ("- SQ " & currentNumber & " -" &
return & currentNotes)
(* Can use return (or "\r") for ASCII character 13 (CR) *)
end if
end repeat
end tell
end tell

I hope the comments explain why I've changed some things...

Rich

________________________________________________________
WHEN REPLYING, PLEASE QUOTE ONLY WHAT YOU NEED. Thanks!
Change your preferences or unsubscribe here:
http://lists.figure53.com/listinfo.cgi/qlab-figure53.com

--
Change your preferences or unsubscribe here:
http://groups.google.com/group/qlab

Rich Walsh

unread,
May 25, 2010, 4:04:28 AM5/25/10
to Discussion and support for QLab users.
I'd not tested the case where the existing notes contains more than
two paragraphs, so you need to replace this line:

set currentNotes to paragraphs 2 thru -1 of currentNotes

With:

set currentNotesList to rest of paragraphs of currentNotes
set currentTIDs to AppleScript's text item delimiters
set AppleScript's text item delimiters to return
set currentNotes to currentNotesList as text
set AppleScript's text item delimiters to currentTIDs

Giving you:

tell application "QLab"
tell front workspace
repeat with currentCue in (selected as list)
set currentNumber to q number of currentCue
if currentNumber is not "" then
set currentNotes to notes of currentCue
if currentNotes is missing value then
set currentNotes to ""
else if currentNotes starts with "- SQ" then
set currentNotesList to rest of paragraphs of currentNotes
set currentTIDs to AppleScript's text item delimiters
set AppleScript's text item delimiters to return
set currentNotes to currentNotesList as text
set AppleScript's text item delimiters to currentTIDs
end if
set notes of currentCue to ("- SQ " & currentNumber & " -" &
return & currentNotes)
end if
end repeat
end tell
end tell

AppleScript's text item delimiters are a property of that instance of
AppleScript (eg: Script Editor), so you should always set them back
after changing them in case you then try to run another script without
loading a new instance of AppleScript first (ie: quitting and
reopening Script Editor). I suspect QLab doesn't create a new
AppleScript instance for each Script Cue, but I could be wrong.

There's still a bizarre anomaly: if the existing notes start with a
return this is replaced by "- SQ x -"; for some reason AppleScript
does not behave how you would expect when concatenating return to a
string that already starts with return...
Reply all
Reply to author
Forward
0 new messages