Open a window of an app that has string 'a. ' in its name

I would like to open a window that is active on my system but not in focus that has 'a. ' in its window name.

It will be editing a file that will have 'a. ' in its name. If the window is found, it should make it active, if not, switch to the next window that has 'a. ' in its name. Ideally I want this searching to be scoped to one app only. In my case this app is MindNode.

It should be essentially a variation of this macro I use :

open mindnode - vimrc.kmmacros (21.4 KB)

But since I don't know the exact name of the file opened, I can't do it. All I know is the file will always be prefixed with 'a. '

Thank you for any help.

Try this script in an Execute AppleScript Action. It should work for the frontmost app.

tell application "System Events"
  set frontmostApp to name of first item of (processes whose frontmost is true)
  tell process frontmostApp
    set oWin to first window whose name starts with "a."
    set value of attribute "AXMain" of oWin to true
  end tell
end tell

EDIT:  2017-08-18  7:20 PM CT

Just posted a macro with a more generalized script that supports the text in the window name that it contains, starts with, or ends with.

###[MACRO:   Make Window FrontMost Based on Name](
1 Like

This is amazing. :yellow_heart:

Thank you so much.

1 Like

Revised my above post.

Hey @JMichaelTX

Actually, my bad. Your applescript did not work.

I just tested it whilst still having my open file action there that points to that specific file in there.

The script is NOT designed to work with an Open File dialog is present.

I have tested it with BBEdit and Evernote, and it works fine for me.

If you are using the script with another macro, please post your macro, so we can review.

I was thinking of using it like this :

open mindnode - working project.kmmacros (27.3 KB)

But not fully sure how to get the macro working even from the instructions.

Your macro works fine for me, when I make these changes:

  1. Use BBEdit as the app
  • Disable the Prompt for Input
  • Enable the two Set Variables
  • Enter "a." for MWF__WinName variable

BBEdit has three windows:

From my instructions on the macro page:

    (all shown in the magenta color)
    • GRP: Enable the Actions you Want for Input
      • Prompt for User Input
      • Set Variables for WinName, PosInName

Is that clear to you? If not let me know how to change.

Just tried that.

Here is the macro I used :

open mindnode - working project.kmmacros (27.3 KB)

However it says it cannot find such window and throws an error

Although that window of that app with a. in its file name certainly exists :

This app searches over names of active windows. As you can see 'a. ' is there.

Can you show me a screenshot of the mindnode Window menu, like this one for BBEdit, that shows a list of windows open in that app:

Also, when you get the notification popup that the window can't be found, can you do a screenshot of a larger region that includes the mindnode app?

Do you have any special dialog or popup windows showing in mindnode when you trigger the macro?

Here is the screenshot of window menu bar of the app :

What do you mean larger area? This script is supposed to be ran when the current active window is not MindNode and does not have 'a. ' in its name. For example here is what I get running this script from KM editor :

When I run it in MindNode, it actually switches correctly.

Perhaps I can do an if check before that script, if not in MindNode, switch to it, then run the script, if in MindNode, just run the script.

Or is there a better way?

It seems your script only searches for windows local to the app currently active, not globally.

That's not what you stated above:

I'm not clear on your workflow or requirements.

My script/macro is designed to search ONLY in the FRONTMOST app for a window whose name contains/starts with/ends with user supplied text. If it finds a window that meets that criteria, it makes it the frontmost window of that app.

If MindNode is NOT the frontmost app, then you need to Activate it first, before you call my script.

If you need something different, then please provide your complete workflow.

1 Like

This macro works really well.

open mindnode - working project.kmmacros (29.6 KB)

Thank you @JMichaelTX

I will use your script it other scenarios too, it's pretty handy.

OK, great! Glad you got it working. :smile: