1
votes

I have a Folder Action watching a folder to run an Applescript whenever a file is added to it.

The Applescript tells my thumbnail generator app to process the images. This works fine. The app creates a subfolder, and places the thumbnails inside.

The issue is that the Folder Action gets triggered for each image made in the subfolders, and it makes a thumbnail of the thumbnails in yet another subfolder.

This happens only once for some reason, but its still too much.

Is there a way I can set a Folder Action to ignore files added to its subfolders? I need to maintain this directory structure where the thumbnail generator outputs into a child folder.

Here's the script:

on adding folder items to this_folder after receiving added_items
    repeat with eachItem in added_items
        tell application "ThumbsUp" to open eachItem
    end repeat
end adding folder items to

On another forum someone suggested this instead:

on adding folder items to this_folder after receiving added_items
    
    repeat with eachItem in added_items
        tell application "Finder" to set itsParent to (container of eachItem) as alias
        if itsParent is this_folder then tell application "ThumbsUp" to open eachItem
    end repeat
    
end adding folder items to

which should make ThumbsUp not run on items in the subfolder, but for some reason it continues with the same behaviour.

How can I stop folder action from running on subfolders?

2

2 Answers

0
votes

Someone on another forum posted script as an answer, which works. The problem is because ThumbsUp creates the subfolder, and that subfolder gets added to the list of files to open. So this script fixes that

on adding folder items to this_folder after receiving added_items
    repeat with eachItem in added_items
        tell application "System Events" to set itsKind to kind of eachItem
        if not (itsKind is "Folder") then tell application "ThumbsUp" to open eachItem
    end repeat
end adding folder items to
-1
votes

Folder Actions do not normally recurse, so I suspect the problem is that the "ThumbsUp" application is designed to process folders of images as well as individual images. When it creates a folder to store the thumbnails, that folder is seen as 'added' to the watched folder, and is sent to the script and back to ThumbsUp. Open ThumbsUp and see if you can set the output folder to a different location. If that doesn't work, try excluding folders from being processed in your script:

on adding folder items to this_folder after receiving added_items
    tell application "System Events"
        repeat with an_item in added_items
            set disk_item to disk item (POSIX path of an_item)
            if class of disk_item is not folder then
                tell application "ThumbsUp" to open disk_item
            end if
        end repeat
    end tell
end adding folder items to