Thursday, February 25, 2021

#1 2021-01-09 08:12:28 am

Fredrik71
Member
Registered: 2019-10-23
Posts: 625

Lets do example with NSPasteboardNameDrag

Lets do example with NSPasteboard pasteboardWithName and NSPasteboardNameDrag

In this example we will use Finder item and drag that item to Terminal window. To perform
a drag action. If we check the pasteboard (NSPasteboardNameDrag) we will see it has
public.file-url

If we later perform command+c and command+v it will not effect NSPasteboardNameDrag.
In other words its possible to perform a drag action of item and later ask for the URL.
The drag could be a input URL for a function (handler).

We could check the inode from command-line
ex. ls -i <path_to_file> | awk '{print $1}'

Here is example code to test.

Applescript:

set pasteboardDrag to current application's NSPasteboard's pasteboardWithName:(current application's NSPasteboardNameDrag)
set rawData to (current application's NSString's alloc()'s initWithData:(pasteboardDrag's
dataForType:"public.file-url") encoding:(current application's NSUTF8StringEncoding)) as text
-- Get inode
log rawData
set theURL to (current application's |NSURL|'s URLFromPasteboard:pasteboardDrag) as «class furl»

Last edited by Fredrik71 (2021-01-09 08:14:31 am)


The purpose to study someone else art is not to add, its to make less more.

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)