Renaming the Application and Applescript Errors
I have recently upgraded to CaptureOne v16.3 and shortly discovered that most of my scripts were throwing errors when I ran them from the Capture One Scripts menu, but not if I ran them standalone or from Script Editor.
On further investigation I discovered this was because I had renamed the Application (to Capture One 16.3) and that this commonly used Applescript expression to bring application windows to the front was the source of the error.
Tell application "system events" to set frontmost of application process (get name of current application) to true
Why this happened
An Applescript application has several associated names that are not directly linked.
The application's name, e.g. used in tell application "Capture One", and obtained from get name of current application, is taken from the name of the application file.
The name of the application's process, an element of System Events, is not linked to the application's file name. I think it is linked to the plist.info file within application's content folder. (for the uninitiated, using Finder select the application file, then right click and select "show package contents")
Typically a vendor will install their application with the filename matching the name of the application's process, so that these names are the same although not directly linked.
When I renamed the application file, the application name became "Capture One 16.3", but the application process was still "Capture One". The Applescript expression above failed because System events does not have an application process "Capture One 16.3"
Workarounds
Both of these workarounds work for any application that I have tried, including renamed and not renamed Capture One versions
The most direct approach is to search the applicationsprocesses for an application with the file name given by the current application. The Applescript expression is a little tricky, the "its" in "its file's name" is critical and not obvious.
set currentFileName to (get name of current application) & ".app"
tell application "System Events" to set frontmost of first application process whose (its background only is false) and (its file's name is currentFileName) to true
Another solution is based on the observation that the Application's properties contains the process name in the "name" element. However, just executing "get name of current application" or "get name of application (get name of current application) just gets you the application's file name.
However this one line expression does get and use the process name from the application's properties
tell application "System Events" to set frontmost of application process (get name of (get my application (get name of current application)'s properties)) to true
However, Capture One's properties includes alist of all the variants in the current collection
As this results in a download of Capture One's properties, it can take a longer time if Capture One's current collection has a large number of variants. The execution time with my M1Max Mac Studio is about 100 milliseconds for 5000 variants, about the same as the first workaround. However, with say 50,000 variants on an older Intel based Mac the execution time could be really obnoxious.
-
Have you submitted a support request for this? I would report it.
0 -
I think CaptureOne should not change the behaviour of their applications.
I have checked a few other applications and found that their behaviour on renaming is the as Capture One. If Capture One changes its behaviour, it becomes the exception, which could also lead to confusion and might well break something else.
Conisdering that the group of users that wrtes applications for general use is fairly small, and that the work arounds are not difficult once you know what they are - the same ends could be acheived just by adding an app note in the knowledge base.
0
Post is closed for comments.
Comments
2 comments