###MACRO: Make Window FrontMost Based on Name
~~~ VER: 1.0 2017-08-18 ~~~
####DOWNLOAD:
Make Window FrontMost Based on Name.kmmacros (8.4 KB)
Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.
###Use Case
- Bring a App Window FrontMost based on its name
###ReleaseNotes
Author.@JMichaelTX
PURPOSE:
-
Make App Window FrontMost Based on Its Name
- Contains, Starts With, OR Ends With
HOW TO USE:
- Make the App of Interest FrontMost
- Trigger this Macro
MACRO SETUP
-
Carefully review the Release Notes and the Macro Actions
- Make sure you understand what the Macro will do.
- You are responsible for running the Macro, not me.
.
- Assign a Trigger to this maro.
- Move this macro to a Macro Group that is only Active when you need this Macro.
- ENABLE this Macro.
. -
REVIEW/CHANGE THE FOLLOWING MACRO ACTIONS:
(all shown in the magenta color)- GRP: Enable the Actions you Want for Input
- Prompt for User Input
OR - Set Variables for WinName, PosInName
- Prompt for User Input
- GRP: Enable the Actions you Want for Input
TAGS: @Windows @FrontMost @UI
USER SETTINGS:
- Any Action in magenta color is designed to be changed by end-user
ACTION COLOR CODES
- To facilitate the reading, customizing, and maintenance of this macro,
key Actions are colored as follows: - GREEN -- Key Comments designed to highlight main sections of macro
- MAGENTA -- Actions designed to be customized by user
- YELLOW -- Primary Actions (usually the main purpose of the macro)
- ORANGE -- Actions that permanently destroy Variables or Clipboards,
OR IF/THEN and PAUSE Actions
REQUIRES:
- Keyboard Maestro Ver 7.3+ (don't even ask me about KM 6 support).
- El Capitan 10.11.6+
- It make work with Yosemite, but I make no guarantees.
USE AT YOUR OWN RISK
- While I have given this limited testing, and to the best of my knowledge will do no harm, I cannot guarantee it.
- If you have any doubts or questions:
- Ask first
- Turn on the KM Debugger from the KM Status Menu, and step through the macro, making sure you understand what it is doing with each Action.
###AppleScript
property ptyScriptName : "Make App Window FrontMost Based on Name"
property ptyScriptVer : "1.2"
property ptyScriptDate : "2017-08-18"
property ptyScriptAuthor : "JMichaelTX"
(*
===============================================================================
REQUIRES:
• KM Variables:
• MWF__WinName
* MWF__PosInName
Local: /Users/Shared/Dropbox/SW/DEV/KM/Scripts/Make @Window @FrontMost Based on Name @UI @KM @AS.scpt
===============================================================================
*)
property LF : linefeed
set scriptResults to "TBD"
try
--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
set frontApp to path to frontmost application as text -- use for dialogs
tell application "Keyboard Maestro Engine"
set winNamePartial to getvariable "MWF__WinName"
set posInName to getvariable "MWF__PosInName"
end tell
tell application "System Events"
set frontmostApp to name of first item of (processes whose frontmost is true)
tell process frontmostApp
if (posInName = "starts with") then
set oWin to first window whose name starts with winNamePartial
else if (posInName = "ends with") then
set oWin to first window whose name ends with winNamePartial
else
set oWin to first window whose name contains winNamePartial
end if
set value of attribute "AXMain" of oWin to true
end tell
end tell
set scriptResults to "OK"
--~~~~~~~~~~~~~ END TRY ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
on error errMsg number errNum
if errNum = -128 then ## User Canceled
set errMsg to "[USER_CANCELED]"
end if
if errNum = -1719 then
set msgStr to "Window Could NOT be Found Whose Name " & LF & ¬
posInName & " \"" & winNamePartial & "\""
set msgTitleStr to ptyScriptName
display notification msgStr with title msgTitleStr sound name "Basso.aiff"
end if
set scriptResults to "[ERROR]" & return & errMsg & return & return ¬
& "SCRIPT: " & ptyScriptName & " Ver: " & ptyScriptVer & return ¬
& "Error Number: " & errNum
end try
--~~~~~~~~~~~~~~~~END ON ERROR ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
return scriptResults