Want to highlight a helpful answer? Upvote!

Did someone help you, or did an answer or User Tip resolve your issue? Upvote by selecting the upvote arrow. Your feedback helps others! Learn more about when to upvote >

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Folder Action does not run on SECOND file only

Does any one know of a bug or a log for folder scripts that do not run? I am trying to get a basic folder script (to replace %20 in the file name) of the Downloads folder.


When downloading multiple files (two or more) it runs only on the first file, successfully without error, and then never runs on the second file. If I move both of the files out of the Downloads folder and move it back it, the one file that does not get the folder action now does and everything is peachy.


So it is not that the folder action is not scripted properly. It is just that the folder does not catch the second file download - guess maybe too fast? Has any one seen this or have this bug?


Regards,

Chris Wanja

15" Unibody MacBook Pro , Mac OS X (10.6.4)

Posted on Mar 7, 2012 5:12 PM

Reply
15 replies

Apr 20, 2012 5:58 PM in response to red_menace

Chris i have the same problem, i've implemented a script and i 've attached about 1000 folders, and than when i copy more than one file to one of theses folders, or some files are copied or it is never trigged, sometimes it simply does not work!!


I did a test, i run this applescript [tell application "System Events" to activate"] before copy the files, but it kept unstable, sometimes it works, sometime it does not work!


i did notfound anything aboutthis subjecton the Internet.


Please i need some help to solve this problem

Apr 20, 2012 11:33 PM in response to fop.net

Folder actions can be spotty, particularly when doing tasks that involve the Finder. I think what happens is that triggering a folder action script will make the dispatcher miss any files added while the script is running (and for a throttle period after), so adding files faster than about once every ten seconds can cause problems. Of course, the dispatcher is supposed to check periodically for missed files, but the default time for that is fairly long (3 minutes), and I'm not entirely convinced it works as advertised.


There are workarounds and alternate approaches, but we'd need to see the script in question.

Apr 21, 2012 5:17 AM in response to twtwtw

For my script, it is pretty simple -- I am away from my computer, but can easily explain it:


It has a Find / Replace. It finds any file in ~/Downloads/ that has %20 and then replaces it with a space ( ) [minus the parentheses).


Pretty simple script if you asked me. But i guess I could see how adding a file to the folder while it is running would cause it to be skipped. My only problem with that explination is that once I remove the file from the folder and then drag it back into the folder it STILL does not fire off. And this could be 10 - 20 seconds after.


Any additional thoughts?

Apr 21, 2012 10:09 AM in response to Chris Wanja

Need more details:


  • Are you using the Finder, System Events.app, or unix to change the file names?
  • If you move in two or more files in the same drag, do they all get processed or just the first one?
  • Do you get any errors in Console.app when the Folder action runs?
  • If the script fails to fix a file, and you leave it alone for 15 minutes, is the file fixed in the interim?

Apr 24, 2012 6:04 AM in response to Chris Wanja

In my case, i use both solutions


1- Automator running rsync (unix) to copy files, and i use the Finder to copy the new files to my external HD

2- When i use Finder, sametimes the event dispatch my actionscript, and move all files sucessfully but other moment it does not. In both of cases, the Folder Action Dispatcher and System Event process are in memory.

3- No erros in console, the script is very tested, it´s ok.

4- My case the files was not copied.


I use this handle to capture my folder events "on adding folder items to this_folder after receiving added_items"

I have more than a thousands foders with the same script activated.


My problem is: The system does not trigger a folder action script, or the delay is very big.

Apr 24, 2012 12:41 PM in response to twtwtw

In reply to twtwtw


  • Are you using the Finder, System Events.app, or unix to change the file names?

    Finder. The Automator script is linked here: http://img.chriswanja.com/personal/FolderActionScreencap.png

  • If you move in two or more files in the same drag, do they all get processed or just the first one?

    Moving multiple items in (tested with 2, 3, and 4 files); 2 - all were changed, 3 - all were changed, 4 - all were changed

  • Do you get any errors in Console.app when the Folder action runs?

    Downloaded three files. Two were not renamed. In Console, there were these two errors:

    • 4/24/12 2:18:06.448 PM com.apple.launchd.peruser.501: (com.apple.FolderActions.folders) Throttling respawn: Will start in 2 seconds
  • If the script fails to fix a file, and you leave it alone for 15 minutes, is the file fixed in the interim?
    • After the above, I let the two additional files sit from 2:18 till 2:40. Never changed. No additional Console errors either during that waiting period.
    • There were additional Automator errors (like below), but they looked to only be related to MS Office issues.

      4/24/12 2:28:18.201 PM Automator Runner: -[AMApplicationRegistry loadDefinitionAtURL:]: No application name for definition at URL file://localhost/Library/Automator/Office.definition/


Do you think adding in a few second pause after or before the Automator script runs would alleviate the problem? I noticed you can add that. My thoughts on the latter are that it would only help if I was able to download all the files I need in that X number of seconds - IE if I get it to 5 seconds, and I download 20 files, chances are unlikely I won't get through all 20 links in 5 seconds.


My system is:

10.7.3 Unibody MBP


Appreciate your assistance.

Regards,

Chris Wanja

chris.wanja@gmail.com

Apr 24, 2012 2:44 PM in response to Chris Wanja

well, with a little testing the problem seems to be that the Finder/System Events don't queue up apple events properly. Folder actions seems to be running the script at each invocation but it's not getting picked up by the app at the other end when that app is busy. a delay statement might help, or you might try rewriting the workflow so that it checks every file in the folder, rather than just the ones passed by the folder action.

Apr 25, 2012 4:43 PM in response to twtwtw

In reply to twtwtw



I think this is a system problem, the system could not fail to execute a script for any unavailability of another application, and it can open another instance of it,
On the other hand, to implement something to bypass that was scheduled by the mac osx, it would not begood behavior.
I cleared my log, and found a bug of unknown cause, or by executor or by implemented code.








25/04/12 20:15:00,171 com.apple.launchd.peruser.501: (com.apple.quicklook.config[6284]) Bug: launchd_core_logic.c:4230 (25397):9

25/04/12 20:15:00,172 com.apple.launchd.peruser.501: (com.apple.quicklook.config[6284]) Bug: launchd_core_logic.c:4180 (25397):9

25/04/12 20:15:00,172 com.apple.launchd.peruser.501: (com.apple.quicklook.config[6284]) Bug: launchd_core_logic.c:4181 (25397):9

25/04/12 20:15:00,172 com.apple.launchd.peruser.501: (com.apple.quicklook.config[6284]) Bug: launchd_core_logic.c:4182 (25397):9

25/04/12 20:15:00,172 com.apple.launchd.peruser.501: (com.apple.quicklook.config[6284]) Bug: launchd_core_logic.c:4189 (25397):9

25/04/12 20:18:07,417 com.apple.launchd.peruser.501: ([0x0-0x35035].com.apple.AppleScriptRunner) Bug: launchd_core_logic.c:4151 (25397):24

25/04/12 20:18:07,418 com.apple.launchd.peruser.501: ([0x0-0x35035].com.apple.AppleScriptRunner) Bug: launchd_core_logic.c:4224 (25397):9

25/04/12 20:18:07,418 com.apple.launchd.peruser.501: ([0x0-0x35035].com.apple.AppleScriptRunner[6869]) Bug: launchd_core_logic.c:4180 (25397):9

25/04/12 20:18:07,418 com.apple.launchd.peruser.501: ([0x0-0x35035].com.apple.AppleScriptRunner[6869]) Bug: launchd_core_logic.c:4181 (25397):9

25/04/12 20:18:07,418 com.apple.launchd.peruser.501: ([0x0-0x35035].com.apple.AppleScriptRunner[6869]) Bug: launchd_core_logic.c:4182 (25397):9

25/04/12 20:18:11,601 AppleScript Runner: CPSGetFrontProcess(): This call is deprecated and should not be called anymore.

25/04/12 20:18:11,665 com.apple.launchd.peruser.501: ([0x0-0x36036].com.apple.AppleScriptRunner) Bug: launchd_core_logic.c:4151 (25397):24

25/04/12 20:18:11,666 com.apple.launchd.peruser.501: ([0x0-0x36036].com.apple.AppleScriptRunner) Bug: launchd_core_logic.c:4224 (25397):9

25/04/12 20:18:11,666 com.apple.launchd.peruser.501: ([0x0-0x36036].com.apple.AppleScriptRunner[6880]) Bug: launchd_core_logic.c:4180 (25397):9

25/04/12 20:18:11,666 com.apple.launchd.peruser.501: ([0x0-0x36036].com.apple.AppleScriptRunner[6880]) Bug: launchd_core_logic.c:4181 (25397):9

25/04/12 20:18:11,666 com.apple.launchd.peruser.501: ([0x0-0x36036].com.apple.AppleScriptRunner[6880]) Bug: launchd_core_logic.c:4182 (25397):9

25/04/12 20:18:15,801 AppleScript Runner: CPSGetFrontProcess(): This call is deprecated and should not be called anymore.

25/04/12 20:18:15,869 com.apple.launchd.peruser.501: ([0x0-0x37037].com.apple.AppleScriptRunner) Bug: launchd_core_logic.c:4151 (25397):24

25/04/12 20:18:15,869 com.apple.launchd.peruser.501: ([0x0-0x37037].com.apple.AppleScriptRunner) Bug: launchd_core_logic.c:4224 (25397):9

25/04/12 20:18:15,870 com.apple.launchd.peruser.501: ([0x0-0x37037].com.apple.AppleScriptRunner[6891]) Bug: launchd_core_logic.c:4180 (25397):9

25/04/12 20:18:15,870 com.apple.launchd.peruser.501: ([0x0-0x37037].com.apple.AppleScriptRunner[6891]) Bug: launchd_core_logic.c:4181 (25397):9

25/04/12 20:18:15,870 com.apple.launchd.peruser.501: ([0x0-0x37037].com.apple.AppleScriptRunner[6891]) Bug: launchd_core_logic.c:4182 (25397):9

25/04/12 20:18:20,227 AppleScript Runner: CPSGetFrontProcess(): This call is deprecated and should not be called anymore.

25/04/12 20:18:46,506 Dock: kCGErrorIllegalArgument: CGSSetWindowListGlobalClipShape: Invalid window 0x7d

25/04/12 20:18:46,506 Dock: kCGErrorFailure: Set a breakpoint @ CGErrorBreakpoint() to catch errors as they are logged.

25/04/12 20:18:46,530 Dock: kCGErrorIllegalArgument: CGSSetWindowTransformsAtPlacement: Failed

25/04/12 20:18:46,545 Dock: kCGErrorIllegalArgument: CGSSetWindowListGlobalClipShape: Invalid window 0x7d

25/04/12 20:18:46,546 Dock: kCGErrorIllegalArgument: CGSSetWindowTransformsAtPlacement: Failed

25/04/12 20:18:46,546 Dock: kCGErrorIllegalArgument: CGSOrderWindowListWithOperation

25/04/12 20:18:46,547 Dock: kCGErrorIllegalArgument: CGSOrderWindowList

Apr 25, 2012 4:59 PM in response to fop.net

A overview of my applescript



on adding folder items tothis_folderafter receivingthese_items

set pFileWatchedFolder to copyItems(these_items)


if pFileWatchedFolder is not missing value then speak(ioLib's getDisplayName(pFileWatchedFolder))


end adding folder items to


on copyItems(these_items)

local pFileWatchedFolder

set pFileWatchedFolder to missing value


try


repeat with i from 1 to number of items in these_items

set als_item to item i of these_items as alias

set strItemPath to als_item as alias as Unicode text


set pFileWatchedFolder to ioLib's getWatchedFolder(als_item, pFileWatchedFolder, myWatchedFolders)

if pFileWatchedFolder is missing value then

return pFileWatchedFolder

end if



set this_watched to pFileWatchedFolder as alias as Unicode text


set remotePath to ioLib's getRemotePath(this_watched, strItemPath, myRemoteFolder)

set targetPath to ioLib's getTargetPath(remotePath)


tell application "Finder"



-- verificando se o destino é uma pasta ou um arquivo

if ioLib's isFolder(strItemPath) then


ioLib's attachFolderAction(als_item, path to me asUnicode text)



-- verifica se a pasta existe

if not (exists remotePath) then

set folderName to ioLib's getDisplayName(als_item)


makenewfolderattargetPathwith properties {name:folderName}

end if


if length of (list folder strItemPath without invisibles) > 0 then

set folderItems to (items of entire contents of folder strItemPath)


my copyItems(folderItems)

end if

else if not (exists remotePath) then


-- Copiando o arquivo

if ioLib's isVisibleAlias(als_item) then

copy fileals_item to foldertargetPath

end if

end if


end tell


end repeat



return pFileWatchedFolder

on error errStr

display alerterrStr

end try


end copyItems



------------------------------------------------

------- Metodos Utilitários --------------

------------------------------------------------


on speak(str)

say str & " backup, complete."

end speak

Aug 16, 2013 5:08 AM in response to Chris Wanja

Hi chris if you are running the legacy folder actioin script from a n automator.app "run applescript" workflow node you will need to change the event hander from what you have "on adding folder items to my_hot_action_folder after receiving list_of_added_items .... end on adding items" to that of "on run {list_of_added_items,some_parms} .... end run " I think.


Errors/Run time error log for applescripts - see later in post


If your applescript is solid as far a you know (no run time errors), then you can simply use the automator.app "folder action" workflow using a "run applescript" node only for the folders where you want the applescript event to run.


works great!


You can derive the other envronmentals (folder name etc etc) dynamically from within the applescript. (see my example and others out there)


I just posted this link in reation to another issue that might be of assistance to you. . If your former applescript folder action was rock solid then became erratic and unpredictable in OSX 10.7 or 10.8, you simply need to attach an AUTOMATOR "folder ACTIONS" workflow node to the folder.



The Automator.app's "folder action" "run applescript" workflow node contains 99.% of your original applescript you use current.



You just need to change the handler.. so simple.



see this link I just posted .https://discussions.apple.com/thread/4237919?start=30&tstart=0


2) Errors/Run time error log for applescripts: - nope... you will have to develop your own.. especially for backgroud tasks. I developed a simple "logger" that writes to ~/library/logs/my_apple_script.event.log via


do shell script "echo " & console_sysout & " >> " & my_event_trace_log_POSIX


etc etc "and watch with the console.app. you just need to set error recovery environments over all or parts of your script using "try... on error ... end try" constructs.. these are well documented on these and the macscripts.net forums.. so many examples.


In these cases. you need to make your own method of logging stats and errors...


I aev an apple script hat does this and have this in my ~/library/scripts and dynamically load it in the aplescript and pass the text strings to it.. works great.


you could also just use a simple logger via an applescript "do shell" and use a unix log command as somthing really simple .


do shell script "logger " & "\"" & tracefailed_msg & "\"" -- log this to /var/log .. ahs users name attached



hth

Post your results for others to see.



Warwick

Hong Hong

Folder Action does not run on SECOND file only

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.