Improvement: Change kmmacrolist.txt to kmmacrolist.json and use JSON instead of Plaintext.
Using Shortcuts to trigger KM macro remotely is not a new thing. (See e.g., this post).
However, what I'm going to share is to let Shortcuts show a list of macros for us to choose from.
This is how it looks like:
I. Setup
To accomplish this task, we need do to at least three things:
1. Create a Macro List File.
For instance, I created a file named kmmacrolist.json and placed it in my dropbox folder: ~/Dropbox/Scripting/KM/Shortcuts/kmmacrolist.json.
In this file, I have a list of KM macros. Each line is a Description of the macro, followed by a comma and a space, and then lastly its UUID, something like this:
Note:
The Description can be any memorable text. It does not have to be the name of the macro, since we are going to trigger it with the UUID.
I'm using UUID instead of name because most of the macro names are prefixed by a number, e.g., 03) Macro Name. It is unnecessary to show these prefixed numbers in the list of the Shortcuts.
Basically, it monitors my ~/Dropbox/Scripting/KM/Shortcuts folder. When a new file named execMacro.txt is added, it reads it's context (the UUID) and then triggers the macro. Afterwards, it deletes the file.
In the AppleScript, I trigger the macro with parameter Shortcuts. This allows me to do something with the macro being triggered. For instance, if I trigger the macro to check Airpods battery level from my iPad, I'll use Pushover to send the batter level result to my iPad only. Otherwise, I will just show on my Mac.
All UUIDs are saved in our private Dropbox folder (you may use the iCloud folder). It is relatively safer than the Remote Trigger, which may be triggered by anyone.
Supposing our Dropbox (or iCloud) syncing is fast enough, it will be more reliable than the Remote Trigger, which is said to be not 100% reliable.
We only put a limited number of macros to be triggered remotely. It could arguably be quicker to locate the target macro than the Keyboard Maestro Control app. As you can see in my demo video above, I get the Pushover notification very quickly, which is the result of the macro being triggered.
We can easily update the macro list at anytime. For instance, we can make a macro to append the macroName and macroUUID of any selected macro to the kmmacrolist.txt file.
It will have negative speed affect on the Shortcuts (processing more lines).
It's not easy to choose a macro from a long list.
Instead, consider making multiple macro list files and make a separate Shortcuts for each macro list file. The only difference between these Shortcuts will be the path of the "Get File" action. This setup will then serve as a "pseudo macro group".
(PS: I personally do not have much use of it, but I just came up with this idea this afternoon and hope it can help others who might have good use of it.)
I have updated the OP to use kmmacrolist.json instead of kmmacrolist.txt in the Shortcuts. It simplifies the Shortcuts and has better appearance in the "Choose from Dictionary" action.
I also changed the KM macro to add selected macro to the kmmacrolist.json file.
Edit the AppleScript file (==PushoverNotification.scpt==):
insert:
set Device to do shell script "echo $KMPARAM_Device"
and
if (Device is not "All") or (Device is not "") then
set curl to curl & "--form-string \"device=" & Device & "\" "
end if
I have not tested fully, because I'm using only one device (iPad). But I think, with the above AppleScript, if the Device field in KM is set to All or blank, then the message will be pushed to all devices. Otherwise, set the field to a specified device that we set in our the Pushover account. See:
device - your user's device name to send the message directly to that device, rather than all of the user's devices (multiple devices may be separated by a comma)
@martin this is normal. You don't have to take into account the size of the images, because they are automatically adjusted when Pushover runs. The bigger, the better the quality of the display in the notification.
I personally do not have much need of remote trigger right now. As @appleianer has mentioned in a few places on the forum, when connected to the same local network, it is more efficient to use a Shell command to trigger KM macros. The Shortcuts trigger is useful when we are not close to the Mac.
I can imagine it would be useful to those who have a work computer running in the company. They can then trigger KM macros on the work computer from home.
Another case is when someone has a Mac running as a server. They may want to do something with the server remotely. Such as enabling or disabling a certain service.
We can simply use it to check if the Mac is still running. If it's not running, the macro will not be triggered and it will not return anything. We may use other ways to first wake up Mac remotely.
I don't have need of any of these usages right now and have not tried any of them.
Hi @henryone, in the following posts times 2 examples, how I execute KM actions on my iMac via Siri Shortcuts. Thereby the scan is triggered via SSH action and the snapshot with the following alarm and the locking of the keyboard via iCloud Drive....
Please click on video in the posts. You will then come to Droplr and can see the videos in a better resolution
What I do on a daily basis is use Hey Siri to wake my Macs up from sleep and then use a Keyboard Maestro macro to unlock them.