Problems running AppleScripts simultaneously
Problems running AppleScripts simultaneously
- Subject: Problems running AppleScripts simultaneously
- From: "Jacopille, David" <email@hidden>
- Date: Fri, 24 May 2019 18:44:56 +0000
- Thread-topic: Problems running AppleScripts simultaneously
AppleScript gurus,
In the past year I've been running multiple AppleScripts on the same server and
have been encountering about a 10% failure rate when doing so. For years these
scripts have been rock solid, but for years it would have been rare to run
scripts at the same time because those were slower times.
I have 6 Mac Pros and 5 Mac Mini servers with 10.12.6 and same scripts and
Adobe apps. All have scheduled restarts every weekend. All exhibit the same
symptoms. I believe running multiple scripts driving any applications could
reproduce the symptoms if run intensely enough. But this is the most common
example:
Over the course of an hour on the same server I will run these Applescripts,
all written dynamically as .applescript text files with different parameters.
All script files run via osascript.
* 100 AppleScripts that drive Adobe InDesign… one at a time.
* also run 300 AppleScripts that drive Adobe Illustrator… also one at a
time.
10% failure rate:
* At no time will Illustrator be driven by more than one script. Nor
InDesign.
* But at least 95% of the time for an hour two AppleScripts will be running
simultaneously, each driving Illustrator and InDesign separately.
* All 400 of the above dynamically generated scripts are stored separately
and can be run later. None ever have syntactical issues. All will complete
successfully in a healthy environment.
* No script would ever have both Illustrator and InDesign tells.
* 0.1% of the script’s lines are tell “Finder” lines. This could result
two different AppleScripts driving the same app (the Finder) coincidentally at
the same time, but rarely.
0% failure rate:
If I isolate InDesign and its scripts to one server, and Illustrator and its
scripts to another server, and run exactly the same set of InDesign and
Illustrator scripts the failure rate drops to zero.
Symptoms:
1. AppleScript stderr from osascript returns "application is not running"
meaning that System Events does not think that the application that the
AppleScript is trying to drive is running. But it is running and seems to be
working fine from the UI… System Events just lost track of it somehow.
2. System Events seems deeply affected in all these cases. Script
Debugger's dictionary explorer mode fails in various ways when looking at
System Events depending on how hosed it is.
3. Both osascript -e ‘tell application “Adobe Illustrator” to quit’ and
osascript -e ‘tell application id “com.adobe.illustrator” to quit’ both fail
with ‘application is not running’ whether Illustrator is running or not.
Telling Illustrator to activate also returns ‘application is not running’
whether Illustrator was running or not.
4. Depending on how confused System Events is a ‘tell’ to any other random
application like ‘tell application “BBEdit” to activate’ may fail with
‘application is not running’. Or it may work.
Three things restore health, but don’t change the 10% failure rate… only 6-10
Illustrator and InDesign scripts can run before another anomaly is encountered:
1. Restarting the whole machine. Not a practical solution every few minutes.
2. Manually quitting the running Adobe apps and killing/restarting System
Events fixes restores the environment (98% of the time). Occasionally the
Finder also needs to be force quit. Also impractical.
3. Automated ‘recovery’ Perl scripts to kill Adobe and System Events. Since
AppleScript doesn’t work Adobe app has to be shut down with kill -15. This is
the most graceful kill type but may be harsher than a normal quit. Sometimes
the app does not restart in a healthy state. A loop that tests System Events +
Illustrator health has to often loop through a few cycles of kill and restart…
but it usually works.
Stuff I’ve tried:
1. System Events was in some cases not running, perhaps after a crash. I
set up a launchd plist to keep in running ‘no matter what’. That does keep it
running, but doesn’t help much.
2. I’ve tweaked the recovery script to clear Adobe caches, preferences,
etc.. Doesn’t help much… probably only in rare situations where Adobe caches
or prefs become corrupt which I don’t suspect is a frequent problem.
3. I’ve done super clean removals of all Adobe products, caches, preferences
using Adobe Cleaner software plus deleting 20 other locations via shell script.
And then super clean installs of just InDesign and Illustrator (latest 2018
version). Some servers seem to have a lower failure rate for a while. Others
not are not any better. Either way the failure rate returns to 10% immediately
or very soon.
4. Prayed to the Console god. Read the word of the Console day and night.
Puny Console god did not save me.
Bottom line:
Efforts at recovery scripts to restore a healthy environment quickly are not
100% reliable at doing so. Even when recovery works (usually) the failure rate
stays at 10% and another recovery is needed within a few minutes.
Is the problem any two AppleScripts running simultaneously are known to flummox
System Events sooner or later?
Is the rare cases where two AppleScripts might simultaneously be running a
‘tell application “Finder”…’ the source of chaos?
Is there any way to recover more gracefully?
Are there any scripting techniques that would be safer.
Any wisdom would be greatly appreciated.
Thank you,
David Jacopille
Boston Massachusetts
MFS Email system made the following annotation
---------------------------------------------------------------------------------------------------------------------------------------
This email communication and any attachments may contain proprietary,
confidential, or privileged information. If you are not the intended recipient,
you are hereby notified that you have received this email in error and that any
review, disclosure, dissemination, distribution or copying of it or its
contents is prohibited. The sender does not waive confidentiality or any
privilege by mistransmission. If you have received this email in error, please
notify the sender immediately, delete this email, and destroy all copies and
any attachments.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden