Jump to content
franzheidl

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

Share this post


Link to post

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.

Share this post


Link to post

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

Share this post


Link to post

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?!

Share this post


Link to post

@JolinM,

 

not sure If I fully understand what you're trying to accomplish – POSIX is the default path format anyway?

 

Also not sure why you're getting the newline behaviour (if it is what you're on about), if I run it standalone it works just fine here. 

Share this post


Link to post

@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}").

Share this post


Link to post

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

Share this post


Link to post

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

Share this post


Link to post

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.

Share this post


Link to post

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

Share this post


Link to post

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

Share this post


Link to post
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.

Share this post


Link to post

@franzheidl Thanks for sharing your workflow! It's great, and I use it quite a bit.

 

It's not a big deal, but I wanted to give you heads up that the "Copy file URL to Clipboard" action doesn't appear to work with filenames that contain a comma.

 

Thanks again for posting this workflow!

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...