Jump to content

Copy Paths to Clipboard (POSIX, HFS, '~/', quoted, etc)


Recommended Posts

copypaths_paths.png
 
 
Workflow for Alfred 2 to copy the paths of your current files and Documents to the clipboard in a variety of formats: 
 
* POSIX or HFS paths 
* '~/'-shortened POSIX paths
* quoted paths
* comma- or newline-separated.
 
Works as a scriptfilter that gives you feedback how your paths would be copied:
 
copypaths_s_q_n.png
 
All options (except newline-separation) are available as File Actions also:
 
copypaths_actions.png
 
More details in the README on github.
 
Download: http://cl.ly/YX1Q

 

 

Github: https://github.com/franzheidl/copy-paths-to-clipboard

Edited by franzheidl
Link to comment

Just updated the scriptfilter to work with paths containing non-ASCII/Unicode characters.

Use quoted option '-q' if you're copying for Terminal, otherwise Terminal won't understand such a path  :)

 

 

Pull from github or use updated download link above.

Link to comment
  • 3 months later...

Hi franzheidl,

 

I'm trying to simplify your script to only get the Posix. I created a new Alfred Workflow, running the Applescript to get the POSIX file path in your GIThub.

I have no idea why, but the result I get is always follow by a paragraph return

 

"/Applications/

"
 
instead of
"/Applications/"

 

Any clue why I have this behaviour?

 

Best

Link to comment
  • 3 weeks later...

Great workflow, thank you!

 

What I really would like to have the possibility to either only copy (the default setting you implemented) or additionally paste (what one can select by changing the "Copy to Clipboard" part of the workflow) - at the moment one has to decide between one of the two options.

 

Is that possible?!

Link to comment
  • 1 month later...

@Januz,

 

much appreciated.

 

So what you're after is 

 

1.) Copy path(s) –– by default POSIX

 

and then

 

2.) Paste the path and optionally have it converted just before pasting it in?

 

That should be possible, although to me that sounds a bit like an edge/corner case, I usually copy paths for a purpose and already know what format I need them to be.

 

Anyway, the problem is that you either can simply use Cmd-V to paste – then you'd need an additional intermediate step to modify the contents of the clipboard, OR you'd need to use an additional keyword for converting and pasting.

 

The first option doesn't sound too sensible to me, the second should be possible but is a bit of the reverse of what I wanted the workflow to be. To make that possible regardless of what application you want to paste in you'd need Applescript GUI scripting (à la "keystroke "V" using {command down}").

Link to comment
  • 5 months later...

Could you help with a minor modification? I'm trying to prepend "file://" to the regular file path output so that I can link to local files from Evernote and other programs.  When I open the "Copy to Clipboard" part of the workflow, it would seem I could do so by entering in file://{query}.  But that doesn't seem to work.  

 

I suppose an Applescript could do the same, but I'm not a script kiddie and would have to go Googling for a how to.

 

Could anyone help?

 

Screenshot%202014-05-30%2015.33.40.png

Link to comment

I'm no "script kiddy" by a long shot, but you can setup a workflow with a keyword linked to a /usr/bin/osascript. this would grab the system link and copy it to the clipboard.

 

 

 

the script is:

 

on path2url(thepath)
return do shell script "python -c \"import urllib, sys; print (urllib.quote(sys.argv[1]))\" " & quoted form of thepath
end path2url


tell application "Finder"
set sel to the selection as text
set the clipboard to "file://localhost" & my path2url(POSIX path of sel)
end tell

3AQLtbU.png?1

ewaMKlB.png

Link to comment
  • 1 month later...

Hi franzheidl, Thank you for the very handy workflow!   From your GitHub usage description:  "Invoke the scriptfilter by typing paths . . .  if you're in an other (document-based) application the path of your frontmost document will be copied."  I wonder if this workflow can be easily adapted to the following scenario.  Would it be possible to alter this workflow so that it could copy all of the paths of the open documents in an application?  Sometimes I end up with quite a few Word documents open.  I would like to be able to copy all of the paths of the open documents to the clipboard in one fell swoop so that I can then paste them into an omnioutliner file or store them in DEVONthink.  

 

Does anyone know how to do this or if there is already a workflow or script available that will do it?  Thanks again franzheidl for making your workflow available.  It is a time saver.

Link to comment
  • 3 months later...
  • 6 months later...

Just added an option to copy the path(s) of the current document(s) or Finder item(s) as a properly encoded file url.

 

paths-url.png

 

Also changed the hfs option to use '-hfs' (incl. the leading hyphen), and updated the icons.

 

GitHub: https://github.com/franzheidl/copy-paths-to-clipboard

 

Download: http://cl.ly/YX1Q

Is there a way I can delete options I don't want to use here?  For example, I want the file link option only.  I tried deleting items in the script and it just broke things:

 

Alfred%20Preferences%208n4jb.png.png

Link to comment
  • 2 years later...

Hi everyone, 

I am having a bit of trouble getting remote server paths via copy paths. The pattern "smb://servername_or_ip/path…" would be what I actually need. Can someone push me in the right direction, please… ;) How would I go about solving this? Until now I somehow always run in circles… Thanks in advance for any hints.

 

What I get with Copy Paths to Clipboard (also tried all other options):
/Volumes/path-to-whatever-file

 

Desired outcome: with File Information – copy & paste full path:
smb://servername/path-to-whatever-file

Link to comment
3 hours ago, patowod said:

I am having a bit of trouble getting remote server paths via copy paths

 

Well, that's kind of the whole point… The system makes network volumes look like normal, local volumes to applications.

 

You might be able to get the source of the volume using a command like df or system_profiler SPNetworkVolumeDataType.

Link to comment
  • 1 year later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...