Hello,
First off I’d like to apologize if this specific problem has been tackled elsewhere. I’ve searched through the forums here and elsewhere (Apple Discussion Forums, etc.) and can’t quite seem to get exactly what I need.
Also, I am fairly new to Applescript. So… if my issue has a simple solution, I won’t be surprised.
Allrighty… with that said, here’s what’s going on:
- I’m manually scripting something that I should be able to do, but can’t, with Folder Actions. The reason I can’t do it with Folder Actions is because it involves files being copied over a network into a local folder, and Folder Actions doesn’t pick up on the fact that they’ve been copied in.
- The intention of the script is to monitor the modification date of the folder in question (the “Drop” folder), and run a routine that sends all new files to a Compressor droplet when it detects that the modification date of the folder has changed (indicating the arrival of new files). I’ve also built in a routine to make sure that it doesn’t send partially-copied files to Compressor.
The simplified version of my script is as follows:
on run
tell application "Finder"
set the drop_folder to "Mac OS:Users:cvw:Compressor:ProRes422:Drop" as alias
set x to drop_folder
set modDate to modification date of x
repeat
try
set dateCheck to modification date of x
if modDate ≠dateCheck then
-- in the original code, this runs a routine that picks up every new file placed into my Drop folder and sends it to a Compressor droplet.
set modDate to dateCheck
end if
delay 10
on error
delay 5
end try
end repeat
end tell
end run
This script, as it stands, works perfectly. I can run it from the Script editor or I can save it out as an application, and it will successfully handle all files I throw at it.
However, as the title of my post would suggest, my problem is that the script simply refuses to quit. Whether I hit Cmd-Q, select Quit from the app menu, or attempt a shutdown/restart/log off, it just sits there and I have to force quit it from the force quit panel.
Now… in the research I’ve done, I keep seeing that this problem can frequently be fixed by using an idle handler, in a stay-open application, instead of a repeat loop. I gave that a shot but I could only get it to work when I enclosed all of my existing script in an idle handler (and turning off the repeat loop). Unfortunately, this disabled the functionality of my script because part of my script relies on a continuous update of the modification date checker (at the end of the script, the modDate is updated, then checked against an updated dateCheck, then updated again, then checked again, etc.). Inside the idle handler, the entire script would run once each time it was called, not being able to take advantage of the repeat loop to check the modification date on each repeat.
If there’s any way to stick an idle handler within the “tell” block, that might do it… basically just swap out the existing repeat loop for an idle handler. Or that might be impossible and I might be talking gibberish.
I’ve tried a number of “on quit” blocks, to no avail (which again I believe is the result of the CPU being hogged by the repeat loop… or something along those lines). For example, I’ve stuck the following code at the end of my script:
on quit
beep
return
end quit
… the beep just making sure that the script responds when I tell it to quit. And sure enough, every time I hit Cmd-Q, it beeped, so it was running my “on quit” block… it just didn’t quit. And I’ve replaced “return” with “error -128”, “error number -128”, and “continue quit”… none of them worked.
And again, this is meant to be a script that runs in the background. I can’t have it toss up a dialog during the normal operation of the script asking if it should quit. I suppose, if it would work, I could have it bring up a dialog asking “Are you sure you want to quit?” when the quit command was given… if that would somehow help things.
Well, I hope this all made enough sense. Sorry if I’m a bit long-winded. If you’ve got any questions to help clarify what my issue is, please let me know. I can also post the entirety of the script if that would help matters.
And thank you so much for taking time to read this and hopefully toss some insight my way.