Basic Folder Action....

Hello everybody!
I am new to Automator/ Apple Script and tried to program something for a friend of mine:
Folder “Source” with changing amount of subfolders. Content: Pictures.
The Program should do the following task: Check Folder “Source” for content, copy (Picture) content to different Folder “Target”, then erase Subfolders in Folder “Source”. thats it…

What i managed to do by now is a folder action and/ or an automator program checking folder “source”, copy the pictures to “target” and thats it. Whenever i try to add the action “afterwards delete content of folder “source”” it ends up in a) pictures are in the trash or b) pictures copied, subfolders still in folder “source”.

Can someone help?

Btw, what i “programmed”:

  • ask finder object
  • check content of folder “source” (with subfolders)
  • filter objects (kind is not folder)
  • move filtered objects to Target folder (and erase content of target folder before)
  • check content of folder
  • filter objects (any kind of content)
  • move content to trash

I appreciate any kind of help - thanks in advance and i hope my english is “read- and understandable”

Frank

Hi. Welcome to MacScripter. (Somewhat belatedly, I’m afraid. The Automator forum doesn’t get a lot of visitors.)

I can’t get the filter action to work in Automator 2.6, but this works provided there’s only one level of subfolders:

Ask for Finder Items. (Select “Folders” in the “Type:” pop-up.)
Get Folder Contents. (Leave “Repeat for each subfolder” unchecked.) Gets the subfolders.
Set Value of Variable. (Click the pop-up and enter a suitable name, perhaps “subfolders”.) Memorises them,
Get Folder Contents. (Leave “Repeat for each subfolder” unchecked.) Gets the subfolders’ contents.
Move Finder Items. (Set the destination folder.) Moves the contents to the destination folder.

Get Value of Variable. (Same variable name as above. Click “Options” and check “Ignore this action’s input”.) Gets the subfolders again.
Move Finder Items to Trash. Moves them to the trash.

Hi Nigel,

many thanks for your help! Especially “Set and get value of variable”…
Finally i managed that all subfolders are checked, picture content is moved to another folder and the content of the main folder is moved to trash…
But… the picture content in the main folder is not moved to the new folder:

Main Folder - Picture 1
Subfolder 1 - Picture 2
Subfolder 2 - Picture 3
Subfolder 3

Pictures 2 to 3 are moved to another folder, Picture 1 not.
All Subfolders are moved to trash, including picture 1
Until now i did not manage ist to get Picture 1 moved to another folder… maybe you can give me a hint/ help again?

Many thanks in advance

Frank

My workflow looks like this:

Service receives (Select “Folders” in the “Type:” pop-up.)
Ask for Finder Items.
Get Folder Contents. (“Repeat for each subfolder” checked.) Gets the subfolders.
Set Value of Variable. (Click the pop-up and enter a suitable name, perhaps “subfolders”.) Memorises them,
Get Folder Contents. (Leave “Repeat for each subfolder” unchecked.) Gets the subfolders’ contents.
Filter Finder Objects. (Kind is not “Folder”)
Move Finder Items. (Set the destination folder.) Moves the contents to the destination folder.
Get Value of Variable. (Same variable name as above. Click “Options” and check “Ignore this action’s input”.) Gets the subfolders again.
Move Finder Items to Trash. Moves them to the trash.
Ask for Finder Items. (Subject is Main Folder)
Get Folder Contents. (Leave “Repeat for each subfolder” unchecked.)
Move Finder Items to Trash.

Hi Frank.

I hadn’t realised there’d be files in the top level of the folder too. If the ‘Move Finder Items’ action actually works for you, one of these arrangements may do the trick.

Either:

Ask for Finder Items. (Select “Folders” in the “Type:” pop-up.)
Get Folder Contents. (Check “Repeat for each subfolder”.) Gets the main folder’s entire contents.
Set Value of Variable. (Click the pop-up and enter a suitable name, perhaps “folderContents”.) Memorises them.
Filter Finder Items. (Kind is not folder.) Picks out the files.
Move Finder Items. (Set the destination folder.) Moves them to the destination folder.
Get Value of Variable. (Same variable name as above. Click “Options” and check “Ignore this action’s input”.) Gets the entire contents again. The variable probably still contains the old file references.
Filter Finder Items. (Kind is folder) Picks out the folders.
Move Finder Items to trash. Moves them to the trash.

Or:

Ask for Finder Items. (Select “Folders” in the “Type:” pop-up.)
Set Value of Variable. (Click the pop-up and enter a suitable name, perhaps “mainFolder”.) Memorises the chosen folder.
Get Folder Contents. (Check “Repeat for each subfolder”.) Gets its entire contents.
Filter Finder Items. (Kind is not folder.) Picks out the files.
Move Finder Items. (Set the destination folder.) Moves them to the destination folder.
Get Value of Variable. (Same variable name as above. Click “Options” and check “Ignore this action’s input”.) Gets the main folder again.
Get Folder Contents. (Leave “Repeat for each subfolder” unchecked.) Gets everything remaining in its top level. (Should just be subfolders.)
Move Finder Items to trash. Moves that to the trash.

The ‘Move Finder Items’ action doesn’t work on my machine, but using an AppleScript instead definitely does:

Ask for Finder Items. (Select “Folders” in the “Type:” pop-up.)
Set Value of Variable. (Click the pop-up and enter a suitable name, perhaps “mainFolder”.) Memorises the chosen folder.
Run AppleScript. (Replace the template script with this:

on run {input, parameters}
	
	set mainFolder to item 1 of input
	tell application "Finder"
		set output to (every file of entire contents of mainFolder) as alias list
	end tell
	
	return output

end run

). Finds all the files in the folder’s hierarchy.
Move Finder Items. (Set the destination folder.) Moves them to the destination folder.
Get Value of Variable. (Same variable name as above. Click “Options” and check “Ignore this action’s input”.) Gets the main folder again.
Get Folder Contents. (Leave “Repeat for each subfolder” unchecked.) Gets everything remaining in its top level. (Should just be subfolders.)
Move Finder Items to trash. Moves that to the trash.

Hello Nigel,

long time no hear… :wink:
Finally tested your script and after some “minor changes” it works! Thank you very much!
So this is the working script:

Ask for Finder Items. (Select “Folders” in the “Type:” pop-up.)
Set Value of Variable. (Click the pop-up and enter a suitable name: “mainFolder”.) Memorises the chosen folder.
Run AppleScript

on run {input, parameters}
tell application “Finder”
set mainFolder to item 1 of input
set output to (every file of entire contents of mainFolder) as alias list
end tell
return output
end run

Move Finder Items. (Set the destination folder.) Moves them to the destination folder.
Get Value of Variable. (Same variable name as above. Click “Options” and check “Ignore this action’s input”.) Gets the main folder again.¨
Move Finder Items to trash. Moves that to the trash.

It gets frustrating.
The automator script works, but if you put something in the folder via network: no action (Gear wheel turns for a short period of time)
I guess i have to try in apple script and/ or with an interval.
Again, if someone has an idea why it does not work proper with input via network or on how to implement an interval - thank you very much in advance!

Frank

Finally…
Its just a workaround but finally it all works.
I added another folder to the process which receives the images via network. From this folder all content is automatically copied to the folder with the “filter pictures and move them” action folder. This works. Just a workaround, no “sophisticated” programming… Only one thing, you have to wait for around 5 seconds (before you send new pictures via network), otherwise the action fails.

Hi Frank.

Thanks for the update. Sorry I couldn’t help with the network problem. Folder actions are notorious for triggering too early if a drop takes too long, such as when files are being copied from another source or there are a lot of them. Presumably your workaround works because once the files are on the local disk, their transfer to the action folder is just a matter of a few minor changes in the disk catalogue.

Glad you’ve found something that at least works.