Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call Cocoa Methods from Applescript under OS X

In former OS X versions (pre 10.6) it was possible to call Cocoa methods via the "call method" command in applescript ("Applescript Studio"). E.g. this way: set theURL to "http://www.apple.com" set URLWithString to (call method "stringByAddingPercentEscapesUsingEncoding:" of theURL with parameter 30) The script interpreter in the "Applescript Editor" (10.6) does not understand the command "call method". - Is there an equivalent for "Applescript Editor" (10.6)?

like image 232
Nico Avatar asked Oct 13 '22 19:10

Nico


2 Answers

You can use "call method" in applescript. Apple gave that ability to Automator and we can access that ability from applescript by using the "Automator Runner" application. I just showed this to someone recently. See my post #4 here.

So to answer your question, just put your "call method" code inside a tell application "Automator Runner" tell block.

like image 60
regulus6633 Avatar answered Nov 01 '22 09:11

regulus6633


AppleScript Studio I thought was done in Xcode not AppleScript Editor. Code in AppleScript Editor can only be saved as scripts and the language is just plain AppleScript.

If you're doing this is Xcode, on 10.6, AppleScript Studio no longer exists. It's now AppleScript-Obj-C

I don't know an exact answer.. but...

If you take - (void)makeKeyAndOrderFront:(id)sender in AppleScript-Obj-C, if I have a property linked to a window in Xcode I just go: myWindowProperty's makeKeyAndOrderFront_(sender)

I hope this helped at least a bit!

like image 29
Seb Jachec Avatar answered Nov 01 '22 09:11

Seb Jachec