AppleScript Toolbox only clicks at certain locations which uses CoreGraphics set send an kCGEventLeftMouseDown event followed by an kCGEventLeftMouseUp event. If you want I can add support for an keydown before the click and keyup afterwards which for key modifiers shift, alt, control and command. I don’t think it too much work to add it to AST.
About System Events, I’ve been using that for all my AST click scripts. It works”just tested it a few minutes ago. Tried with the active application and it works as well. I think it works slightly faster with the application (but there is so little difference that there might not be one).
I’m not telling you this to debate, but just to gives you a heads up (maybe my computer is set up in a weird way).
But I think it’s better to use the active application instead of System Events?
Regarding the code, what would you put for multiple modifiers?
I can explain why it seem to work. To inject an osax in an remote application the end user needs to authorize the osax to allow this or the osax needs to be installed in /System/Library/ScriptingAdditions folder. To avoid weird errors I declared all commands in the osax to be “User” AppleEvents. That means when an command is used outside the current application context it will throw an error. Because this security feature is added in Mac OS 10.6 and for backward compatibility the same command will be executed in the current application context when this error occurs. So for you running the script it may seem like it works but in fact it doesn’t.
Let’s execute the following code:
tell application "System Events"
It works like a charm, right? No error and a nice click is performed. But let’s take a look at the log window:
[format]tell application “System Events”
→ error number -1708
→ error number -1708
→ error number -10004
tell application “Script Editor”
As expected the AST click command throws an error. The script is trying a second time and eventually it will try the same command in the current application context, which is in this case Script Editor. So while it may seems like System Events works for you in fact it doesn’t. So to avoid any errors it is better not to use system events because it’s unclear how long Apple will support this bounce back and one day your script won’t run and stops with error -1708.
With AST click there is another reason why I chose to let it bounce back to the current application context. The command is using CoreGraphics to perform the click and the click itself is in the global scope of your desktop with no regards to processes or applications. So even if I would add support for application context the command itself would still be performed in the global scope of your desktop. Adding support for application context would only led to more confusion so it’s more or less obvious not to support it.
No application context or current application to avoid those errors.