What is Best Practice for Handling Script Errors in Execute Script Action?

The reason I like to use the KM Action option to "return results to variable" is that it makes it easy, and less error prone, for the user to set the KM variable of their choice. There are many scripts that are general purpose, like choosing file and folder, and I think it is best for the user to not have to change the script to set a different KM variable.

Due to the nature of Keyboard Maestro, I don't think I'd write any process using it that is truly mission critical. Of course, Peter might disagree with me.

No, I think Peter would agree. KM meets a particular need, and meets it extremely well, but checking a heart monitor or giving a "Go/No Go" on a launch are probably not in its scope. :slight_smile:

First, @JMichaelTX thanks for sharing your template. I also appreciate the discussion regarding the pros and cons of each approach.

The V4.1 template works perfectly on my MacBook Pro 16" (Big Sur 11.3.1 using KM 9.2).

On my Mac mini (Late 2012) (Mojave 10.14.6 also using KM 9.2), however, the template returns:

~~~ VARIABLE from Script Results ~~~
objc[1049]: Class FIFinderSyncExtensionHost is implemented in both /System/Library/PrivateFrameworks/FinderKit.framework/Versions/A/FinderKit (0x7fff9d1323f0) and /System/Library/PrivateFrameworks/FileProvider.framework/OverrideBundles/FinderSyncCollaborationFileProviderOverride.bundle/Contents/MacOS/FinderSyncCollaborationFileProviderOverride (0x110386f50). One of the two will be used. Which one is undefined.
/Users/j/Desktop/

Note, if I copy the AppleScript code to the Script Editor, I get the expected:

~~~ VARIABLE from Script Results ~~~
/Users/j/Desktop/

Anybody know what might be causing this issue?

This is caused by the process that KM uses to run AppleScripts.
To fix, uncheck "Include Errors" in the Gear menu of that Execute AppleScript Action:

image

@JMichaelTX, the change you suggested (deselect Include Errors) indeed eliminated the information that preceded the file path. Thank you!

But now I'm curious:

  1. Presumably there is no error if a folder is successfully selected. If that presumption is correct, why is the information seen on my Mojave system?

  2. Why does the state of Include Errors have no consequence on my Big Sur system?

Those would be questions for @peternlewis.

1 Like

It is a warning the system puts out because Apple chose to implement a specific class, FIFinderSyncExtensionHost, in both of two different Apple Frameworks, both of which happen to be used in this process (indirectly, they are private frameworks so not used directly).

It is essentially an Apple bug, though hopefully harmless (assuming both implementations are identical, otherwise it could have interesting quirky bugs).

Presumably Apple resolved the bug between Mojave and Big Sur which is why you don't see it in Big Sur, thus no need to turn off “Include Errors” - note that Include Errors chooses whether the output of the script is just the stdout, or also includes stderr error stream.

2 Likes

@peternlewis, thanks for the thorough explanation. It surprises me that I hadn't previously encountered this issue.