Wednesday, July 28, 2021

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

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

Get the string from NSPasteboardNameFind

In this example we will return the string from NSPasteboardNameFind

Its pasteboard type of command+f or in english "Find..."
When we use that command we could search for a string in document. We could also return that
string from ASObjC.

So type anything in textfield of find command in any application, press done, run the script below.

ex.

Applescript:

use framework "Foundation"
use framework "AppKit"
use scripting additions

set pasteboardFind to current application's NSPasteboard's pasteboardWithName:(current application's NSPasteboardNameFind)
set rawData to (current application's NSString's alloc()'s initWithData:(pasteboardFind's dataForType:"public.utf8-plain-text") encoding:(current application's NSUTF8StringEncoding)) as text

Applescript:

use framework "Foundation"
use framework "AppKit"
use scripting additions

-- Set NSPasteboardNameFind
set theString to (display dialog "" default answer "")'s text returned
set pasteboardFind to current application's NSPasteboard's pasteboardWithName:(current application's NSPasteboardNameFind)
pasteboardFind's setString:(current application's NSString's stringWithString:theString) forType:"public.utf8-plain-text"

-- Get NSPasteboardNameFind
set rawData to (current application's NSString's alloc()'s initWithData:(pasteboardFind's dataForType:"public.utf8-plain-text") encoding:(current application's NSUTF8StringEncoding)) as text
-- Or
set thePasteboardFind to pasteboardFind's stringForType:"public.utf8-plain-text") as text

Last edited by Fredrik71 (2021-01-10 08:59:44 am)


if you are the expert, who will you call if its not your imagination.

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)