Jump to content

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
Posted

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);
}

 

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