The only issue is that the animation takes about a second to complete. If you spam the trigger key too quickly, it may miss a trigger.
You said you wanted it to work with a specific app. I made it work with Keyboard Maestro Editor. You will have to try your specific app, which I don't have. So I couldn't test it for your app.
Basically, my idea was simply to try to activate the app using a menu item. Keyboard Maestro Editor has such a menu item. I'm not sure whether Scrivener has a menu item that brings it to full screen. You will have to look for one.
There might be other approaches to solve this issue. I will continue to ponder it.
Yes, that is the whole macro. I know, it's so simple it looks like it couldn't work, but it does! It's amazing!
Did you try it? It works with the KM Editor.
Your exact words were:
I would like to (un)minimize a specific window.
That's what I did. I made it work with a specific window. It's impossible for me to make it work with your specific window because I don't have your app. Therefore, you will have to take a minute to find a menu item in your app that brings your window to the front.
Oh well, if you are talking about apps with multiple sub-windows, AND you want this macro to work with ANY application, not a specific application, that's a different question. I'm not sure if macOS keeps track of "which window in each app was the last one displayed." BTT may have its own internal trackers for that, but KM is limited to public APIs in macOS.
I'm still pondering it. I have a few more tricks up my sleeve.
Remember, your code only works with a specific application, Scrivener. Your code does not work with "Any Application". I'm not sure that BTT would be able to do that.
Right. That means your BTT macro will work with a specific window with a specific name. That's exactly what my macro (above) does - it works with a specific program with a specific name - "Keyboard Maestro".
If you want to, you could make my macro work with Scrivener. All you have to do is find a menu item in Scrivener that activates Scrivener, and then modify my macro to activate that menu item. Of course I can't do that because I don't have Scrivener.
You see, the problem is that I don't have BTT. Therefore I misunderstood what your BTT program does. You said "Should be more or less self-explanatory" but in fact it was not self explanatory. I thought your BTT program did something different from what it does. I won't explain what I thought it did, because that won't help you.
Okay, now we are getting somewhere. Now that I understand what you want, I will reconsider.
What you really want is this:
I want a KM macro that searches for a window containing the string "X" in the frontmost app and that activates that window within that app.
I'm looking for a way to do this now. Remember, BTT is not bound to public APIs in macOS, while KM is. If BTT is using a private macOS API to achieve this, then KM won't be able to achieve it.
Also, you didn't say what you want the macro to do if there are two windows open with the same name. It's entirely possible that this could happen. (If you had mentioned this from the start, I probably would have understood the issue.)
Maybe in your specific case every window will have a unique name, but any solution I write will have to handle the case where two windows of the same name exist. Here's an example. This app has two windows open with the same name, "Test1".
My macro has to make a decision when two windows have the same name. I presume you don't care what my macro does, which means I can pick any of them at random.
By the way, I'm working on a solution, but it requires that your app be AppleScript-compatible. I think you said your app is Safari, which I suspect is AppleScript compatible. Are there any other apps besides Safari that you want it to work with? You should list the names of any apps you want this macro to work with, because if any of them are not AppleScript compatible, my solution will not work.
Also, my solution will not work if you are using multiple desktops, or spaces. I hope you aren't doing that.
What this macro does is save the name of every open window in a specific app (I may make it work with more apps in the future), into a KM global variable called Windows. Then it has all the information needed to activate the window.
The problem that I'm trying to resolve right now is how to convert an AppleScript list into a multi-line KM variable. I'm not very good with AppleScript, so this is taking a while.
Safari was just an example. The point is to be able to trigger the macro always, from any app, no matter how many desktops are open. You're telling me that KM probably can't do that. Then that's the way it is. That's one of the reasons why I use KM and BTT. Thank you very much for your efforts.
I'm willing to stop, but I'm halfway there. I'll try to finish my solution anyway. Although you seem to be saying that you want the solution to work with multiple desktops. That's a new requirement that I probably can't fix, because macOS doesn't provide public APIs for "spaces."
I see your window name contains emoji's. I have no idea if my macro will work with window names that contain emojis.