I’ve looked all over the place but can’t find the syntax anywhere.
I’m looking for a script to take the selected folder that was selected in Automator, take the contents of that folder, and send it to the trash for one of my Automator applications, and then give the option to empty the trash and if cancelled, still send the contents to the trash.
Don’t exactly know what your asking but i use this in my applescript menu to clean my desktop.
set MyDesktop to path to desktop
tell application "Finder"
try
move every item of MyDesktop to the trash
end try
end tell
This is a sample droplet that you can drop items on it. If you drop folder(s) it trashes the items (including any other folders in that folder) in those folders, not the folder itself. If you drop items other than folders, it simply ignores them. At the end, it asks to empty trash or not. If you click Cancel, trash won’t be emptied. Make necessary changes to make it work with your Automator action.
on open (the_items)
tell application "Finder"
repeat with i from 1 to (count of items of the_items)
set the_path to (item i of the_items)
if (the_path as string) ends with ":" then
move every item of the_path to trash
end if
end repeat
display dialog "Empty trash?"
empty
end tell
end open
My approach is to grab the name of and path to the folder, trash the entire folder, then create a new folder at the same location and name it with the same name. That way you don’t have to look at the contents at all.
set theFolder to (choose folder)
tell application "Finder"
set fldrName to name of theFolder
set myPath to folder of theFolder
move theFolder to trash
make folder at myPath with properties {name:fldrName}
end tell
This is conservative, too - the old folder is in the Trash, not yet gone forever as it would be if you rm’d it.