Automator: Service to list File Paths of selected items, into Text File
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.
finder automator path
add a comment |
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.
finder automator path
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
– user3439894
Aug 27 '18 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.
– Winterflags
Aug 27 '18 at 18:46
add a comment |
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.
finder automator path
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.
finder automator path
finder automator path
edited Aug 27 '18 at 18:58
Winterflags
asked Aug 27 '18 at 18:14
WinterflagsWinterflags
2,212104273
2,212104273
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
– user3439894
Aug 27 '18 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.
– Winterflags
Aug 27 '18 at 18:46
add a comment |
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
– user3439894
Aug 27 '18 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.
– Winterflags
Aug 27 '18 at 18:46
4
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
– user3439894
Aug 27 '18 at 18:43
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
– user3439894
Aug 27 '18 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.
– Winterflags
Aug 27 '18 at 18:46
@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.
– Winterflags
Aug 27 '18 at 18:46
add a comment |
3 Answers
3
active
oldest
votes
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 foldersinFinder - Set Value of Variable
Inputs - Run Shell Script:
/usr/bin/dirname "$1"(make sure to pass inputas arguments) - Set Value of Variable
Parent Folder - Get Value of Variable
Inputs<-- this should not accept input (right-click on the action and selectIgnore 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:

+1 Like use of pure Automator. I myself am not too good at pure Automator
– JBis
Aug 27 '18 at 20:22
add a comment |
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(orCopy [#] Items as Pathnamesfor multiple files) in the context menuThe pathnames are now saved to your clipboard. You can paste them into Notes or a text file
2
Plus one- trivial hand work that does not need scripting
– fd0
Aug 27 '18 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.
– JBis
Aug 27 '18 at 20:21
add a comment |
Assuming you know how to create save and use a service menu item...

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
@user3439894 Finder sends the files to input
– JBis
Aug 27 '18 at 18:54
@user3439894 Oh I see now. Yes that's correct.
– JBis
Aug 27 '18 at 18:56
1
Change the second-to-last line totell application "Finder" to set myPath to (POSIX path of (get (container of (first item of input)) as text))and the last line todo 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
Aug 27 '18 at 19:02
@user3439894 can't fix now on mobile will fix later
– JBis
Aug 27 '18 at 20:19
@user3439894 Fixed :)
– JBis
Aug 27 '18 at 21:21
|
show 1 more comment
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "118"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fapple.stackexchange.com%2fquestions%2f334878%2fautomator-service-to-list-file-paths-of-selected-items-into-text-file%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
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 foldersinFinder - Set Value of Variable
Inputs - Run Shell Script:
/usr/bin/dirname "$1"(make sure to pass inputas arguments) - Set Value of Variable
Parent Folder - Get Value of Variable
Inputs<-- this should not accept input (right-click on the action and selectIgnore 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:

+1 Like use of pure Automator. I myself am not too good at pure Automator
– JBis
Aug 27 '18 at 20:22
add a comment |
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 foldersinFinder - Set Value of Variable
Inputs - Run Shell Script:
/usr/bin/dirname "$1"(make sure to pass inputas arguments) - Set Value of Variable
Parent Folder - Get Value of Variable
Inputs<-- this should not accept input (right-click on the action and selectIgnore 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:

+1 Like use of pure Automator. I myself am not too good at pure Automator
– JBis
Aug 27 '18 at 20:22
add a comment |
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 foldersinFinder - Set Value of Variable
Inputs - Run Shell Script:
/usr/bin/dirname "$1"(make sure to pass inputas arguments) - Set Value of Variable
Parent Folder - Get Value of Variable
Inputs<-- this should not accept input (right-click on the action and selectIgnore 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:

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 foldersinFinder - Set Value of Variable
Inputs - Run Shell Script:
/usr/bin/dirname "$1"(make sure to pass inputas arguments) - Set Value of Variable
Parent Folder - Get Value of Variable
Inputs<-- this should not accept input (right-click on the action and selectIgnore 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:

answered Aug 27 '18 at 18:51
aaplmathaaplmath
1,6921030
1,6921030
+1 Like use of pure Automator. I myself am not too good at pure Automator
– JBis
Aug 27 '18 at 20:22
add a comment |
+1 Like use of pure Automator. I myself am not too good at pure Automator
– JBis
Aug 27 '18 at 20:22
+1 Like use of pure Automator. I myself am not too good at pure Automator
– JBis
Aug 27 '18 at 20:22
+1 Like use of pure Automator. I myself am not too good at pure Automator
– JBis
Aug 27 '18 at 20:22
add a comment |
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(orCopy [#] Items as Pathnamesfor multiple files) in the context menuThe pathnames are now saved to your clipboard. You can paste them into Notes or a text file
2
Plus one- trivial hand work that does not need scripting
– fd0
Aug 27 '18 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.
– JBis
Aug 27 '18 at 20:21
add a comment |
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(orCopy [#] Items as Pathnamesfor multiple files) in the context menuThe pathnames are now saved to your clipboard. You can paste them into Notes or a text file
2
Plus one- trivial hand work that does not need scripting
– fd0
Aug 27 '18 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.
– JBis
Aug 27 '18 at 20:21
add a comment |
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(orCopy [#] Items as Pathnamesfor multiple files) in the context menuThe pathnames are now saved to your clipboard. You can paste them into Notes or a text file
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(orCopy [#] Items as Pathnamesfor multiple files) in the context menuThe pathnames are now saved to your clipboard. You can paste them into Notes or a text file
edited Aug 27 '18 at 19:17
aaplmath
1,6921030
1,6921030
answered Aug 27 '18 at 18:53
RuskesRuskes
37.6k540118
37.6k540118
2
Plus one- trivial hand work that does not need scripting
– fd0
Aug 27 '18 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.
– JBis
Aug 27 '18 at 20:21
add a comment |
2
Plus one- trivial hand work that does not need scripting
– fd0
Aug 27 '18 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.
– JBis
Aug 27 '18 at 20:21
2
2
Plus one- trivial hand work that does not need scripting
– fd0
Aug 27 '18 at 19:06
Plus one- trivial hand work that does not need scripting
– fd0
Aug 27 '18 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.
– JBis
Aug 27 '18 at 20:21
-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.
– JBis
Aug 27 '18 at 20:21
add a comment |
Assuming you know how to create save and use a service menu item...

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
@user3439894 Finder sends the files to input
– JBis
Aug 27 '18 at 18:54
@user3439894 Oh I see now. Yes that's correct.
– JBis
Aug 27 '18 at 18:56
1
Change the second-to-last line totell application "Finder" to set myPath to (POSIX path of (get (container of (first item of input)) as text))and the last line todo 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
Aug 27 '18 at 19:02
@user3439894 can't fix now on mobile will fix later
– JBis
Aug 27 '18 at 20:19
@user3439894 Fixed :)
– JBis
Aug 27 '18 at 21:21
|
show 1 more comment
Assuming you know how to create save and use a service menu item...

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
@user3439894 Finder sends the files to input
– JBis
Aug 27 '18 at 18:54
@user3439894 Oh I see now. Yes that's correct.
– JBis
Aug 27 '18 at 18:56
1
Change the second-to-last line totell application "Finder" to set myPath to (POSIX path of (get (container of (first item of input)) as text))and the last line todo 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
Aug 27 '18 at 19:02
@user3439894 can't fix now on mobile will fix later
– JBis
Aug 27 '18 at 20:19
@user3439894 Fixed :)
– JBis
Aug 27 '18 at 21:21
|
show 1 more comment
Assuming you know how to create save and use a service menu item...

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
Assuming you know how to create save and use a service menu item...

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
edited Aug 27 '18 at 21:21
answered Aug 27 '18 at 18:50
JBisJBis
5,77631451
5,77631451
@user3439894 Finder sends the files to input
– JBis
Aug 27 '18 at 18:54
@user3439894 Oh I see now. Yes that's correct.
– JBis
Aug 27 '18 at 18:56
1
Change the second-to-last line totell application "Finder" to set myPath to (POSIX path of (get (container of (first item of input)) as text))and the last line todo 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
Aug 27 '18 at 19:02
@user3439894 can't fix now on mobile will fix later
– JBis
Aug 27 '18 at 20:19
@user3439894 Fixed :)
– JBis
Aug 27 '18 at 21:21
|
show 1 more comment
@user3439894 Finder sends the files to input
– JBis
Aug 27 '18 at 18:54
@user3439894 Oh I see now. Yes that's correct.
– JBis
Aug 27 '18 at 18:56
1
Change the second-to-last line totell application "Finder" to set myPath to (POSIX path of (get (container of (first item of input)) as text))and the last line todo 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
Aug 27 '18 at 19:02
@user3439894 can't fix now on mobile will fix later
– JBis
Aug 27 '18 at 20:19
@user3439894 Fixed :)
– JBis
Aug 27 '18 at 21:21
@user3439894 Finder sends the files to input
– JBis
Aug 27 '18 at 18:54
@user3439894 Finder sends the files to input
– JBis
Aug 27 '18 at 18:54
@user3439894 Oh I see now. Yes that's correct.
– JBis
Aug 27 '18 at 18:56
@user3439894 Oh I see now. Yes that's correct.
– JBis
Aug 27 '18 at 18:56
1
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
Aug 27 '18 at 19:02
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
Aug 27 '18 at 19:02
@user3439894 can't fix now on mobile will fix later
– JBis
Aug 27 '18 at 20:19
@user3439894 can't fix now on mobile will fix later
– JBis
Aug 27 '18 at 20:19
@user3439894 Fixed :)
– JBis
Aug 27 '18 at 21:21
@user3439894 Fixed :)
– JBis
Aug 27 '18 at 21:21
|
show 1 more comment
Thanks for contributing an answer to Ask Different!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fapple.stackexchange.com%2fquestions%2f334878%2fautomator-service-to-list-file-paths-of-selected-items-into-text-file%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown


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
– user3439894
Aug 27 '18 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.
– Winterflags
Aug 27 '18 at 18:46