Close Palette by Name?

Thanks a lot @kcwhat. Indeed I wasn't aware of this actions. I tried to use them to reach my goal and with the very first system start after setting up the action it seemed to do what I wanted to. Unfortunately this avoids the ability to open my Palettes afterwards with my regular macro. This seem to be a permanent command which has to be deactivated using the "Reveal…" action.

Things I tried:

• use "Conceal Macro Palettes" triggered with "Engine Launch" (divided with a Pause of 10 sec.)

Result: the Palettes disappear as expected but didn't show when they should with my regular Macro.

• created a dedicated Macro Group with a Macro using the action "Conceal Macro Palettes" inside
• created a Global Macro and used "Activate for one action" triggered with "Engine Launch" (divided with a Pause 10 sec)

The result is unfortunately the same.The Palettes disappear but won't open again.

I use mine as a toggle, on my StreamDeck, to conceal and reveal all the time. It depends on the application I'm in.

Hi @Hans-Peter_Henkel.

Can you post a screenshot of at least one of the macro palette that would open at system start?
It might be easier for others to see what is going on.

Select the macro and use "Copy as Image" from the menu. Then paste it to the forum.

image

This will include the triggers in the image as well.

Sometimes, the macro group settings may also affect the behavior, so including a screenshot might also be helpful.
image

1 Like

You know, it's all about relativity. From my perspective this is "pro level" and gents like ccstone or the master are simply not from this world. :joy:

I know that it would be worth the time to investigate and get better skills. Unfortunately the days have just 24 hours and that is not enough for me. :wink: If only I could, I would… but I am already happy what KM can do for me, even on a "non pro" level.

Thanks again and I will try to get forward with this trying to keep the balance between benefit and effort.

1 Like

Thanks @martin for your help. I needed to restart again to check.

As follows the Palette that shows up last on top of all the others that are configured like this.

image

And here is the Global Macro Group from within the Macro is triggered.

image

Thanks again.

And BTW: even this icon shows up after the system start.

Hi @Hans-Peter_Henkel,

I think this is probably the cause:
You have "Shows a palette until". Be default, it shows a palette.

You may change it to:
image

Or "Always activated and shows ...."

They will behave slightly different.

For me, I usually set here to be "Always activated".

I will do this:

  1. Create another macro, name it, say "Finder Palette 2021 - Activate",
  2. Add the action Show Palette of Macros.
  3. Click the plus button, navigate to "Finder Palette 2021" macro group and click Macro Group "Finder Palette 2021".
  4. Set up a trigger and you are good to go.

I have done the first two steps for you. Please download the macro below and do steps 3 and 4. (I don't have the macro group; therefore, you have to do step 3 on your Mac).

Finder Palette 2021 - Activate.kmmacros (1.2 KB)

1 Like

I respect all of the contributors on this forum. There are several superstars at different levels of acumen. You never know who/m has figured out what and when. The beauty of it all is, we all utilize Keyboard Maestro in different facets based on our needs. Pro Level is relative to the problem and subsequent solution. So solutions may come from @ccstone one day, @gglick another, @tiffle dropping a gem or even YOU tomorrow. JMichaelTX's contributions continue to help me (and many others) to this day. The fact of the matter is that people come here to help, with suggestions, based off of their experience and usage. There are a ton of processes that I employ that some of the superstars wouldn't think of and vice versa. I do agree that @ccstone is at a scripting/regex level that I dare not step in. I'm just glad that he and many other are here to share their expertise. I appreciate all Keyboard Maestro contributors. When helping others, everyone here is or will be pro level at some point.

KC

KC

6 Likes

I couldn't say thanks enough @martin!

Just this did the trick. I followed your instructions and used your Macro template. It worked for this particular one first like expected. But then I changed the recommended setting to all other Palettes that showed up in parallel and they also didn't appear any longer at the start. In the meantime I figured out that even a user log-out and back in was enough to test the behavior.

Now all is working totally to my liking, the Palette shows up with my macro, disappears with the selection of one entry and does not show up with the system start!

You guys are awesome! Thanks again so much everyone! :+1: :+1: :+1:

2 Likes

Thanks @kcwhat, I totally agree with you. I just wish I'd had more time to learn and practice different things to just sniff a bit more of the "pro air", of course still on a very low level. :joy: Maybe some day, when it comes close to retiring.

JMichaelTX also helped me a bunch of times. So sad that he is no longer with us. He really was one of the most ideal examples of a real pro that didn't have any problem to help even the newest members with hardly any knowledge at all with as much patience and kindness as possible.

Thanks again and have a great day!

3 Likes

You're very welcome!
I'm glad I could help out and make you happy.

There is another action you could try:

There are a few options to this action as well:
image

Using this action and the one I had in the uploaded macro will be different.

With this action, I believe the appearance is what you've set in the macro group settings.
For instance, I have a macro palette using this action and set up its appearance to show icons only:
image

I will use mouse click to trigger the target macro.


For the majority of the palettes, I prefer to use this action:

because the palette uses the Conflict Palette style, and I can use keyboards to trigger the target macro.

I did not know how to utilize the macro palette until very late (like three years later after I began to use KM). My workflow completely changed since then. No more numerous hotkeys to remember anymore. As I've shown you in my first reply, I need only ONE hotkey for most of my works.

2 Likes

Thanks again, @martin. That looks great.

This is indeed what I use since I got this hint from my first related question.

image

This is something I need to check when I maybe have a little more time. It sounds and looks very interesting. Currently I am really happy with the solution I have gained thanks to your and other members help. :smiley:

BTW: I forgot to mention that I also used KM for way more than three years before I stumbled over the awesome Palette feature through the great tutorials of @appleianer!

1 Like

How about closing a palette whose names contains a certain term? I have a single macro that opens one of many palettes based on the front application, so the palette name varies. I'd like the macro to first check to see if one of its palettes is open, and if so, close it. The palette names all end with "(menu)"

I tried a bunch of stuff like this check for an open palette with a name containing the term:

tell application "System Events"
   set theWindows to name of every window of process "Keyboard Maestro"
   repeat with i from 1 to length of theWindows
      set theWindow to item i of theWindows
      if theWindow contains "(menu)" then
         return theWindow
      end if
   end repeat
end tell

... but no dice because KM doesn't "see" palettes.

Since KM is handling the initial triggering of the macro, you could have it set the front application to a variable which is then passed to the AppleScript. So for example, if Safari is at the front, you could have KM pass the name of Safari's palette via a variable and then have the AppleScript read that variable to close said palette.

But.... this can likely be done natively with KM.

I have a similar macro that opens a palette based on the front application, and then hides said palette after I click an entry (or hit the ⎋ key, or 5 seconds of inactivity pass). You mentioned checking to see if a palette is open and then closing it... is there a reason you need to check first instead of just using the KM action Hide Macro Group?

Thanks @cdthomer - I'm not married to AppleScript here, but I'm still stuck on how to do it as you described with a variable and/or natively. The palette is determined with a Switch/Case action and a bunch of manual entries like this:

I made this a few years ago, and even though it's a little clunky, I've just added to it over the years by duplicating the group into a new "case" as needed for new apps.

Anyway, I don't know how to create a variable for the given macro group since it's set with a drop down list, and the ExecutingMacroGroup is the group the macro itself is in, not the macro group of the palette.

FWIW: This was a minor feature I wanted to add, but now I'm more curious than anything :slight_smile:

So this is one way to pass the front app's name as a variable to AppleScript which can then use it to close the palette assuming the palette contains that app's name. I imagine since the palettes in question are specific to each app they should have some sort of naming convention that identifies them as such.

It works quite well for me in my limited testing but please let me know if it does or does not work for you! :grin:

-Chris

Close an Application Specific Palette Using Applescript.kmmacros (3.8 KB)

Macro screenshot (click to expand/collapse)

----------------------------------------------------------
# Author:				Chris Thomerson (@cdthomer)
#
# Current Version:		1.0 (Initial script)
# Version History:		1.0 (Initial script)
#
# Created:				Saturday, January 29, 2022
# Modified:				Saturday, January 29, 2022
# macOS:				11.6.3 (Big Sur)
# Tags:					Keyboard Maestro, Palettes
#
# DISCLAIMER
# Permission to use, copy, modify, and/or distribute this
# software for any purpose with or without fee is hereby granted.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
# WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
# THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
# CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
----------------------------------------------------------

### Requires Keyboard Maestro 8.0.3+ ###
set kmInst to system attribute "KMINSTANCE"
tell application "Keyboard Maestro Engine"
	set frontApp to getvariable "local__frontApp" instance kmInst --gets variable from KM
end tell

tell application "System Events"
	tell application process "Keyboard Maestro Engine"
		
		--pauses until the front application's palette appears
		repeat until (first window whose subrole is "AXSystemDialog" and title contains frontApp) exists
			delay 0.1
		end repeat
		
		--simulates clicking the close button of said palette
		click button 1 of (first window whose subrole is "AXSystemDialog" and title contains frontApp)
		
	end tell
end tell
2 Likes

SWEET.

This is the bit I needed:

(first window whose subrole is "AXSystemDialog" and title contains frontApp)

Your code works great after a slight tweak to test if the palette is open:

tell application "Keyboard Maestro Engine"
	set frontApp to getvariable "local__frontApp" instance kmInst --gets variable from KM
end tell

tell application "System Events"
	tell application process "Keyboard Maestro Engine"
		
		--pauses until the front application's palette appears
		if (first window whose subrole is "AXSystemDialog" and title contains frontApp) exists then
			
			
			--simulates clicking the close button of said palette
			click button 1 of (first window whose subrole is "AXSystemDialog" and title contains frontApp)
		end if
		
	end tell
end tell

Thanks so much! This snippet will help me beyond this one use :+1:

1 Like

Outstanding! Glad it works for you and will prove useful elsewhere too!

Hey @cdthomer, is this still working for you? I thought I would check before I go diving in to see why I am having a problem with this:

(first window whose subrole is "AXSystemDialog" and title contains frontApp)

Error:

System Events got an error: Can’t get button 1 of window 1 of application process "Keyboard Maestro Engine" whose subrole = "AXSystemDialog" and title contains "Keyboard Maestro". Invalid index. (-1719).

Hey Evan,

Yes it is still working for me. However, AppleScript in general has become very buggy as of late. See my topic below for an example of the issues I’ve had. So it doesn’t surprise me, unfortunately, that you are having issues.

Question Regarding “Retry This Loop” Used in a “Try/Catch” Action - Questions & Suggestions - Keyboard Maestro Discourse

Thanks for the reply Chris.

That's strange.

I started to debug by inserting the always-helpful Variable Inspector Prompt action into the macro as various points.. As I moved the action down through the macro to isolate the action that was erroring - surprise - no error. Now it's working fine for the moment. Weird.