I was thinking about what is the best way to use this statement for GUI Scripting:

tell application "System Events"

There is any difference with

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

and

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

Moreover It seems that "process" statement can access the GUI while application one can't.

有帮助吗?

解决方案 2

If you write

tell application "Finder"
  tell application "System Events"

  end tell
end tell

you need to keep the "Finder" tell structure open for as long as you need the "System Events" tell structure. This might mess up your code and it could cause problems if multiple apps have conflicting commands.

"System Events" rarely or never conflicts with anything and is needed relatively often. It makes sense to have a very long "System Events" tell structure but it doesn't make sense to have a very long "Finder" tell structure.

Whether you use process or application has nothing to do with it. Both can access GUI scripting, but you may need System Events to do this while controlling an app other than Finder.

其他提示

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top