KM macro to switch Stream Deck Profiles works but is slow

yes, you are right. In that vein, I created a button template profile consisting only of empty buttons with different background design/colors and text font/color. When I add a button in any profile, I just copy from the button template profile to the profile of interest.

1 Like

If I'm understanding correctly, you've developed a way to use a Keyboard Maestro dictionary, with your "button handler," that lets you move SD buttons without having to change the KM trigger's Device Key row and column???

I've been using the UI hack instead of the "dummy app" method because I didn't want to be constantly updating the device key as my button system evolves.

If I'm correct that your method does it require updating the device key, would you be willing to share examples of add dictionary and your button handler?

Thanks,
Russell

That is correct. I rewrite my code from time to time and my current button handler does not support the moving of buttons, all buttons currently are currently displayed in alphabetical order. That design actually works for me, but I realize that won't work for everyone. Also, my current code simply changes the contents of the variable whose name is displayed on the Stream Deck button. Again, that won't work for everyone. Some people will want the button to trigger a macro, and I could certainly and easily add that feature.

I scrolled back to this thread to see what you are referring to here, and I can't determine what you are referring to.

In a post above, I did share some details of my code. I showed what my dictionary contained, and I explained how my code interpreted that data.

You can see the dictionary above, including the key and the data. If the data starts with the word "Green," then the button is drawn in green and the variable whose name is the key is set to 1. If the data starts with the word "Red," then the button is drawn in red and the variables whose name is the key is set to 0. This doesn't seem like a lot, but it really helps me. And then I have a single macro with 32 USB triggers that starts like this:

and contains these actions after the 32 triggers:

What this does is allows me to stop having a separate macro for each button. This is all it takes to give me the power of indirection. By doing this, I can have a single macro that can handle all buttons. Yes, I call it a "button handler." Here is the first action in the button handler:

image

This extracts the button numbers. The actions that put data into the dictionary are easy enough, but I won't upload them today. Here's the last action for you to ponder, which is the code that actually sets the colour of the buttons.

image

When I upload my entire set of macros, I will do it in a new thread.

Thanks for the additional info. This is quite a bit beyond my level of expertise, but you've given me a starting point for further study.

I downloaded DoNothingApp.zip and duplicated DoNothingApp.app. (renaming the duplicate to PS-Adjustment Layers.app). Stream Deck will let me specify DoNothingApp.app, but when I select PS-Adjustment Layers.app, it reverts to DoNothingApp.app.

Any idea why it's not accepting a renamed copy of DoNothingApp.app?

I'm not sure I understand what you're saying—what do you mean it reverts to? Screenshot?

-rob.

1 Like

Thanks, Rob.

In the Stream Deck preferences profiles tab, I select a profile and click the "Application" pull-down menu. I scroll down to Other... , then navigate to and "Open" the dummy app I created by duplicating your DoNothingApp.app and giving it the name, "PS-Adjustment Layers.app". But instead of listing my dummy app as the profile's application, it lists DoNothingApp.app, ignoring what I’ve just set as the application.

Why would the SD app accept some dummy AppleScript apps and not others?

Thanks for the clarification. I wonder if Stream Deck uses bundle identifiers, which would be the same for a duplicated app. Try this instead: Right click on dummy app and open it in Script Editor. Use Save As to save it as a new application name (Dummy App 2), then try Stream Deck again.

I don't do anything like this with my SD, so it's tough to give much more specific guidance :).

-rob.

That worked!

I also had success opening your original DoNothingApp.app and doing a "Save as..." from it.

Think it’s the bundle IDs?

Thanks,
Russell

Yep, it sure seems like they use bundle IDs. Either method will work—as long as you Save As from AppleScript, it'll get a new ID.

-rob.

I found this comment on the original post for the dummy app hack:

I found I needed separate apps with unique names/bundle IDs for the Stream Deck to recognise them as distinct per profile, so creating unique apps on the fly seemed easier.

Makes sense! Glad you got it sorted.

-rob.

In my experience, the SD app displays blank apps by their original name, but it makes no difference when it comes to the profile switch hack working.

Hello everyone,

This is my first post!

The solution with the dummy app works perfectly but I find it restrictive (you have to deactivate the default profile and also if I understood correctly you have to handle with KM the change of profile triggered by the activation of applications).

I found on another forum (Can Stream Deck go to the previously used profile? - #10 by rbanks88 - macOS - Automators Talk) an alternative way via AppleScript that lets you change the profile without having to click on the menu bar first (which I think is the main problem with the AppleScript solution).

Here's the code to activate the “Bear” profile:

tell application "System Events"
 tell process "Stream Deck"
 tell menu 1 of menu bar item 1 of menu bar 2
  click (first menu item whose name contains "Bear")
 end tell
 end tell
end tell

It seems to work, it's elegant and fast, and doesn't require to modify the Stream Deck configuration.

Hope this helps!

François

Been down this road. Great if you have one SD device, but if you have more than one, you have to do a second click to enter its menu.

So you end up with this:

set inst to system attribute "KMINSTANCE"
tell application "Keyboard Maestro Engine"
    set profileName to getvariable "Local__ProfileName" instance inst
end tell

tell application "System Events"
    tell process "Stream Deck"
        tell menu bar item 1 of menu bar 2
            click
            tell menu item 8 of menu 1
                click
                tell menu 1
                    set menuItems to every menu item
                    repeat with anItem in menuItems
                        if name of anItem contains profileName then
                            click anItem
                            exit repeat
                        end if
                    end repeat
                end tell
            end tell
        end tell
    end tell
end tell

...which on my mac takes 2.26s to run, making it a non-starter.

Hello All!
I am looking for a way to trigger Streamdeck profile when I visit a given URL in Safari.
What I did:

  1. created dummy app that does nothing (1=1) and saved it under name ‘SD_Profile_Gmail’

  2. set Streamdeck profile to launch when this app is launched

  3. created KM macro with variable based on URL part where I’m trying several triggers (as on the screenshot):
    a) application Safari Activates - KO: application is brought to the front and then goes back to Safari retriggering the macro in an endless loop
    b) application Safari is Active, repeat every X minutes/seconds - KO: macro retriggers only every few minutes so doesn't act instantly when going to URL; also if set too low (i.e. 5 seconds) then Safari loses focus every 5 seconds
    c) part of address is typed ("mail." or "gmail" in my particular case) - it seemed to work but doesn't work at the moment. I would prefer it to be based on URL part in variable rather than typing address on keyboard.

It seems that 3a) or b) is the best option now but I don't want it to retrigger if already triggered i.e. 30 seconds ago.

Is there any option in KM to park the macro after trigger till some time passed?

Thanks!

I don't have my Stream Deck with me, but I think this should work:

Switch SD for Safari URL.kmmacros (51 KB)

Macro screenshot