Automator Get Filename of Selected File

I'm trying to create a Service where I can select an individual file, right click, go to Services and tap Perm Delete using Automator - i.e.:

rm <path>

I've looked around and i just can't find how to get the file path of the selected file.

Can anyone help.

Thanks


The secret is in the pop up menu "Services receive selected" at the top of the dialog. Set this to "files or folders".

Then your Automator service will get passed the list of selected files and folders.

Now you just need to use them. Add a "Run Shell Script" action. The shell script can get passed the list as either arguments or via stdin. Given that you are unlikely to select enough files to cause problems in an argument string then select "as arguments" in the "Pass input:" pop up.

Matthieu is right - you should have a confirmation.

Everything will now look like this :-

enter image description here


Use a Run Shell Script action.

Select the /bin/sh shell and select pass input as argument

Add the code

for f in "$@"
do
    rm -rf "$f"
done

I would also suggestion using a Ask for confirmation action before running the script. You know for safety, since rm has no way back.