I'm baffled by this. Any AppleScript which uses tell application "System Events"
runs slow only on 1 account of my Mac but fine on the other account.
Just as a simple example, tell application “System Events” to display dialog “Hello World”
displays the dialog almost instantly on account 1, but will take up to 6 or 7 seconds to display the dialog on account 2.
EDIT: Just to clarify, As user3439894 mentioned in the comment below. I understand that display dialog doesn't need to be called by System Events. This issue has nothing to do with display dialog. I'm using it as a simple example to demonstrate the issue. As I mention below ANY code I call inside system events is slow (eg. sent frontmost to true, click menu items, etc.).
Its only system event calls though. A simple display dialog “Hello World”
or any other code that does not involve system events will run fast on both accounts.
A few more notes:
- It's not just display dialogs in tell application "System Events", it's ANY code I attempt to run in tell system events (e.g. click menu items, set frontmost to true, ect.). I'm just using the display dialog as a simple example.
- The delay is actually inconsistent. For example, with the display dialog command, most of the time it takes about 6 or 7 seconds for the dialog to appear, but occasionally the dialog will appear instantly. Other times, the dialog will appear instantly but then clicking the "OK" button will cause a 6 or 7 second delay (with the beachball).
- Both accounts on same Mac are admin accounts.
- The delay occurs in script editor, osascript, or apple script applications.
I'm lost. Any ideas?
EDIT 2 - More clarifications based on comments:
I've been trouble shooting this for several days and at this point I'm fairly certain of the following:
This has NOTHING to do with my code or how I am calling the script. It also is not AppleScript in general, or the account being slow.
Scripts NOT involving
tell application "System Events"
run fine on both accounts. Both accounts are generally running fast.It's specifically
tell application "System Events"
on ONE account.tell application "System Events"
runs fine on one of my user accounts. The SAME exact script, called the EXACT same way is taking 6 to 7 even 10 seconds to run on the second user account on the same computer. Both accounts have admin access.
display dialog
is a part of Standard Additions and doesn't need to be, nor should it be, called by System Events! Simply usedisplay dialog "Hello World"
. Check it out in the Library in Script Editor: ⇧⌘Losascript
, and it occurs if I call the script directly on the command line (e.g.osascript /path/to/script.scpt
).tell application "System Events" to set quit delay to 0
. SE auto-quits after a short time; this will tell it to keep running indefinitely.