Translate into Apple Events AppleScript

北慕城南 提交于 2020-01-06 08:26:29

问题


I have an very simple applescript:

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

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

export AEDebugSends=1;
export AEDebugReceives=1

Now I am getting this output:

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}

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

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?

Thanks in advance


回答1:


would expect to see calls to functions defined here

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

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:

  • 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.

  • 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).

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

  • OK, but the acTa of what? ...

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.

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!



来源:https://stackoverflow.com/questions/53638803/translate-into-apple-events-applescript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!