转换成 Apple Events AppleScript [英] Translate into Apple Events AppleScript

查看:20
本文介绍了转换成 Apple Events AppleScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常简单的applescript:

I have an very simple applescript:

tell application "Opera"
   get URL of active tab of window 1
end tell

我想看看底层的 Apple Events.所以我在启用了这两个环境变量的情况下启动了它:

I want to see Apple Events underlying. So I have launched it with these two environment variables enabled:

export AEDebugSends=1;
export AEDebugReceives=1

现在我得到这个输出:

osascript browser.scpt 
{core,getd target='psn '[Opera] {----={form=prop,want=prop,seld=URL ,from={form=prop,want=prop,seld=acTa,from={form=indx,want=cwin,seld=1,from=NULL-impl}}}} attr:{csig=65536 returnID=15130}

我希望看到对此处定义的函数的调用:https://developer.apple.com/documentation/coreservices/apple_events?language=objc

I would expect to see calls to functions defined here: https://developer.apple.com/documentation/coreservices/apple_events?language=objc

我的最终目标是将 Applescript 翻译成 c 或 Obj-C 代码.

My final goal is to translate that Applescript into c or Obj-C code.

有人能帮我理解输出的含义吗?

Could someone help me to understand the meaning of the output?

提前致谢

推荐答案

希望看到对此处定义的函数的调用

would expect to see calls to functions defined here

好吧,别期待了.您拥有的是 Apple 事件本身,以 AEPrint 符号表示,如下所述:

Well, stop expecting that. What you have is the Apple event itself, expressed in AEPrint notation, as explained here:

https://developer.apple.com/library/archive/technotes/tn/tn2045.html

您可以使用它来构建相同的 Apple 事件,或者您可以使用更高级别的命令将其组成部分.但无论哪种方式,系统都不能为您编写代码!这就是 Apple 活动,由 AppleScript 为您打造.学习阅读 AEPrint 符号、学习 Apple 事件的结构、学习手工构建相同的 Apple 事件,这些都是你必须自己做的事情.

You can use that to construct the same Apple event, or you can form it in pieces using higher level commands. But either way, it is not up to the system to write your code for you! That is the Apple event, built for you by AppleScript. Learning to read AEPrint notation, learning the structure of an Apple event, learning to build the same Apple event by hand, is all something you must do yourself.

仅举一个您将使用的推理示例:

Just to give an example of the reasoning you will use:

  • 您的 Apple 活动以动词 coregetd 开头.这是 Apple 事件等价于 get(AppleScript 中的第一个单词),正如您通过查看应用程序的 SDEF 字典所了解的那样.

  • Your Apple event starts with the verb coregetd. That is the Apple event equivalent of get (the first word in your AppleScript), as you learn from looking in the application's SDEF dictionary.

好的,现在我们知道动词了;直接宾语是什么?它是一个 URL (注意空格,这些是四字母代码);那是相当于您的 URL 的 Apple 事件(同样,我们通过字典了解这一点).

OK, now we know the verb; what's the direct object? It's an URL  (note the space, these are four-letter codes); that is the Apple event equivalent of your URL (again, we learn this through the dictionary).

好的,但是什么URL?它是 acTaURL,也就是 active tab(同样,字典向我们展示了这种等效性).

OK, but what URL? It's the URL of the acTa, which is the active tab (again, the dictionary shows us this equivalence).

好的,但是acTa是什么?...

OK, but the acTa of what? ...

等等.以这种方式将 Apple 事件分解为属性、元素和对象说明符后,您可以通过 Carbon 或 Cocoa 命令再次构建它.

And so on. Once you have broken down the Apple event into properties and elements and objects specifiers in this way, you can build it up again through Carbon or Cocoa commands.

出于我无法理解的原因,您选择了一段很长的旅程.您已选择抛弃 AppleScript 符号的简单性并自己构建 Apple 事件.你选择了一条需要大量学习的漫长道路.没有捷径;运行时不会为您编写代码.最长的旅程从第一步开始.开始!

You have chosen, for reasons that escape me, to embark on a very long journey. You have elected to throw away the simplicity of AppleScript notation and construct an Apple event yourself. You have chosen a long road involving much learning. There is no shortcut; the runtime is not going to write your code for you. The longest journey begins with the first step. Begin!

这篇关于转换成 Apple Events AppleScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆