I have recently run into a few mysterious errors with Script Debugger’s debugger, I had another couple of problems yesterday and had a flash of insight with this one.
This code works (the entire script and all the libraries work) with Debugger mode off. With Debugger on I get an error here which is obvious bollocks
if (ScriptData's appDataStatus) and (1 ≤ (theAppData's imagesPerSecond)) then -- if the existing data is valid
set cumImageCount to countProcessedImages + (theAppData's imageCount)
set cumBatchCount to countEXIFtoolBatches + (theAppData's batchCount)
set cumElapsedImageTime to ((theAppData's imageCount) / (theAppData's imagesPerSecond)) + (countProcessedImages / imageEXIFtoolRate)
set cumElapsedBatchTime to ((theAppData's batchCount) / (theAppData's batchesPerSecond)) + (countEXIFtoolBatches / batchEXIFtoolRate)
set cumImageRate to (cumImageCount / cumElapsedImageTime)
set cumBatchRate to (cumBatchCount / cumElapsedBatchTime)
log {theAppData's imagesPerSecond, cumImageRate}
set theAppData's imagesPerSecond to cumImageRate
--copy cumImageRate to (imagesPerSecond of theAppData)
set theAppData's imageCount to cumImageCount
The log statement works perfectly and gives the following:
(100, 121.025249637964)
However, with debugger off the following line generates this error that stops execution
The variable imagesPerSecond is not defined.
The offending object is “‘utxt’(“imagesPerSecond”)”
This is obvious bollocks because the “imagesPerSecond” used in this line is a property name, not a variable, and it is defined and accessible, as evidenced by the previous line.
If I try the alternative copy command, I get the same problem.
If I turn debugger off, the script execution passes here, it executes the log statement and executes to the end without error.
After retiring in some some frustration, I started wondering if Script Debugger was mixing up labels.
I have a Global variable with one property named “imagesPerSecond”:
{imagesPerSecond:121.025249637964, imageCount:0, batchesPerSecond:16.0, batchCount:0}
There is also local variable “imagesPerSecond” which is is declared in a local statement above but undefined and unused at this stage of execution.(near end of second line)
local imageEXIFtoolRate, batchEXIFtoolRate, imageEXIFtoolRateDisp, batchEXIFtoolRateDisp
local elapsedOverheadTime, overheadTimeDisp, elapsedExecutionTime, roundedExecutionTime, imagesPerSecond, imagesPerSecondDisp
local cumImageCount, cumBatchCount, cumElapsedImageTime, cumElapsedBatchTime, cumImageRate, cumBatchRate
The local variable refers to a slightly different quantity; I hadn’t had a chance to name them clearly yet.
I renamed the variables and properties more clearly and separately - the name of the property in the Global Variable and the name of the local variable are now different, and the problem has disappeared
Property–> EXIFtoolImageRate Local Variable → imagAvgRate.
Thee first snippet above is now as follows
local imageEXIFtoolRate, batchEXIFtoolRate, imageEXIFtoolRateDisp, batchEXIFtoolRateDisp
local elapsedOverheadTime, overheadTimeDisp, elapsedExecutionTime, roundedExecutionTime, imagAvgRate, imagesPerSecondDisp
local cumImageCount, cumBatchCount, cumElapsedImageTime, cumElapsedBatchTime, cumImageRate, cumBatchRate
(next code irrelevant but included for completeness)
## calculate and update the application's performance data
if validExifTimeAnalysis then -- -- if the new data is valid
set imageEXIFtoolRate to (1 / EXIFtimePerImage)
set imageEXIFtoolRateDisp to U's roundDecimals((imageEXIFtoolRate), 0)
set batchEXIFtoolRate to (1 / EXIFtimePerBatch)
set batchEXIFtoolRateDisp to U's roundDecimals((batchEXIFtoolRate), 1)
set EXIFtoolRateMessage to "EXIFtool Batch requests per second " & batchEXIFtoolRateDisp & "; EXIFtool Images per second: " & imageEXIFtoolRateDisp
(below is where the problem used to occur
if (ScriptData's appDataStatus) and (1 ≤ (theAppData's EXIFtoolImageRate)) then -- if the existing data is valid
set cumImageCount to countProcessedImages + (theAppData's imageCount)
set cumBatchCount to countEXIFtoolBatches + (theAppData's batchCount)
set cumElapsedImageTime to ((theAppData's imageCount) / (theAppData's EXIFtoolImageRate)) + (countProcessedImages / imageEXIFtoolRate)
set cumElapsedBatchTime to ((theAppData's batchCount) / (theAppData's EXIFtoolBatchRate)) + (countEXIFtoolBatches / batchEXIFtoolRate)
set cumImageRate to (cumImageCount / cumElapsedImageTime)
set cumBatchRate to (cumBatchCount / cumElapsedBatchTime)
set theAppData's EXIFtoolImageRate to cumImageRate
--copy cumImageRate to (EXIFtoolImageRate of theAppData)
set theAppData's imageCount to cumImageCount
I have stopped ScriptDebugger and restarted it several times, and also copied the Applescript code to a new file without changing the problem behavior
I think this kind of problem might also be a potential data leak. I had an occurrence a few weeks where I copied my debugged and running script (related to this script) from ScriptDebugger to Script Editor, and pn the first run Script Editor said I had an uninitialized variable. I tracked it down, and it was in fact not initialized, but Script Debugger was running it without showing any error. I added a line to initialize the variable, but did not document the situation. Could be this confusion but in reverse.
MacOS 13.62, Script Debugger 8.06, Mac Studio M1 64GB