In terminal, we can easily delete (or remove) a file or folder with the command “rm“. Coupled with the “-rf” flag, we can get the system to forcefully delete a file or folder without prompt. In this tutorial, I will show you how you can make use of this command, together with Automator, to add a “Delete” option to the context menu.
Open Automator and select “Services”.
At the top of the right pane, select “files or folders” in “Finder”.
On the left most pane, select “Utilities” and drag the “Ask for Confirmation” option to the workflow. Enter the message to show up in the confirmation dialog.
Next, drag “Run Shell Script” to the workflow. Change the “Pass input” field to “as arguments”.
Paste the following lines into the shell script body: 5. Lastly, save the service with the name “Delete”.
That’s it. Now when you right click on any file or folder, you should see a “Delete” option. Select it and it will delete the file/folder.
Binding a shortcut key to Delete file
An additional thing that you can do with this newly created “Delete” service is to bind a keyboard shortcut to it. You can then press the shortcut key to quickly delete the file.
In Finder, go to “Finder -> Services -> Services Preferences” in the menu bar. Locate the “Delete” option, click on it and select “Add shortcut”.
Once you have set your shortcut key, you can press it after you have selected the file(s) and it will delete the selected file(s). Enjoy!