Not sure if this will be apple script but is there a way to create an "if" argument. Example. When I unlock my screen, run this macro and open this application. If the application is already running, do nothing.
Thanks. I'm new to Maestro.
Not sure if this will be apple script but is there a way to create an "if" argument. Example. When I unlock my screen, run this macro and open this application. If the application is already running, do nothing.
Thanks. I'm new to Maestro.
Hi, @Moe; welcome to Keyboard Maestro and the forum.
When I see someone new to the forum, I like to share a few links that are helpful:
Check out these actions:
Do nothing? Hmm, what do you want if the application is already running but is not the front application? And what do you want if the application is the front application but all the windows are hidden? Based on your words "do nothing", it won't even be brought to the front. Is that what you want, for the application to remain in the background?
Depending on your answers. the following macro may be sufficient: (I'm going to assume the app is "Maps" but you can change that.)
Thank you both for your input.
By do nothing I mean, don't re-run the script again. I lock my computer multiple times a day but I leave the app I want open. When done for the day I ALWAYS close the app, but the next day I forget to open it up and then 2 hours later I remember to do something and I should have looked at that app as soon as I unlocked. ADHD is no joke so having it open when I first start for the day makes me focus on the tasks at hand. It does not have to be forefront. I always see is as I have 34" screens and during the day I do have timers on some of the tasks that show up. I'm going to mark these as both closed if I can because I can do both of your replies. Thank you again. Totally appreciate it.
Okay, then try creating this macro. Replace the name "Maps" with your preferred app.
You will notice that I have two "Pause" actions. In some cases (for some apps) these pauses may not be needed, but since I can't test your app, because I don't know what your app is, I am leaving these pauses there. You are free to delete them if you test this macro and decide that they don't do anything.
But now that I've written this, I see a potential problem. You said "when I unlock my screen" but I have a feeling that what you actually meant was "when I log into my Mac." If so, my macro will need a small change. Unlocking and Logging-In are very different things.
Wow. I was close. However, I will tell you that when I do Activate, the app opens but minimizes to the dock. But I see see that if I use "Open" the triangle says it's better to use activate but not sure why it's minimizing. You've been helpful so if I need to read some more I will.
I figured this out. If I close the app while it's minimized, when it opens up, it minimizes itself for whatever reason, but if I close the app while it's fully open and the window shows, it will open and won't minimize after unlocking. This doesn't happen with all app so not sure why this app (which is "Trello"). I'm sure I can find a way around this so thank you again.
It sounds like you solved your problem, but I'm still going to post this message that I drafted...
MacOS is like this. An app is still "at the front" if you can see the name of the app on the System Menu bar at the upper left of the screen. All of its menu items are still visible, so it really is "at the front".
I suspected this might be a problem, so I asked you what should happen if the windows are hidden. You said do nothing. So that's what I did. Now it sounds like you want something else. If you want something else, I may be able to help, but then you may have to tell me what your app is, because many apps behave differently.
Bear in mind that in macOS an app and all its menus can be frontmost even when all of the apps windows are minimized. This is different from Windows.
You used the phrase "the app minimizes." That's not correct. Apps can be hidden, but they cannot be minimized. For example, in a macOS menu, the Minimize menu item appears only under the Windows Menu, and not under the application's menu name. Check it out. The word "minimize" applies only to windows, not apps.
Here's an example of my claims with one app, Safari:
And here's where the word "Minimize" is used in Safari:
As you can see, windows can be minimized, but not apps. Apps can be hidden, or apps can be placed behind other windows owned by other apps, but they can't be minimized.
Yes forgive me. I work in a windows environment all day long and forget to change the terminology when dealing with mac.
I've attached a small video. The video will clear up once you start playing it. It's always easier to show you then explain it. FYI I started all over again with my initial creation but this happened when I scratched it and wrote out your macro. As you will see, Trello opens in a window. When I hit the yellow minus sign, it animates itself to the dock. I then right click and close it. When I execute the trigger again, it opens the app but then animates it immediately to the dock. When I click the dock icon to open it up, and then hit the red X, then right click the icon and close it, then run the macro again, it opens it back up in a window. Something about the red versus the yellow button. I gave it a 5 second pause just to see if I was trying to activate Trelllo to fast before it completely opened. I actually don't need any extra criteria after the open trello part if I use the red X. Problem is, I always use the minus button. I'm not sure what the yellow button is doing but that's it in a nutshell. I hope that helps. I can't help but laugh because it's always the simplest things it seems that want to give the most trouble.
The reason this is becoming a long thread is because you are conflating two different things: windows and applications. These are not the same things, at all. There are many threads on this website where people ask for applications to be opened, and they don't realize they are asking the wrong question. What they really want is for the windows of an application to be restored after launching the application. Now that you've elaborated, I think that's what you really want. You don't just want the application to be launched, you also want one of its windows to be restored onto the screen. Those are different tasks requiring different actions to solve. (But it should be easy to fix.)
Allow me to explain the difference between the red and yellow button. The red button closes the application, while the yellow button minimizes the current window. These are completely different things. An application with minimized windows is still running, and can even be the frontmost application! You can see a good example of that in your video when you press the yellow button, as the name "Trello" still appears in the upper left corner of the screen after you pressed the yellow button.
My macro was designed to launch the application, NOT restore the applications windows. That will require an extra step. Not all macOS apps behave the same way, so some apps need different actions in KM to activate the window. I don't have Trello, so I can't check the Trello menus to help you with that part of the problem.
However in most cases you can activate a minimized window by using the Window Menu of the app. Most likely there is a menu item in Trello's Window menu that will do exactly what you want, and you can trigger that by a KM action similar to the following one:
The macOS Messages app will restore its window on the screen if you do the above action. But you want to restore one of the windows of the Trello app. What you should do is look at all the menu items in the Trello Window app and see which ones solves your problem. If you upload a screenshot of that menu, I might be able to help some more. Or you can wait for someone else on this site who has Trello to tell you what the required action will be.
Thank you so very much for just taking the time to explain this. That took a lot of patience on your part and I want you to know I truly appreciate it. At this point, you have given me all the tools and knowledge to make this work for me so I will take it from here. Thank you once again and please enjoy the rest of the weekend.
Fun fact: while messing around with window management I learned that a minimized window has a subrole property of "AXDialog". It returns to "AXWindow" when it is unminimized.
Point being, there's no real reason to expect that property to change when you shut down your Mac.
I am happy that you are happy with my wordy explanations. Sometimes people think I'm over-explaining, and they don't like me for that reason.
I apooogize for the late response. Thank you. I rarely shut down my Mac, I only lock it.