3

How can this Automator Service for Finder be created?

  • I'd like to be able to use Finder's Context menu (by right-clicking a Finder item) to run a Service that gets the file paths of the selected files.
  • The paths should be entered into a Text File (which can be unsaved or saved in the current folder).

Furthermore:

  • I currently only need to be able to get the paths of multiple selected files – but not the paths of subfolder contents, etc. I hope that serves not to overcomplicate things.

  • I would prefer if the filenames don't have Escaping Spaces ("Like\ This"), but instead normal spaces – but if there's a setting for that, I'd like how to alter between the modes within the script.

2
  • 4
    You can get the pathnames in Finder after selecting the items, right-click and then press the option key. Copy n Items changes to: Copy n Items as Pathnames Commented Aug 27, 2018 at 18:43
  • @user3439894 Wow, had no idea, thanks! I guess I can't accept it as an answer, as it's the right answer to the wrong question. But this is the solution I was looking for.
    – P A N
    Commented Aug 27, 2018 at 18:46

3 Answers 3

4

If you're looking for something that's more "pure Automator," here's one option (although, as was mentioned in the comments, right-clicking on the items in Finder, holding option, and selecting Copy Items as Pathnames is probably the easiest solution):

  • Accepts files or folders in Finder
  • Set Value of Variable Inputs
  • Run Shell Script: /usr/bin/dirname "$1" (make sure to pass input as arguments)
  • Set Value of Variable Parent Folder
  • Get Value of Variable Inputs <-- this should not accept input (right-click on the action and select Ignore Input)
  • New Text File (Plain text, [whatever file name you want], Parent Folder (drag this in from the variables list))

I've included a screenshot below:

Screenshot of Service

1
  • +1 Like use of pure Automator. I myself am not too good at pure Automator Commented Aug 27, 2018 at 20:22
3

No script is needed, as this is already built into Finder (this works for one or multiple files):

  • Right click on the file(s) in Finder

  • Press and hold option

  • Select Copy [file name] as Pathname (or Copy [#] Items as Pathnames for multiple files) in the context menu

  • The pathnames are now saved to your clipboard. You can paste them into Notes or a text file

2
  • 2
    Plus one- trivial hand work that does not need scripting
    – fd0
    Commented Aug 27, 2018 at 19:06
  • -1 The OP is new to Automator. Providing a scripting alternative would allow them to learn. This solution while correct, does not answer the OPs question entirely. Commented Aug 27, 2018 at 20:21
1

Assuming you know how to create save and use a service menu item...

![enter image description here

Script

on run {input, parameters}
    set myExport to ""
    repeat with x in input
        set myExport to myExport & the POSIX path of x & return
    end repeat
    tell application "Finder" to set myPath to (POSIX path of (get (container of (first item of input)) as text))
    do shell script "echo " & the quoted form of myExport & " > " & the quoted form of (myPath & "/file_list.txt")
end run
6
  • @user3439894 Finder sends the files to input Commented Aug 27, 2018 at 18:54
  • @user3439894 Oh I see now. Yes that's correct. Commented Aug 27, 2018 at 18:56
  • 1
    Change the second-to-last line to tell application "Finder" to set myPath to (POSIX path of (get (container of (first item of input)) as text)) and the last line to do shell script "echo " & the quoted form of myExport & " > " & the quoted form of (myPath & "/file_list.txt") and it'll work if the first item isn't a directory. N.B.: There's probably a cleaner way to accomplish this.
    – aaplmath
    Commented Aug 27, 2018 at 19:02
  • @user3439894 can't fix now on mobile will fix later Commented Aug 27, 2018 at 20:19
  • @user3439894 Fixed :) Commented Aug 27, 2018 at 21:21

You must log in to answer this question.

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