convert-how

52 views
Skip to first unread message

Kalman Tarr

unread,
Mar 29, 2023, 5:33:06 AM3/29/23
to QLab
Morning Guys,

I have a question that I need help.
I placed a 'Record' in a memo cue notes field. It is a text naturally.
I read it and try to put them in 'record' variable. Without success.
The question is, how can I convert them to a usable variable form.
I show the script.

tell application id "com.figure53.QLab.4" to tell front workspace

(*

set theBaseRecord to {audio:character id 127925 , video:character id 128250 , midi:character id 127929}

*)

I show the expected result above


But the real result is, which is text. Wrong!

{"audio:character id 127925 as Unicode text", "video:character id 128250 as Unicode text", "midi:character id 127929 as Unicode text"}



set theRecordtemp to (paragraphs of (get notes of cue "chrUni")) as list

set therecords to {} 

set my text item delimiters to ":"

repeat with i from 1 to count of theRecordtemp

set end of therecords to (first text item of (item (i) of theRecordtemp)) & ":" & (second text item of (item (i) of theRecordtemp)) as WHAT

end repeat

display dialog therecords as text with title (count of therecords) as text

end tell


I suppose the solution more complicated I thought.


(* notes of cue "chrUni"

audio:character id 127925

video:character id 128250

midi:character id 127929

*)


'as What' colored red represents the Question itself.

Hopefully the question is understandable.

Thanks in advance,

Best,

Kalman


Rich Walsh

unread,
Mar 29, 2023, 6:14:42 AM3/29/23
to ql...@googlegroups.com
The simple answer is don’t use records. They are really unwieldy and you can not dynamically change the labels without going through the hoops we’ve already discussed: https://groups.google.com/g/qlab/c/PSHyy6Rc_lo/m/og6Z5NQDAgAJhttps://groups.google.com/g/qlab/c/YykMf_hKt40/m/s36e1AWXAgAJ.

If you’re determined to use records (why? what are you doing with this data that means you need to store it in one variable not three?) then this will work with the notes formatted as you indicated:

tell application id "com.figure53.QLab.4" to tell front workspace

set currentTIDs to AppleScript's text item delimiters

set AppleScript's text item delimiters to {":", linefeed, return}

set theNotes to notes of cue "chrUni"

set theRecord to {audio:text item 2 of theNotes, video:text item 4 of theNotes, midi:text item 6 of theNotes}

display dialog audio of theRecord -- etc…

set AppleScript's text item delimiters to currentTIDs

end tell


Seriously, don’t use records. You don’t need to use records. Key / value pairs in AppleScript are not worth the effort: don’t use records.

You could do this instead:

tell application id "com.figure53.QLab.4" to tell front workspace

set currentTIDs to AppleScript's text item delimiters

set AppleScript's text item delimiters to {":", linefeed, return}

set theNotes to notes of cue "chrUni"

set notRecord to text items of theNotes

set reportList to {}

repeat with i from 1 to count notRecord by 2

set end of reportList to item i of notRecord & ":" & item (i + 1) of notRecord

end repeat

set AppleScript's text item delimiters to return

display dialog reportList as text

set AppleScript's text item delimiters to currentTIDs

end tell


Or this:

tell application id "com.figure53.QLab.4" to tell front workspace

set currentTIDs to AppleScript's text item delimiters

set AppleScript's text item delimiters to {":", linefeed, return}

set theNotes to notes of cue "chrUni"

set notRecord to text items of theNotes

set theKeys to {}

set theValues to {}

repeat with i from 1 to count notRecord by 2

set end of theKeys to item i of notRecord

set end of theValues to item (i + 1) of notRecord

end repeat

set reportList to {}

repeat with i from 1 to count theKeys

set end of reportList to item i of theKeys & ":" & item i of theValues

end repeat

set AppleScript's text item delimiters to return

display dialog reportList as text

set AppleScript's text item delimiters to currentTIDs

end tell


Don’t use records.

Rich

Kalman Tarr

unread,
Mar 29, 2023, 8:15:42 AM3/29/23
to QLab
Hi Rich,

I've created a workspace that collects the cues depending what 'q type' they are.
And I would like to place the result in a text file showing in which attached image shown. That's all.
I thought I can get the character id easily I store them in record.
It is eassy to refer to. (Audio, video, etc)

display dialog myRecord's wait (e.g.)


I browsed the net for solutions. I found of varying complexity.
In my opinion the simplest the next one. I really like it.

set myData to (get notes of cue "chrUni")

set myRecord to run script "{" & myData & "}"

display dialog  myRecord's theGroup


I have to say, I don't understand how it acually works. But it doing its job.


The checkmark represent if it is armed and 'x' if not.

These are all unicode characters. Don't ask why.


The workspace has several unicode char not just three.

This is the real list. Maybe it will even expand


{audio:character id 128266, video:character id 128250, photo:character id 128247, midi:character id 127925, theTrue:character id 10004,

theFalse:character id 10006, memo:character id 9729, wait:character id 9203, theStart:character id 9654, thepause:character id 9208,

theStop:character id 9673, theGroup:character id 128194}


scrshot.png



Thanks your great solution Rich.


Sincerely,


Kalman


Rich Walsh

unread,
Mar 29, 2023, 8:55:11 AM3/29/23
to ql...@googlegroups.com
Why coerce the record backwards and forwards to text in a cue’s notes? If you aren’t trying to get the key labels dynamically then you already know what they are and can just work with the record natively:

set myRecord to {audio:character id 128266, video:character id 128250, photo:character id 128247, midi:character id 127925, theTrue:character id 10004, theFalse:character id 10006, memo:character id 9729, wait:character id 9203, theStart:character id 9654, thepause:character id 9208, theStop:character id 9673, theGroup:character id 128194}

display dialog myRecord's theGroup


You only need to work with script objects if you don’t know the labels (eg: theGroup), or need to change them.

This line…

set myRecord to run script "{" & myData & "}"


…does the equivalent of the first line above but by embedding it in a script object you make the key labels into variables you can change dynamically, not parts of the code itself. In the first version, the label “myGroup” is fixed by the code; in the script object version you can change that label into whatever you want.

The script object becomes dynamic code that is compiled at run time, not when the script is originally compiled (and the variables are unknown).

Rich

On 29 Mar 2023, at 13:15, Kalman Tarr <tarr....@gmail.com> wrote:

Hi Rich,

I've created a workspace that collects the cues depending what 'q type' they are.
And I would like to place the result in a text file showing in which attached image shown. That's all.
I thought I can get the character id easily I store them in record.
It is eassy to refer to. (Audio, video, etc)
display dialog myRecord's wait (e.g.)

I browsed the net for solutions. I found of varying complexity.
In my opinion the simplest the next one. I really like it.

set myData to (get notes of cue "chrUni")
set myRecord to run script "{" & myData & "}"
display dialog  myRecord's theGroup

I have to say, I don't understand how it acually works. But it doing its job.

The checkmark represent if it is armed and 'x' if not.
These are all unicode characters. Don't ask why.

The workspace has several unicode char not just three.
This is the real list. Maybe it will even expand

{audio:character id 128266, video:character id 128250, photo:character id 128247, midi:character id 127925, theTrue:character id 10004,
theFalse:character id 10006, memo:character id 9729, wait:character id 9203, theStart:character id 9654, thepause:character id 9208,
theStop:character id 9673, theGroup:character id 128194}

Kalman Tarr

unread,
Mar 29, 2023, 11:52:48 AM3/29/23
to QLab
Rich, my primary solution it matched to your offer.
But I only had one goal, I didn't want to see the record variable in the script.
From that point it was a mind game. How to do it if I hide the "record" values in a notes field as text and read them back from the field and coerce to be a record variable. 
I mentioned several times, I am not a pro in programmig.  Sometimes I need help to get through the problem. Maybe manytimes.
As a pensioner, I would like to keep my mind clear and alive, that's why I invent tasks for myself. This was one of them.
Don't be mad at me for that, please. I really enjoy script language.
It is highly great thing to learn from a skilled person like You, Mic, Chris and Sam.
Thanks for your past and future help.

Sincerely,

Kalman

Reply all
Reply to author
Forward
0 new messages