List All Windows and Properties of App (KM8+)

MACRO: List All Windows and Window Properties of the Front Application


Version 1.0
Released 2017-12-25
Requires KM8+


DOWNLOAD:

List All Windows and Properties of App.kmmacros (19 KB)
Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.


# Use Cases

  1. Identify hidden or invisible Windows of an App
  2. Identify all objects being displayed by an app that are true macOS Windows
  3. Find out what Window Properties are being set

Note: Only true macOS Windows can be accessed by native KM Actions. However, AppleScript can access most any object on a window using UI scripting. If you don't find the object of interest using this tool, then you will need to use another tool that lists/identifies all objects on a Window.


# Example Output


# Related Macros/Scripts that You May Also be Interested In


REFERENCE:

This macro built based on this topic/post:

Topic Title: Window Information Tool
URL: Window Information Tools

Date: 2016-05-21
Author: @ccstone


ReleaseNotes

Author.@JMichaelTX

PURPOSE:

  • Display Properties for Each Window of an App

HOW TO USE:

  1. Activate any window of the app of interest
  2. 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. :wink:
      .
  • Assign a Trigger to this maro.
  • Move this macro to a Macro Group that is only Active when you need this Macro. In this case that is probably a Group with GLOBAL access.
  • ENABLE this Macro.
    .
  • REVIEW/CHANGE THE FOLLOWING MACRO ACTIONS:
    (all shown in the magenta color)
    • SET Name of App to Use (Default: FrontMost App)

REQUIRES:

  1. KM 8.0.2+
  • But it can be written in KM 7.3.1+
  • It is KM8 specific just because some of the Actions have changed to make things simpler, but equivalent Actions are available in KM 7.3.1.
    .
  1. macOS 10.11.6 (El Capitan)
  • KM 8 Requires Yosemite or later, so this macro will probably run on Yosemite, but I make no guarantees. :wink:

NOTICE: This macro/script is just an Example

  • It has had very limited testing.
  • You need to test further before using in a production environment.
  • It does not have extensive error checking/handling.
  • It may not be complete. It is provided as an example to show you one approach to solving a problem.

TAGS: @Windows @Properties @AppleScript

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

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.

Macro-Image


# AppleScript

Note: This particular script MUST be run as text in the KM Execute Script Action.

AppleScript Code
property ptyScriptName : "Get Windows & Properties of Selected App"
property ptyScriptVer : "2.1"
property ptyScriptDate : "2017-12-24"
property ptyScriptAuthor : "JMichaelTX" -- based on script by @ccstone

property LF : linefeed
property ptyDiv : "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"

# --------------------------------------------------------------------------------
## # NOTICE:  This Script MUST be run as TEXT in a KM Execute Script Action ###
#                  Otherwise, the property names returned are their class name
# --------------------------------------------------------------------------------

## # Requires Keyboard Maestro 8.0.3+ ###

set kmInst to system attribute "KMINSTANCE"

tell application "Keyboard Maestro Engine"
  set appName to getvariable "Local__appName" instance kmInst
end tell

set tempRec to {}
tell application "System Events"
  set winRec to properties of every window of application process appName
  
  set iW to 0
  repeat with i in winRec
    --- Each Item is Properties for ONE Window ---
    
    set iW to iW + 1
    --- Set Window Header/Title Output ---
    set end of tempRec to ptyDiv & ¬
      LF & "WINDOW #" & iW & "   " & subrole of i & "   " & title of i & LF & ptyDiv
    
    --- Add Contents of Properies ---
    set end of tempRec to contents of i
    
    --- Set END of Window List (used in KM RegEx ---
    set end of tempRec to "~~~ END ~~~"
  end repeat
end tell

return tempRec

5 Likes