Editing formatting of notes field of a cue

113 views
Skip to first unread message

George Dennis

unread,
Jan 21, 2023, 8:40:12 AM1/21/23
to ql...@googlegroups.com
Hello,

Has anyone ever had any success editing the formatting of the notes field of a cue using a script? Specifically, I would like to edit the font, size and colour of several hundred notes fields.

Have been scratching my head for a bit now and can't seem to get anything to work.

Any suggestions would be greatly appreciated!

--

George Dennis

Kalman Tarr

unread,
Jan 22, 2023, 6:01:48 AM1/22/23
to QLab
Hi George,

I have asked the question like this earlier here in the group. The answer was, NO. I think it was Mic, who answered. Not possible because notes fields using the same font properties from beginning till end. In it, to write program line for the 'format' key, it is not possible. Or you can try but the system never excecutes it. So No.

Best,
Kalman

micpool

unread,
Jan 22, 2023, 7:26:28 AM1/22/23
to QLab
Yes I looked at this last April and made some progress but the unpredictable behaviour of the o key thwarted my efforts. I had another look after George’s post, and have 90 percent of a fairly ugly solution. If  can solve a couple of things I think I may have something that would get the job done, although it will be messy.

Mic

George Dennis

unread,
Jan 22, 2023, 8:06:46 AM1/22/23
to ql...@googlegroups.com
Ah, apologies, I'd tried to search for previous discussion on this but didn't see any so assumed it was a new topic.

Thanks for the replies both.

I've started to delve into UI scripting and using the copy/paste format command to see if I can get anywhere that way. Would certainly be an ugly solution as well, but might get the job done. Will see how far I get.

Thanks!

George


--
Contact support anytime: sup...@figure53.com
Follow QLab on Twitter: https://twitter.com/QLabApp
User Group Code of Conduct: https://qlab.app/code-of-conduct/
---
You received this message because you are subscribed to the Google Groups "QLab" group.
To unsubscribe from this group and stop receiving emails from it, send an email to qlab+uns...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/qlab/33a867c4-f075-4f16-b142-0f110020ea18n%40googlegroups.com.

Rich Walsh

unread,
Jan 22, 2023, 8:39:56 AM1/22/23
to ql...@googlegroups.com
I can’t work out how Mic’s script is doing what it does from the screen capture, so I don’t know what the issue is with "I can't find a way of exiting a notes field that has been entered using the key map shortcut "o" using the keyboard”, but in case it’s useful this will get you out of that field if the Inspector is open:

tell application "System Events" to tell (first application process whose bundle identifier is "com.figure53.QLab.5") to set focused of first UI element of group 1 of splitter group 1 of window 1 whose accessibility description is "cue number" to true


You can also just toggle selection to another cue and back…

Rich

micpool

unread,
Jan 22, 2023, 9:42:06 AM1/22/23
to QLab
Hi Rich

The main problem I having is this
If I edit in the notes field above the toolbar ESC terminates text entry into notes
If I edit in the inspector notes field it doesn't

Mic

Rich Walsh

unread,
Jan 22, 2023, 10:50:57 AM1/22/23
to ql...@googlegroups.com
Try this?

tell application "System Events" to tell (first application process whose bundle identifier is "com.figure53.QLab.5") to set focused of outline 1 of scroll area 1 of splitter group 1 of splitter group 1 of splitter group 1 of window 1 to true


I think this gets you out of any form of editing…?

Rich

micpool

unread,
Jan 22, 2023, 11:12:31 AM1/22/23
to QLab
That's the Badger!!

Standby for solution

Mic

micpool

unread,
Jan 22, 2023, 11:35:46 AM1/22/23
to QLab
This is a very rough proof of concept.
This uses TextEdit.app to format the text. (It would be neater if this was done entirely on the clipboard)
Test thoroughly and only run on copies of workspaces
Lots of things will reset the formatting!!

-- Format the notes of selected cues
-- set format here
set thecolor to "green"
set theSize to 75
set theFont to "Gill Sans Bold Italic"

try
    tell application "TextEdit"
        quit
    end tell
end try
delay 1

tell application "TextEdit"
    activate   
end tell

tell application id "com.figure53.QLab.5" to tell front workspace
    activate
    set theCues to (selected as list)
    repeat with eachcue in theCues
        set theText to the notes of eachcue
       
       
        tell application "TextEdit"
            activate
            delay 1
            tell document 1
                set the text 1 to the theText
                 set the size of the text 1 to theSize
                set the font of the text 1 to theFont
                set the color of the text 1 to thecolor
            
                tell application "System Events"
                    keystroke "a" using command down
                    delay 0.1
                    keystroke "c" using command down
                    delay 1
                end tell
               
            end tell
        end tell
       
        tell application id "com.figure53.QLab.5" to tell front workspace to activate

       
        tell application "System Events" to tell (first application process whose bundle identifier is "com.figure53.QLab.5") to set focused of outline 1 of scroll area 1 of splitter group 1 of splitter group 1 of splitter group 1 of window 1 to true
       
       
        set the selected to eachcue
        delay 1
        tell application "System Events"
            keystroke "o"
            keystroke "a" using command down
            keystroke "v" using command down
         end tell

       
        tell application "System Events" to tell (first application process whose bundle identifier is "com.figure53.QLab.5") to set focused of outline 1 of scroll area 1 of splitter group 1 of splitter group 1 of splitter group 1 of window 1 to true
    end repeat
end tell

tell application "TextEdit"
    quit without saving
end tell

Screen recording attached

Mic

Reformat notes2.mov

Rich Walsh

unread,
Jan 22, 2023, 3:37:34 PM1/22/23
to ql...@googlegroups.com
Is this any more robust / elegant (you need a dummy Text Cue for this)?

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

set notesFormatRecord to {fontSize:48.0, rgbaColor:{red:1.0, alpha:1.0, blue:0, green:0}, fontName:"Comic Sans MS"} -- Desired formatting for Notes

set dummyCue to cue "text" -- Uses a dummy Text Cue numbered “text”; you could test for one, make it if not and then delete…

activate

set selectedCues to (selected as list)

if (count selectedCues) is 0 then return

-- Prepare Inspector

set inspectorWasOpen to inspector visibility

if not inspectorWasOpen then set inspector visibility to true

set selected to dummyCue

tell application "System Events" to tell (first application process whose bundle identifier is "com.figure53.QLab.5") to click (first button of group 1 of splitter group 1 of window 1 whose description contains "Text")

-- Process cues

repeat with eachCue in selectedCues

set selected to dummyCue

set text of dummyCue to notes of eachCue

set text format of dummyCue to notesFormatRecord

tell application "System Events" to tell (first application process whose bundle identifier is "com.figure53.QLab.5")

set focused of text area 1 of scroll area 1 of group 1 of splitter group 1 of window 1 to true

click menu item "Select All" of menu 1 of menu bar item "Edit" of menu bar 1

click menu item "Copy" of menu 1 of menu bar item "Edit" of menu bar 1

end tell

set selected to eachCue

tell application "System Events" to tell (first application process whose bundle identifier is "com.figure53.QLab.5")

set focused of text area 1 of scroll area 1 of group 1 of splitter group 1 of splitter group 1 of splitter group 1 of window 1 to true

click menu item "Select All" of menu 1 of menu bar item "Edit" of menu bar 1

click menu item "Paste" of menu 1 of menu bar item "Edit" of menu bar 1

end tell

end repeat

set inspector visibility to inspectorWasOpen

end tell


By using a text format record from a Text Cue this should open up a vast array of formatting that can be applied, including easily dealing with ranges of characters in different formats…

I’ve only checked it works (even with the dummy cue in a different cue list); I haven’t tried to break it.

Rich

micpool

unread,
Jan 22, 2023, 4:10:42 PM1/22/23
to QLab
On Sunday, January 22, 2023 at 8:37:34 PM UTC Rich Walsh wrote:
Is this any more robust / elegant (you need a dummy Text Cue for this)?

Yes, yours  is a much more elegant and self contained solution,  (but does require a video licence.)

Mic

Rich Walsh

unread,
Jan 22, 2023, 5:48:58 PM1/22/23
to ql...@googlegroups.com
How about this then?

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

set htmlPrefix to "<head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"/></head><body style=\"color:red;font-size:48px;font-family:'Comic Sans MS'\">" -- Use style tags to set desired formatting for Notes

set htmlSufffix to "</body>"

activate

repeat with eachCue in (selected as list)

do shell script "echo " & quoted form of (htmlPrefix & notes of eachCue & htmlSufffix) & " | textutil -convert rtf -stdin -stdout | pbcopy -Prefer rtf"

set selected to eachCue

tell application "System Events" to tell (first application process whose bundle identifier is "com.figure53.QLab.5")

set focused of text area 1 of scroll area 1 of group 1 of splitter group 1 of splitter group 1 of splitter group 1 of window 1 to true

click menu item "Select All" of menu 1 of menu bar item "Edit" of menu bar 1

click menu item "Paste" of menu 1 of menu bar item "Edit" of menu bar 1

end tell

end repeat

end tell


tell application "System Events" to tell (first application process whose bundle identifier is "com.figure53.QLab.5") to set focused of outline 1 of scroll area 1 of splitter group 1 of splitter group 1 of splitter group 1 of window 1 to true


I can just about spell html, but that’s all I know about it – there might be shorter or better versions of the htmlPrefix to make this work…

With a lucky Google search I found two useful tools: textutil & pbcopy. It might be possible to format the text via rtf “tags” (?) instead?

Rich

Rich Walsh

unread,
Jan 23, 2023, 6:20:19 AM1/23/23
to ql...@googlegroups.com
Did a bit more testing and fixed some things that didn’t work (eg: paragraphs):

-- Only works properly when run as a separate process!

-- ###FIXME### This is not guaranteed to handle all possible characters or formatting, but has been tested with <>&"'£€¢¥©®


set userStyle to "color:pink;font-size:42px;font-weight:bold;font-family:'Brush Script MT'" -- Use style object for desired formatting

(* Also see https://www.w3schools.com/jsref/dom_obj_style.asp – this approach could even be scaled up to include span styles *)


-- Declarations


set htmlPrefix to "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"></head><body style=\""

set htmlMidfix to "\">"

set htmlSufffix to "</body>"


-- Use UI scripting to paste (yuck!)


try

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

-- activate -- ###TESTING### Need this line if testing from Script Editor!

-- my leaveField() -- ###TESTING### This line is useful if testing from Script Editor: make sure any current edits are committed

repeat with eachCue in (selected as list)

set originalNotes to notes of eachCue

set cleanNotes to my searchReplaceText(originalNotes, linefeed, "<br>") -- Deal with linefeeds…

set htmlString to htmlPrefix & userStyle & htmlMidfix & cleanNotes & htmlSufffix

do shell script "echo " & quoted form of htmlString & " | textutil -convert rtf -stdin -stdout | pbcopy -Prefer rtf"

set selected to eachCue

tell application "System Events" to tell (first application process whose bundle identifier is "com.figure53.QLab.5")

set focused of text area 1 of scroll area 1 of group 1 of splitter group 1 of splitter group 1 of splitter group 1 of window 1 to true

click menu item "Select All" of menu 1 of menu bar item "Edit" of menu bar 1

click menu item "Paste" of menu 1 of menu bar item "Edit" of menu bar 1

end tell

end repeat

end tell

leaveField()

on error

my displayAlert("UI scripting failed!", "You need to adjust your privacy settings to allow QLab to control your computer…", "critical", {"Cancel", "OK"}, 2, 1)

(* ###FIXME### Broken in Ventura 13.1

tell application "System Settings"

activate

reveal anchor "Privacy_Assistive" of pane id "com.apple.preference.security"

end tell

*)

return

end try


-- Subroutines


(* === ERROR HANDLING === *)


on displayAlert(theWarning, theMessage, theIcon, theButtons, defaultButton, cancelButton) -- [Shared subroutine]

tell application id "com.figure53.QLab.5"

if cancelButton is "" then

if theIcon is "critical" then -- Triangle with app icon

display alert theWarning message theMessage as critical buttons theButtons ¬

default button item defaultButton of theButtons

else if theIcon is "informational" then -- App icon

display alert theWarning message theMessage as informational buttons theButtons ¬

default button item defaultButton of theButtons

else if theIcon is "warning" then -- App icon

display alert theWarning message theMessage as warning buttons theButtons ¬

default button item defaultButton of theButtons

end if

else

if theIcon is "critical" then

display alert theWarning message theMessage as critical buttons theButtons ¬

default button item defaultButton of theButtons cancel button item cancelButton of theButtons

else if theIcon is "informational" then

display alert theWarning message theMessage as informational buttons theButtons ¬

default button item defaultButton of theButtons cancel button item cancelButton of theButtons

else if theIcon is "warning" then

display alert theWarning message theMessage as warning buttons theButtons ¬

default button item defaultButton of theButtons cancel button item cancelButton of theButtons

end if

end if

end tell

end displayAlert


(* === TEXT WRANGLING === *)


on searchReplaceText(theText, searchFor, replaceWith) -- [Shared subroutine]

set currentTIDs to AppleScript's text item delimiters

set AppleScript's text item delimiters to searchFor

set searchedText to text items of theText

set AppleScript's text item delimiters to replaceWith

set replacedText to searchedText as text

set AppleScript's text item delimiters to currentTIDs

return replacedText

end searchReplaceText


(* === QLAB SPECIFIC === *)


on leaveField()

tell application "System Events" to tell (first application process whose bundle identifier is "com.figure53.QLab.5") to set focused of outline 1 of scroll area 1 of splitter group 1 of splitter group 1 of splitter group 1 of window 1 to true

end leaveField


Rich

micpool

unread,
Jan 23, 2023, 8:46:58 AM1/23/23
to QLab
I think any of the solutions we have discussed, using a dummy text cue , automating a round trip to a scriptable text editor, or an html based shell script  solution, should  satisfy George's need  to reformat  his several hundred existing cues.

Beyond that, I think there is a diminishing return on  anything more  involved ,  due to the fact that subsequently  changing the text content of a cue's notes  using OSC or a script,  will revert the text formatting to the default.

Mic

George Dennis

unread,
Jan 23, 2023, 9:23:22 AM1/23/23
to ql...@googlegroups.com
Wow, thank you both for the solutions! What a gift this group is.

I'll give them a whirl now (on a backup of my show file) but think you may have saved me from a pretty tedious couple of hours.

George

--
Contact support anytime: sup...@figure53.com
Follow QLab on Twitter: https://twitter.com/QLabApp
User Group Code of Conduct: https://qlab.app/code-of-conduct/
---
You received this message because you are subscribed to the Google Groups "QLab" group.
To unsubscribe from this group and stop receiving emails from it, send an email to qlab+uns...@googlegroups.com.


--
Reply all
Reply to author
Forward
0 new messages