0

I want to trigger the automator folder action when I remove a file from a folder, is there a way to achieve this? The folder action works perfectly when I add something to it but not when I remove it.

How can I achieve this?

Thanks in advance!

Edit 1:

It is perhaps better if I give more details about what I want to achieve. I have a folder on the desktop and I want his color to change depending on whether it is full or empty. I have already a working shell code which works perfectly when I run it through terminal.

Using that shell code with automator folder action works only when I put a new file inside the folder but not when I remove it.

1
  • I'm not convinced that it's possible. Can you explain your workflow a bit more? Perhaps there's another way of doing it.
    – benwiggy
    Jan 24, 2022 at 12:12

1 Answer 1

2

In Script Editor.app, paste this following AppleScript code into a new document, then name and save it as a “scpt” file to /Users/YOUR_SHORT_NAME/Library/Workflows/Applications/Folder Actions folder.

I don't know what your "working shell code" is so I used code for changing the folder labels in Finder as an example

on adding folder items to theFolder after receiving theNewItems
    --  Called after items have been added to a folder
    --
    --  theFolder is a reference to the modified folder
    --  theNewItems is a list of references to the items added to the folder 
    tell application "Finder" to set label index of theFolder to 3
end adding folder items to

on removing folder items from theFolder after losing removedItemNames
    --  Called after items have been removed from a folder
    --
    --  theFolder is a reference to the modified folder
    --  removedItemNames is a list of names of items removed from the folder
    tell application "Finder"
        set theCount to count of items of entire contents of theFolder
        if theCount = 0 then
            set label index of theFolder to 0
        end if
    end tell
end removing folder items from

After this code is tweaked to your liking, and has been saved to the previous mentioned folder, it will then be available to use within the Folder Actions Setup.app to to attach to any folder of your choice.


FYI: These are all of your Folder Action options you can use with your AppleScripts

on adding folder items to theFolder after receiving theNewItems
    --  Called after items have been added to a folder
    --  theFolder is a reference to the modified folder
    --  theNewItems is a list of references to the items added to the folder 
    -- your code goes here
end adding folder items to

on removing folder items from theFolder after losing removedItemNames
    --  Called after items have been removed from a folder
    --  theFolder is a reference to the modified folder
    --  removedItemNames is a list of names of items removed from the folder
    -- your code goes here
end removing folder items from

on closing folder window for theFolder
    --  Called when a folder's window is closed in the Finder
    --  theFolder is a reference to the closed folder
    -- your code goes here
end closing folder window for

on moving folder window for theFolder from previousBounds
    --  Called when a folder's Finder window has been moved or resized
    --  theFolder is a reference to the folder being altered
    --  previousBounds is old position and size of the folder's Finder window
    -- your code goes here
end moving folder window for
1
  • Many thanks! That is exactly what I wanted to achieve! Have a nice day :)
    – Pa Dalton
    Jan 25, 2022 at 8:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .