Run a System Service as a Script for Alfred Using Keyboard Maestro

I am trying to add a custom file action in Alfred so the selected item (say, an image in this case) in Alfred can be acted upon by any system service ("Upload to CloudApp", "Look Up in Dash" etc.).

The only way this can be done at the moment seems to be via creating a custom workflow inside Alfred.

The input for such a workflow would be the selected item. Then I need to add an Action and from the choices available, one is Run Script.

So I am wondering if I can somehow use Keyboard Maestro to create a macro and use it as a script for the above.

Example of what I actually want to do:

  1. In Finder click on an image file.
  2. Press a hotkey to send the image to Alfred
  3. Select CloudApp custom action from the action list
  4. The image gets uploaded to CloudApp and the URL in clipboard.

Any ideas?

No need to use KM just to press a hotkey and send an image to Alfred. Alfred already has a built-in shortcut for sending the current macOS selection to it, including files in Finder:

Or do you mean you want to automate that entire four-step process with KM? If that's the case, there's probably a way to accomplish the results of that CloudApp action entirely in KM, if you can adapt the script it uses to work with KM actions.

In the example I provided earlier, I need help making #3 work.

I know this is an Alfred question and I already asked there, but am also wondering if I can create a macro in KM that executes a specific system service on an input.

Broadly speaking, my question could perhaps be summarized like this: Is it possible to add a system service inside an action for a macro?

If by system service, you mean the ones that populate the macOS Services menu, then yes. If it's in the form of an Automator workflow, they can be run directly with an Execute an Automator Workflow action; otherwise, they can be invoked from the Services menu like this (make sure to use the exact name of the custom service in the bottom field, of course):


Got it!

  1. I've set a keyboard shortcut for Upload to CloudApp Service in System Preferences > Keyboard.
  1. Created a KM macro that presses the above keyboard shortcut and set it to be triggered by Apple Script.
  1. Created a workflow in Alfred with "File Action" as trigger and "Run NSAppleScript" as trigger. Pasted the script that KM macro generated in the middle.

Now I can send a file to Alfred using a hotkey, then start typing CloudA.., hit return. Alfred calls KM macro and KM runs my keyboard shortcut for the particular Service.

1 Like

Hi @Sridhar, do you know that CloudApp includes basic AppleScripting support to upload files?

Why not only use Keyboard Maestro and bypass Alfred and all the unnecessary steps?

The AppleScript to upload a file to CloudApp is very simple:

tell application "CloudApp"
  upload POSIX file "/Users/zach/"
end tell

With the little help of Finder's Selection Collection you can pass the selected file to the AppleScript:

Here is a full Macro with a previous AppleScript to count the number of selected files and send notifications if 0 or more than 1 file are selected:

Upload Selected Finder File to CloudApp.kmmacros (40.4 KB)

There I have with Launchbar 6 a little more luck, since there from house all "send to" possibilities are pre-installed as a service @Sridhar & @carycrusiau.