I am writing an Apple Script to help me process videos of telescopic meteors. These are meteors that are too faint and small to see with your eyes, but can be seen in videos taken with the right equipment. I have collected many hours of video showing several hundred of these meteors. Processing the video requires quite a few steps:
- Break the video into individual frames. Easy peasy.
- Desaturate the frames.
- Flip each frame horizontally (long story)
- Identify the stars in each frame.
- Search the frames for meteors (Huge job)
- Identify meteors and analyze their paths and speeds
Now, Step #1 is handled by “Video To Photo Extractor”, a program on the App Store. But steps #2 and #3 have to be done with an Apple Script that uses Pixelmator Pro. I had one of these working a few months ago, but for messy reasons I have lost it. So I’m re-writing it, and this time I can’t get it working. (Steps 4 through 6 require a really hairy Java program that I’m still working on.)
At the urging of a friend, I finally agreed to hand the problem to Claude. It has not gone well. Apparently Apple has been changing the keywords for the Script language, and Claude is using a mix of old versions and new versions. It has taken me several dozen iterations through Claude to get something that almost works. I have also used the code writing in Gemini; it’s no better. I suppose that part of the problem may arise from the paucity of scripts written in the Apple Script language, compared to, say, C++ or Java.
So here is the result of my labors. I warn you, I’ve been writing code for more than 50 years, which means that I’m going senile and making more and more stupid mistakes.
on run
set sourceFolder to (choose folder with prompt "Select the folder containing color .png files:")
set destFolder to (choose folder with prompt "Select the folder to save grayscale, flipped .png files:")
convertFolderToGrayscale(sourceFolder, destFolder)
end run
on convertFolderToGrayscale(sourceFolder, destFolder)
set sourcePOSIX to POSIX path of sourceFolder
set destPOSIX to POSIX path of destFolder
tell application "Finder"
set pngFiles to every file of folder sourceFolder whose name extension is "png"
end tell
if (count of pngFiles) is 0 then
display dialog "No .png files were found in the selected source folder." buttons {"OK"} default button 1
return
end if
tell application "Pixelmator Pro"
activate
repeat with aFile in pngFiles
tell application "Finder" to set fileName to name of aFile
set sourceFilePath to sourcePOSIX & fileName
set destFilePath to destPOSIX & fileName
try
set theDocument to open (aFile as alias)
delay 0.5
tell theDocument
-- Turn on color adjustments for the base layer to make it grayscale
--set color adjustments enabled of layer 1 to true
tell color adjustments of layer 1
set saturation to -100
end tell
-- Valid command verified by your dictionary screenshot:
flip horizontally theDocument
end tell
-- Save and close properties
export theDocument to file destFilePath as PNG
close theDocument saving no
on error errMsg
display dialog "Error processing " & fileName & ": " & errMsg buttons {"OK"} default button 1
end try
end repeat
end tell
display dialog "Batch processing complete. Files saved to: " & destPOSIX buttons {"OK"} default button 1
end convertFolderToGrayscale
I apologize for the lousy formatting; a quick scan of the site didn’t show me how to present properly formatted Apple Scripts.
When I run this script, I get several problems. When it runs, it opens each of the frames correctly, then correctly desaturates it and correctly flips it horizontally, but then it does NOT close that window and it does NOT save the output, and it reports this error:
Error processing MeteorB 00_00_00.03.png: You can’t save the file “CF00162E-ADF6-43F5-874E-7ABE63C9DA4C” because the volume “Macintosh HD” is read only.
Yeah, right. It’s trying to save to “Macintosh HD”, the internal hard drive, and not to “Darth Tenzing”, the external hard drive that I specified. Moreover, “Macintosh HD” is NOT read only. I’ll experiment with hard-coding the folder names.
When it was finished, it provided this final report:
Batch processing complete. Files saved to: /Volumes/Darth Tenzing/TelescopicMeteors/SourceFrames/TargetFrames/
No, the files were NOT saved.
Note that the Script Editor declared that the Pixelmator Pro reference to “saturation” was invalid. Script Editor is wrong. So were both Claude and Gemini. When I provided these two LLMs with the quotation from the Pixelmator Pro dictionary in Script Editor, they both had the decency to admit that they were wrong.
So, I need to modify this script to do two things:
- It MUST close each document after it has made the changes. There are 54,000 frames in an hour of video and I really don’t want to have to go through 54,000 windows, closing each one and clicking the button that says “delete” when it asks if I want to save the frame before closing it.
- It MUST save the modified document in the specified folder.
I earnestly solicit any comments on these scripts, other than comments along the lines of “It’s OK, Chris, everything will be just fine. You just sit down and watch endless hours of soap operas on TV while the real programmers get back to work.”
Oh, and if a) it’s technically possible on this forum; and b) you guys would like to see them; I can post a few video snippets of telescopic meteors. A script for analyzing video of telescopic meteors