Sunday, August 25, 2013

Using Automator to get the absolute path of the selected file or folder in Finder in OS X 10.8.4

This guide shows how you can add a contextual menu (i.e. right click menu) which copies the full path of the selected file or folder to the clipboard.

I often need to report to clients the list of files changed in a project manually. Unlike Windows Explorer or Nautilus in Linux, OS X's Finder requires multiple steps in order to retrieve the absolute path of the currently visible directory. Fortunately, Automator comes to the rescue.

These instructions applies to OS X 10.8.4

1) Open Automator.
2) Click 'Service' then click 'Choose'
3) At the top right, change the drop down lists so they look like :
Service receives selected 'files or folders' in 'Finder'
4) Click 'Utilities'. Drag 'Run Shell Script' to the workflow.
5) For 'Pass input', select 'as arguments'
In the text area, use these :
for f in "$@"
do
 echo "$f"
 # echo "'$f'"
done
6) Click 'Utilities'. Drag 'Copy to Clipboard' to the workflow. Drop it at position 2.
7) Click 'File', 'Save'.
8) Give it a name like 'Copy path'.
9) You will now have an entry called 'Copy path' in your Finder contextual menu i.e. the right click menu.