One way of writing the ‘XPath’ pattern in the for ... in
clause is to build it up step by step, and watch what it returns.
The /
characters work as in POSIX file paths, with a special abbreviation for ‘any level’ which is double slash //
So, matching a key
node at any level of nesting:
//key
-->
{"Actions", "Conditions", "ConditionList", "ConditionListMatch", "ElseActions", "MacroActionType", "ThenActions", "DisplayKind", "HonourFailureSettings", "IncludeStdErr", "MacroActionType", "Path", "Text", "UseText", "Variable", "DisplayKind", "MacroActionType", "NotifyOnFailure", "Path", "StopOnFailure", "Variable", "DisplayKind", "MacroActionType", "Path", "Text", "Variable", "TimeOutAbortsMacro", "MacroActionType", "TimeOutAbortsMacro"}
Square-bracket filtering down to key nodes with text MacroActionType
at any level of nesting:
//key[text()='MacroActionType']
-->
{"MacroActionType", "MacroActionType", "MacroActionType", "MacroActionType", "MacroActionType"}
All nodes that are following siblings of key
nodes with the text MacroActionType
: (asterisk matches any node)
//key[text()='MacroActionType']/following-sibling::*
-->
{"IfThenElse", "ThenActions", "DisplayKindVariableHonourFailureSettingsIncludeStdErrMacroActionTypeExecuteAppleScriptPathText-- Script without a PATH --
set x to 1
UseTextVariableLocal__ScriptResultsDisplayKindVariableMacroActionTypeExecuteJavaScriptForAutomationNotifyOnFailurePath%Variable%DND__KM_Scripts_Folder%/Test JXA File.scptStopOnFailureVariableLocal__ScriptResultsDisplayKindVariableMacroActionTypeExecuteAppleScriptPath%Variable%DND__KM_Scripts_Folder%/Test 2 AppleScript File.scptText-- Script without a PATH --
set x to 1
VariableLocal__ScriptResults", "ExecuteAppleScript", "Path", "", "Text", "-- Script without a PATH --
set x to 1
", "UseText", "", "Variable", "Local__ScriptResults", "ExecuteJavaScriptForAutomation", "NotifyOnFailure", "", "Path", "%Variable%DND__KM_Scripts_Folder%/Test JXA File.scpt", "StopOnFailure", "", "Variable", "Local__ScriptResults", "ExecuteAppleScript", "Path", "%Variable%DND__KM_Scripts_Folder%/Test 2 AppleScript File.scpt", "Text", "-- Script without a PATH --
set x to 1
", "Variable", "Local__ScriptResults", "TimeOutAbortsMacro", "", "Group", "TimeOutAbortsMacro", ""}
Filtering those following siblings down to just any key
nodes with the text Path
:
//key[text()='MacroActionType']/following-sibling::key[text()='Path']
-->
{"Path", "Path", "Path"}
The first (one-based indexing [1]
) following sibling of each of these path nodes which has the name string
:
//key[text()='MacroActionType']/following-sibling::key[text()='Path']/following-sibling::string[1]
-->
{"", "%Variable%DND__KM_Scripts_Folder%/Test JXA File.scpt", "%Variable%DND__KM_Scripts_Folder%/Test 2 AppleScript File.scpt"}