Getting Started with macOS Shortcuts

I’ve been trying to build something really easy as an introduction to triggering a macOS shortcut with Keyboard Maestro. I’m missing something really simple, I’m sure.

I created a 2 step Shortcut:

  1. Get Current Weather at Current Location (which I’ve verified works)
  2. Stop and output .

When I run this inside Shortcuts I see, “102.2ºF and Clear”, which sadly is true :cactus:

In KM I set up a macro with “Execute Shortcut” and selected my Shortcut. But nothing seems to come back to the macro. If I ask it to display or save the value to the clipboard nothing happens.

Is there a step I’m missing in the Shortcut to get the result back to KM?

Thanks for any guidance.

— Robert

1 Like

Hi @rdr. You're much more likely to get some quick assistance if you upload your macro (and maybe a screenshot of your shortcut).

In the event you need it, this page includes a link to the upload instructions.

2 Likes

As @_jims notes, include your macro, and also an image of the shortcut.

Thanks for the reply, @_jims and @peternlewis.

Here's a look at my tiny Shortcu. I ran it in Shortcuts to verify it was working:

And here's the macro I'm using to try to execute it (I slipped a sound into it so I could verify it was executing).
CleanShot 2022-07-12 at 20.59.38

You can get it to work by setting a KM variable in the shortcut and display it in the macro.

2 Likes

What you have should work.

I recreated it here, and firstly had endless trouble getting Shortcuts and the system Location security permissions to agree that it had permission to get the location, but eventually got it running.

And then it was behaving the same, when run from Keyboard Maestro it did not display any output.

So then I ran the Terminal command:

shortcuts run "Get Current Weather"

(which is more or less exactly what Keyboard Maestro does). And that didn't output anything, but possibly because the text ends in a carriage return which then makes the prompt overwrite it. Or maybe it too was not getting anything.

So then I tried:

shortcuts run -o temp.output "Get Current Weather"

and inexplicably that worked and created the temp.output with the current temperature, a lovely winter day of “22°C and Partly Cloudy”.

So then I tried

shortcuts run -o - "Get Current Weather" | bbedit

and that worked. Then I tried:

shortcuts run "Get Current Weather" | bbedit

and that worked too. But that's exactly what Keyboard Maestro does.

So then I tried the macro again, and now it was working and displays the results in the window as it should.

So net result is it looks like Shortcuts is misbehaving and who knows what eventually convinced it to work properly.

3 Likes

My understanding is that Shortcuts' results are not always plain text even if they appear to be, so they often need to be coerced into strings that play nice with KM variables. @JimmyHartington showed you one way that can be done using KM's own Shortcut actions; my solution for using Shortcuts with KM has been to use Shortcuts' "Text" action to modify the results into a KM-friendly format:

3 Likes

Can I ask what you did to solve the security permissions for getting current location?
I have the same issue, but have not found a solution.

Quit Shortcuts.
Disabled Location Services
Quit System Preferences.
Launched System Preferences.
Unlocked System Preferences.
Enabled Location Services
Enabled Location permissions for Shortcuts
Launched Shortcuts

I think.

1 Like

Tried you steps. Did not work.
Tried disabling and enabling everything in System Services in Locations Services. And then it works.
Weird. But thanks for pointing me in the right direction.

1 Like

Thanks, @peternlewis. I've been warned Shortcuts is still less than stable.

We had similar experiences. I too had the initial Location security warnings (noted from the log). And like you, I fiddled with the setting long enough that the security warning stopped showing up. That's why I didn't bring it up here, as I figured that part was already resolved.

OK, well I really appreciate the efforts. My takeaway is that Shortcuts needs a little more time in the oven before relying on.

While I have your ear, endless thanks for an absolutely superb product. Keyboard Maestro is an incredible tool.

-- Robert

2 Likes

Thank you @JimmyHartington. When I posted this, I assumed this was the kind of thing I needed to do, though @peternlewis notes that what I had should've worked.

In any case, your approach works consistently for me. Much appreciated.

-- Robert

1 Like

While annoying to the thinking that things work a particular way or at least should, and allowing for the 'slop' in my worried and overly fidgeted system, I sometimes find that some Keyboard Maestro macros need to be executed several times to get them to complete and once working will work for a bit before needing a 'hit it a few times and spit in the back.'

The most frequent offender is a simple resize window to a quarter screen size and move to one of the screen corners using this:

Sometimes it happens with one triggering. Sometimes the first firing does nothing, the second time resizes the window and a third time moves the resized window.

For awhile I kept running into the wall with tweaking/restarting/reinstalling/etc. and asking questions until I'm sure I've badly tired the patients of the very good and generous people here. I've stopped doing that (with this exception). Even the slow E V E N T U A L learn.

I imagine there are actually traceable actions that, when revealed, would have the results make complete sense AND that that level of forensics will remain way above my current or future pay grade.

After much reading and time, I've returned and hold to something Peter has modeled/said that in my interpretation means for the most part keep things short and simple unless you actually enjoy doing battle with the monsters in the swamp at the bottom of the valley of shadows.

So now I do the extra clicking or 'go manual' and remain peaceful, highly appreciative, and very thankful for these amazing tools and people.

Ah yes, the resize/move a window “bug”. I’ve been plagued with this on my M1 MacBook Air for over a year. FWIW, I wrote a macro that ensures proper window placement and have been using it for the last 6 months with no issues. It’s definitely more of a band-aid than a solution; but it might help you as well.

-Chris

Thanks, Chris. I appreciate the validation. Having to set the window name or index won't work as they change too much. Nice thinking on the macro!

I've found BetterTouchTool's response to gestures (4 finger swipe left or right to get left or right half windows works well if you favor gestures over keyboarding as I do) to issue commands and its engine to execute them to be pretty darn good. Between it and Keyboard Maestro, I'm real good for now.

Thank you for taking the time and have an excellent new year!

1 Like

Yes, sadly the Accessibility API has a nasty habit of simply ignoring part or all the request to change the window. Apparently there are apps that can make this worse or better by turning on or off an undocumented accessibility parameter.

As it is, Keyboard Maestro already executes the Accessibility requests multiple times when making the changes.

One thing to try is to simply add a Repeat action around the Manipulate a Window action (and maybe a small Pause as well) and repeat the action 3 times and see if that improves reliability.