I’d like to programmatically execute MacOS Services on text from within AppleScript. I’m comfortable with AppleScript, aware of Cocoa frameworks, and a total bungler with Objective-C. I’ve gotten far enough to guess that NSPerformService might be able to handle this, but have no idea how to implement it.
Anyone care to give me a boost?
Thanks,
Bryan
My guess is it should work something like this:
use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use framework "AppKit"
use scripting additions
set pb to current application's NSPasteboard's pasteboardWithUniqueName()
pb's clearContents()
pb's writeObjects:{"Some%20text"}
set theResult to current application's NSPerformService("Name of Action", pb)
pb's |types|()
set theArray to pb's readObjectsForClasses:{current application's NSString} options:(missing value)
set theString to theArray's firstObject() as text
But it’s not finding the service here.