Jump to content
Alan He

How to get coppied file's path

Recommended Posts

Posted (edited)

When I select a pic , and ⌘ C, I will get file's name, but I need copied path.

 

Because I will scp the file to my vps.

 

 

When I operate like the following .I will get query ,but it's just filename

 

image.png.1383a6945c60c5445842d5224d7850ab.png

 

Edited by Alan He

Share this post


Link to post

Then you'll need to access the pasteboard yourself to retrieve the path.

 

When you copy an image file, the OS puts a bunch of formats on the pasteboard, including the image data, its path, its URL and a text representation. The text representation, which is what Alfred passes to workflows because it can only pass text, is just the filename.

 

The following JXA script should return the path of a file you've copied in Finder:

ObjC.import('AppKit');

function run() {
	// Get file URL from pasteboard
	let url = ObjC.unwrap($.NSPasteboard.generalPasteboard.stringForType('public.file-url'));
	// Decode URI and strip file:// prefix
	return decodeURI(url).substring(7);
}

 

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...