I’m not sure about you guys, but in my experience - folder action scripts are often flaky and unreliable. Sometimes they can seemingly automatically disable, then sometimes re-enabling does not do the trick, you must often relink the script to the folder. I find their behaviors somewhat unreliable, yet extremely convenient when working properly. Case in point, I use a script that simply copies files around to different places. It basically watches a folder, and any items dropped in there get copied off to another location, then deleted. Here is one version of the script I use:
on adding folder items to theFolder after receiving addedItems
stable(addedItems)
repeat with i from 1 to number of items in addedItems
set this_item to item i of addedItems
tell application "Finder"
try
duplicate this_item to folder "PDFer1:Users:admin:Desktop:Create PDFs:In:" with replacing
delete addedItems
end try
end tell
end repeat
tell application "System Events" to set folder actions enabled to true
end adding folder items to
on stable(addedItems)
tell application "Finder"
repeat with theItem in addedItems
-- Mr Comment sez : "Aare u Copieink teh Fileh?"
repeat
try
get info for theItem
set sizethen to (size of the result)
on error theError -- Stuff went wrong, master
display dialog theError
error number -128 -- break it off if stuff went wrong!
end try
delay 5
get info for theItem
set sizenow to (size of the result)
if sizethen = sizenow then
if sizenow = 0.0 then
error number -128 -- break it off if stuff went wrong!
end if
exit repeat
end if
end repeat
end repeat --Waiting for all files to become stable
end tell
end stable
I’ve even added a line to make sure folder actions remain enabled each time the script is triggered. Every so often though, the script quits working. There is typically a file sitting there, but not being acte upon. Deleting this file seems to disable the script entirely.
I seem to remember a clever snippet someone posted. It was a way to achieve a “folder action” without the script actually being a folder action. The code simply provided “watching” capability.
Do any of you experts have any suggestions as to maybe how to amend the existing script? Or perhaps how to achieve fodler action capabilities, yet circumventing the actual folder action set-up?
The usual shift for flakey Folder Actions is to switch to a stay-open application with an on idle handler in it. They go like this:
on run
-- do stuff - this runs when the application is started to set things up.
-- Here, since you're moving the files to other places so the folder is normally empty, you can just process what you find there.
end run
on idle
-- In this section, you just count the files in the folder. If there are some, you process them.
return 60 -- do this every 60 seconds.
end idle
on quit -- not essential if you just quit the app.
-- do stuff - assumes something in the idle handler would cause the application to quit from within or if you want to save stuff before quitting to a pref file or log.
continue quit
end quit
I’m also having the “Flaky Folder Action” Problem.
Our network has a Mac Mini running Mac OSX 10.3.9 which is used solely to send and receive faxes with 4-Sight Fax Server software. 4-Sight Fax will only put incoming faxes into a local folder so I have written a folder action to copy the files to a shared drive. The script is:
on adding folder items to myFolder after receiving aliasList
delay 5
repeat with thisItem in aliasList
processUnknownItem(thisItem)
end repeat
end adding folder items to
on processUnknownItem(thisItem)
if (thisItem as text) ends with ":" then
processFolder(thisItem)
else
processFile(thisItem)
end if
end processUnknownItem
on processFolder(thisFolder)
set itemList to list folder thisFolder without invisibles
--display dialog (thisFolder as string) & " Count " & (count of itemList)
repeat with i in itemList
processUnknownItem(alias ((thisFolder as text) & i))
end repeat
end processFolder
on processFile(thisFile)
try
tell application "Finder"
set fileInfo to the info for thisFile
if ((disk "SCANNED" exists) is equal to false) then
open file "SCANNED2"
try
if the window "SCANNED" is visible then close the window "SCANNED"
end try
end if
if the file type of fileInfo is "TIFF" then
move file thisFile to folder "SCANNED:Fax Incoming:"
end if
end tell
on error myErr
display dialog myErr
end try
end processFile
The script works well but “enable folder actions” turns off a few times every day. I have put the line:
“tell application “System Events” to set folder actions enabled to true” into the script with no help and I have locked the preference file “com.apple.FolderActions.plist” so that enable folder actions cannot be turned off and the same problem continues. The only other software on the computer is 4D Client (v 2003.5) - which sends the faxes to 4-Sight and Timbuktu (v 6.0.3).
Question: What is turning “enable folder actions” off ? Is there a way to lock it on ?
Model: Mac Mini G4
AppleScript: 1.9.3
Browser: Safari 312.6
Operating System: Mac OS X (10.3.9)
If System Events turns off, then I think folder actions are disabled. Maybe you can make a folder actions helper, with an idle handler, that runs in the background at login. Something like this:
on idle
tell application “System Events”
set folder actions enabled to true
end tell
return 5 – check every 5 seconds
end idle
I ran the idle script and nothing has changed. I looked in activity monitor and don’t see it running.
Is there a secret in getting to stay active. I just put it in a script and pushed run. I’m reasonably knowledgeable in applescript but haven’t used the on idle command before.
I saved it as a Stay Open App and it worked but it occ’l generated an error.
So I changed it as follows:
on idle
tell application "System Events"
try
if folder actions enabled is false then set folder actions enabled to true
end try
end tell
return 10 -- check every 10 seconds
end idle
So far this has worked - folder actions has remained enabled.
I just wish I knew what was wrong to cause this as on other computers in our network I haven’t had this problem.
Thanks for all your help.
Roy