It may need to be modified for your use. I have not caught every error (for instance, when an action has no path, nothing happens, including no error).
ยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยท
ERROR!
ยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยท
Execute an AppleScript failed with script error: text-script:1532:1575: execution error: No Path was Found in the Selected Action! (-2700)
ยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยท
ยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยท
ERROR!
ยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยท
Execute an AppleScript failed with script error: text-script:1475:1505: execution error: Finder got an error: Handler canโt handle objects of this class. (-10010)
ยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยท
I haven't dug deeply into this, but is the following too much of a blunt instrument?
"For Each... the substrings matching" <string>(:?~/|/Users/)[^<]*, extracting the path with a regex search for <string>(.+) and append it to a variable? Then line-by-line through the variable revealing the items?
It does feel a little simplistic, but you never know!
PoC, in which I've targeted selected macros rather than actions, but the AS could easily be changed -- but I wanted to see if I could extract from multiple macros at once
Here's a complete script that does all the heavy lifting for you.
It works with selected actions, macros, or macro-groups.
Reveals in the Finder the the files/folders whose paths are found.
--------------------------------------------------------
# Auth: Christopher Stone <scriptmeister@thestoneforge.com>
# dCre: 2023/05/08 03:27
# dMod: 2023/05/08 04:05
# Appl: Keyboard Maestro Editor
# Task: Reveal in the Finder Items Whose Paths Are Listed in the Selected Items {Action(s), Macro(s), or Macro-Group(s)}.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @Keyboard_Maestro, @XML, @Selected, @Items, @Reveal, @Finder, @Path, @ASObjC
--------------------------------------------------------
use AppleScript version "2.4" --ยป Yosemite or later
use framework "Foundation"
use scripting additions
--------------------------------------------------------
property LF : linefeed
--------------------------------------------------------
set {oldTIDS, AppleScript's text item delimiters} to {AppleScript's text item delimiters, LF}
tell application "Keyboard Maestro"
set selectedItemList to selection
if selectedItemList โ {} then
repeat with theItem in selectedItemList
set contents of theItem to xml of theItem -- Extracting XML
end repeat
else
display notification "Nothing was selected in the Keyboard Maestro Editor!" with title "# Path Search #" subtitle "ยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยท" sound name "Tink"
return
end if
end tell
set selectedItemList to selectedItemList as text
set AppleScript's text item delimiters to oldTIDS
# selectedItemList can be used at this point and contains the XML of the selected items.
set foundPathList to my regexFindWithCapture:"(?m)<string>(~?/.+)</string>" fromString:selectedItemList resultTemplate:"$1"
set collatedFurlList to {}
if foundPathList โ {} then
repeat with thePath in foundPathList
set theFURL to (((current application's NSString's stringWithString:thePath)'s stringByStandardizingPath) as text) as ยซclass furlยป
if theFURL is not in collatedFurlList then
set end of collatedFurlList to theFURL
end if
end repeat
tell application "Finder"
activate
repeat with theFURL in collatedFurlList
reveal theFURL
end repeat
end tell
else
display notification "No Viable Path Strings Were Found!" with title "# Path Search #" subtitle "ยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยท" sound name "Tink"
end if
--------------------------------------------------------
--ยป HANDLERS
--------------------------------------------------------
on regexFindWithCapture:thePattern fromString:theString resultTemplate:templateStr
set theString to current application's NSString's stringWithString:theString
set theRegEx to current application's NSRegularExpression's regularExpressionWithPattern:thePattern options:0 |error|:(missing value)
set theFinds to theRegEx's matchesInString:theString options:0 range:{0, theString's |length|()}
set theResult to current application's NSMutableArray's array()
repeat with aFind in theFinds
set foundString to (theRegEx's replacementStringForResult:aFind inString:theString |offset|:0 template:templateStr)
(theResult's addObject:foundString)
end repeat
return theResult as list
end regexFindWithCapture:fromString:resultTemplate:
--------------------------------------------------------
Here's the part that extracts the XML if you want to play around with other methods of getting the paths.
--------------------------------------------------------
property LF : linefeed
--------------------------------------------------------
set {oldTIDS, AppleScript's text item delimiters} to {AppleScript's text item delimiters, LF}
tell application "Keyboard Maestro"
set selectedItemList to selection
if selectedItemList โ {} then
repeat with theItem in selectedItemList
set contents of theItem to xml of theItem -- Extracting XML
end repeat
else
display notification "Nothing was selected in the Keyboard Maestro Editor!" with title "# Path Search #" subtitle "ยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยท" sound name "Tink"
return
end if
end tell
set selectedItemList to selectedItemList as text
set AppleScript's text item delimiters to oldTIDS
return selectedItemList
Note the technique of reusing the selectedItemList in place to extract the XML. This is very fast and efficient.
This is very nice, thank you @ccstone and @Nige_S for demonstrating better ways to do this. I have added an action to reveal them in finder and will upgrade if you wind up addressing that in the script.
I appreciate the help! This will save me a lot of strain.
This is one of several reasons why I'd rather talk to the XML directly with JavaScript or AppleScriptObjC instead of parsing with RegEx. It makes certain kinds of filtering a whole lot easier.
However โ my understanding of XPath and the tools to utilize it are insufficient to tackle that modality at present โ so I'm stuck with the more painfully brute-force methods of RegEx.