--------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2022/12/12 06:21
# dMod: 2022/12/12 06:21
# Appl: Keyboard Maestro
# Task: Change Selected Macro Groups App Affiliation to iCab.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @Keyboard_Maestro
--------------------------------------------------------
tell application "Keyboard Maestro"
# Selected Macro Group (you can get the macro group via other means as well).
set theMacroGroup to (get selection)'s item 1
tell theMacroGroup
set available application xml to getXML() of me
end tell
end tell
--------------------------------------------------------
--ยป HANDLERS
--------------------------------------------------------
on getXML()
return "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">
<plist version=\"1.0\">
<dict>
<key>Targeting</key>
<string>Included</string>
<key>TargetingApps</key>
<array>
<dict>
<key>BundleIdentifier</key>
<string>de.icab.iCab</string>
<key>Name</key>
<string>iCab</string>
<key>NewFile</key>
<string>/Applications/Applications_Chris/Internet_Apps/Web_Browser_Apps/iCab/iCab 6/iCab.app</string>
</dict>
</array>
</dict>
</plist>
"
end getXML
--------------------------------------------------------
"The next days" can sometimes last longer than expected
Based on Chris' script I wrote the attached one which toggles the macro's assigned application, in this case Keyboard Maestro.
I find it useful when working on the layout of a palette which is normally not assigned to KM.
I wanted to share โ maybe someone is interested โฆ
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
tell application "Keyboard Maestro"
set _mySelMacroGroups to selected macro groups
if _mySelMacroGroups is not {} then
repeat with i in _mySelMacroGroups
set _available_app_xml to available application xml of i
if _available_app_xml contains _targetApp then
set theString to _available_app_xml
set suchen to _targetApp & _deactivateAppKM as string
set ersetzen to _deactivateAppKM
tell me to set _new_available_app_xml to austauschen(suchen, ersetzen, theString)
tell i to set available application xml to _new_available_app_xml
else
set theString to _available_app_xml
set suchen to _deactivateAppKM
set ersetzen to _targetApp & _deactivateAppKM as string
tell me to set _new_available_app_xml to austauschen(suchen, ersetzen, theString)
tell i to set available application xml to _new_available_app_xml
end if
end repeat
end if
end tell
property _targetApp : " <dict>
<key>BundleIdentifier</key>
<string>com.stairways.keyboardmaestro.editor</string>
<key>Name</key>
<string>Keyboard Maestro</string>
<key>NewFile</key>
<string>/Applications/Keyboard Maestro.app</string>
</dict>
"
property _deactivateAppKM : " </array>
</dict>
</plist>
"
property _activateAppKM : " <dict>
<key>BundleIdentifier</key>
<string>com.stairways.keyboardmaestro.editor</string>
<key>Name</key>
<string>Keyboard Maestro</string>
<key>NewFile</key>
<string>/Applications/Keyboard Maestro.app</string>
</dict>
</array>
</dict>
</plist>
"
on austauschen(suchen, ersetzen, theString)
set olddelis to my text item delimiters
set my text item delimiters to (suchen)
tell me to set theList to (every text item of theString)
set x to theList
set my text item delimiters to (ersetzen)
set theString to theList as string
set my text item delimiters to olddelis
return theString
end austauschen