Downloading and importing a .kmmacros file from a URL

Hello! I have this macro that I share with team members and have it saved on a cloud server so anyone on the team can download it and install it. Most of my team are not KM users, so I'm trying to find a way to have the .kmmacros file auto-download from a direct download link URL to the Downloads folder and then import into KM, so when a team member updates/installs the macro, they don't need to use the KM interface at all. (Just trying to make it very easy.)

And I am getting quite close! I figured out how to ask for/select the downloaded file and import, but it's the auto-download I'm having trouble with. I found this Shell script that will indeed download the file, but when I go to import, I get an error. (I have very little experience with Shell scripting.)


Screen Shot 2022-10-31 at 3.16.45 PM

I cannot quite pinpoint where the error is. Is it in the download, the script, the file name, the URL?

When I download the file manually via the URL, it imports fine. Maybe there is a better way to do this? Open to ideas, thank you!

I just compared the file sizes via "Get Info" on the shell downloaded one and the manually downloaded one and it seems the shell downloaded one is just not downloading the macro file all the way... anybody know why that may be?

Manually download how? cURL in the Terminal or with a web browser? Are you providing a public link or do your users need to authenticate to download?

It would be a good idea to quote the variable in your shell script:

curl --url "$KMVAR_VarName" --output...

Thank you! I quoted the variable.

When I say manually download, I mean I enter the URL into Chrome and it takes me to the direct download of the file.

This link is available to anyone on the team, as long as they are logged in, which we are most of the time, there shouldn't be any additional authentication.

Except that an authenticated session in eg Chrome doesn't carry over to cURL -- they'll have to authenticate again (which they won't thank you for!), you'll have to mess around with bearer tokens and a bunch of other nonsense... And that all seems a lot of work.

Can you not just use an "Open URL" action? That can use their default browser so there's a good chance they are already logged in, and if not the auth routine will be the same as usual. The action should simply spawn a new, blank window/tab (which you might have to close later) then download the file as usual, ready for you to import with an "Open File" action.

1 Like

Ah, I see what you mean! Yes, this is more work than it's worth, I think my team members are more than capable of downloading the macro themselves then using the rest of the macro to open it in Keyboard Maestro. Thank you for the reply and explanation! Saved me a lot of wasted time (and headaches) trying to figure this out :sweat_smile:

Shouldn't be needed. Instead of your cURL, use an "Open URL" action pointed at the file to be downloaded. That'll use their default browser, avoiding authentication (or, at worst, doing it in a way that's familiar to them).

Your macro can then wait until the download is complete, then do the import for them. So the only thing you're changing is the action you use to download the file.

Oh right, of course! That is so much simpler, thank you! I will definitely implement that. What would be the best way to wait for the download to complete? Is there a way to watch folders for a new file?