Can automation service to get the parent folder path?

Solution 1:

Create a new Automator Service, with the following settings:

  • Service receives selected [files or folders] in [Finder]

Add a Run Shell Script action, with the following settings:

  • Shell [/bin/bash]               Pass input [as argument]

Replacing all of the default code with the example code below:

toTheClipboard="File Path: file://$(sed 's: :%20:g' <<< "$1") Parent Folder: file://$(dirname "$1" | sed 's: :%20:g')"
pbcopy<<<"$toTheClipboard"

Save the Automator Service, then in Finder, select an item and right-click selecting the service from the Services context menu. The service is also available from the Finder > Services menu.

You can then paste from the clipboard to wherever you want it.


Note: The example code is just that and does not employ any error handling and is meant only to show one of many ways accomplish a task. The onus is always upon the User to add/use appropriate error handling as needed/wanted.