2

I already have a service that will create a network file:/// link to a share point over AFP but I would like to have one that does the parent folder of a file.

If I right click a file I would like to have the option to either choose to copy the file path to the file or the files parent folder.

I would prefer that the script be in Shell / bash and not in AppleScript and my dream scenario would be a way to copy both the file path and file path parent folder to the clipboard. Then when I pasted it would look like this:

File Path: file:///Volume/parentfolder/file.pdf Parent Folder: file:///Volume/parentfolder

Preferably I would like to obtain four lines of text in the clipboard in one action, but the second half (parent folder) is the one I lack currently.

  • @bmike, I fail to see how you interpreted the OP to where you changed the last paragraph to include "Preferably I would like to obtain four lines of text in the clipboard in one action" when what I see shown is one line of text, i.e. File Path: file:///Volume/parentfolder/file.pdf Parent Folder: file:///Volume/parentfolder, so am I missing something or have you misinterpreted something? Thanks. – user3439894 Mar 3 '18 at 2:51
  • Yes. I may have done a bad edit @user3439894 - can you fix it? – bmike Mar 3 '18 at 3:31
2

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.

  • This is perfect except I would need the spaces to be replaced with %20 so they can be correctly linked. Im going to try some digging to see if I can figure it out. – Brave_Buffalo Mar 5 '18 at 18:55
  • I tried but ive been unsuccessful in trying to remove the spaces in the text generated with %20. I would really appreciate an update to the code you provided without the spaces. Thank you so much! – Brave_Buffalo Mar 5 '18 at 19:30
  • @Brave_Buffalo, I've updated it to replace spaces with %20. – user3439894 Mar 5 '18 at 21:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .