Leaving aside the moral issues, I think it unlikely that Chat GPT knew how to set a variable to the last item of (cues whose running is true and q type is "script"). It only knew that because friendlygiraffe had presumably fed the whole script into chatGPT and asked it to improve it and it would have forgotten it 5 minutes later.
If you ask chatGPT "write an AppleScript to set a variable named theCue, to the currently running script cue, in QLab." It will reply
tell application "QLab"
set theCue to id of current cue of front workspace
end tell
If you prompt it further "that finds the selected cue I want the script cue that is running"
it will offer something like
tell application "QLab"
set theCue to id of selected cue of front workspace whose cue type is "Script" and (state = "running" or state = "paused")
end tell
You can tell it how to correct this and eventually it will get a correct answer,, but currently the answers it gives tomorrow will be no better as it doesn't learn from new input.
If you asked it to write the whole script from scratch with "write a precisely coded and brilliantly impressive Applescript for QLab to change the number displayed by a text cue numbered "T1" to a target number in the notes field of the script cue you create , in a duration set by the post wait of the script cue you create"
A:
tell application "QLab"
-- Retrieve the target number from the notes field of the script cue
set targetNumber to notes of cue "Script Cue Name" of front workspace
-- Find the text cue with number "T1" and set its display value to the target number
set textCue to cue "T1" of front workspace
set postWait to post wait of cue "Script Cue Name" of front workspace
tell textCue
set display value to targetNumber
if postWait > 0 then
start fade out from 1 to 0 over postWait
end if
end tell
end tell
I've given it another 5 helpful clues and it still produces garbage that won't even compile let alone run, and is no where near to solving the problem.
My main objection is that the script it produced for fg after being fed the entire original script is not very good It sort of works but doesn't really. and just creates a different set of timing problems.
In the few minutes I spent improving my scrip I came up with:
--change the number displayed by a text cue numbered "T1" to a target number in the notes field of the cue in a duration approximately set by the post wait of the cue.
set theFPS to 10 -- number of repeats per second your computer can comfortably manage e.g 10
set theCalcTime to 0.018 --estimate of the time taken to calculate a single repeat loop
tell application id "com.figure53.QLab.5" to tell front workspace
set theCue to last item of (cues whose running is true and q type is "script")
set theTargetNumber to notes of theCue as integer
set theCurrentNumber to the text of cue "T1" as integer
set theDuration to post wait of theCue
if theTargetNumber > theCurrentNumber then
set theDifference to (theTargetNumber - theCurrentNumber)
set theDelay to theDuration / theDifference
set theFramesTotal to theFPS * theDuration
set theStep to (theDifference / theFramesTotal)
repeat until the text of cue "T1" as integer = theTargetNumber
set theNewNumber to ((the text of cue "T1" as integer) + theStep) as integer
if theNewNumber > theTargetNumber then set theNewNumber to theTargetNumber
set the text of cue "T1" to theNewNumber as text
delay (1 / theFPS) - theCalcTime
end repeat
else
set theDifference to (theCurrentNumber - theTargetNumber)
set theDelay to theDuration / theDifference
set theFramesTotal to theFPS * theDuration
set theStep to (theDifference / theFramesTotal)
repeat until the text of cue "T1" as integer = theTargetNumber
set theNewNumber to ((the text of cue "T1" as integer) - theStep) as integer
if theNewNumber < theTargetNumber then set theNewNumber to theTargetNumber
set the text of cue "T1" to theNewNumber as text
delay (1 / theFPS) - theCalcTime
end repeat
end if
end tell
As well as setting the delay, this also sets a step size, based on the number of loop iterations your computer can comfortably handle within the required duration. and also adjusts the delay between loops to allow for the approximate time taken to calculate in each repeat.
I think that's probably the best you can do. If you want absolute accuracy of duration, or you want to use a fade curve to vary the counting speed then my first answers using OSC 1D fades will give a much better result
Mic