如何在 OS X 下从 Applescript 调用 Cocoa 方法
在以前的 OS X 版本(10.6 之前)中,可以通过 applescript(“Applescript Studio”)中的“call method”命令调用 Cocoa 方法。 例如这样: <代码> 将 URL 设置为“http://www.apple.com” 将 URLWithString 设置为(使用参数 30 调用 theURL 的“stringByAddingPercentEscapesUsingEncoding:”方法) “Applescript 编辑器”(10.6) 中的脚本解释器不理解命令“call method”。 - 是否有“Applescript Editor”(10.6)的等效项?
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)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以在applescript中使用“调用方法”。 Apple 为 Automator 提供了这种能力,我们可以使用“Automator Runner”应用程序从 applescript 访问该能力。我最近刚刚向某人展示过这个。请参阅我的帖子 #4 此处。
因此,要回答您的问题,只需将您的“调用方法”代码放入 tell 应用程序“Automator Runner”tell 块中即可。
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.
AppleScript Studio 我认为是在 Xcode 中完成的,而不是 AppleScript Editor。 AppleScript Editor 中的代码只能保存为脚本,并且语言只是普通的AppleScript。
如果您在 Xcode 中执行此操作,则在 10.6 上,AppleScript Studio 不再存在。现在是 AppleScript-Obj-C
我不知道确切的答案..但是...
如果您在 AppleScript-Obj- 中采用
- (void)makeKeyAndOrderFront:(id)sender
C,如果我有一个链接到 Xcode 中窗口的属性,我只需执行:myWindowProperty's makeKeyAndOrderFront_(sender)
我希望这至少有一点帮助!
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!