Detect How Many Preview.app Windows Are Open?

how can i know that how many Preview App Window be opened ? So I can manipulate the window position base on the opened windows numbers.
Thanks

how many

don't know specific number

do you need to Tile them?

Use the WINDOWCOUNT() function, maybe?

yes,count the preview windows, tile them in different position base on how many counts

is the WINDOWCOUNT() can calculate the specific application ? like Preview App

1 Like

If you look at the wiki page https://wiki.keyboardmaestro.com/function/WINDOWCOUNT you’ll see it works for whatever app is at the front.

1 Like

Hey Somyan,

Preview is AppleScriptable, so you can talk to it directly:

tell application "Preview"
   set winCount to count of windows
   return winCount
end tell

For unscriptable apps you can use System Events UI-Scripting:

tell application "System Events"
   tell application process "Preview"
      set winCount to count of windows
      return winCount
   end tell
end tell

Run from an Execute an AppleScript action.

-Chris

As @tiffle said, it works on the FRONT MOST app.

image

If you do a Forum search on "windows" you will find many examples.
Search in the Macro Library to find macros others have written.

1 Like

How do you access the result of the AppleScript from keyboard maestro?