1

我在考虑将此语句用于 GUI 脚本的最佳方法是什么:

tell application "System Events"

有什么区别

tell application "System Events"
   tell process "Finder"
   -- do something with the GUI
   end tell
end tell

tell application "Finder"
   tell application "System Events"
   -- do something with the GUI
   end tell
end tell

此外,似乎“进程”语句可以访问 GUI,而应用程序不能。

4

2 回答 2

1

It seems like you answered your own question. The first example works and is correct, the second example does not work and should not be used.

于 2013-12-03T05:57:04.090 回答
0

如果你写

tell application "Finder"
  tell application "System Events"

  end tell
end tell

只要您需要“系统事件”告诉结构,您就需要保持“查找器”告诉结构打开。这可能会弄乱您的代码,并且如果多个应用程序具有冲突的命令,则可能会导致问题。

“系统事件”很少或从不与任何事情发生冲突,并且相对经常需要。有一个很长的“系统事件”告诉结构是有意义的,但有一个很长的“Finder”告诉结构是没有意义的。

无论您使用流程还是应用程序都与它无关。两者都可以访问 GUI 脚本,但您可能需要系统事件才能在控制 Finder 以外的应用程序时执行此操作。

于 2013-12-05T00:14:31.947 回答