Table of contents
Quick Action
Description
As well as being able to use active triggers set-up by Alfred to drive Drafts actions, we can also use external triggers to drive Drafts actions via Alfred, thanks to Alfred’s external calls. One of the things we can do for example is to create a quick action (also known as a service), where Alfred and Doctor Drafts acts as a go between.
We could interact with a variety of things, including selected text, but what we’re going to do in this use case is create a quick action to send selected files to Drafts.
No Flow
Most of our use cases involve creating a custom Alfred flow, but this time we’re building outside of Alfred.
Building the Flow
First of all, open up the standard Mac app called Automator. and select the option to create a new Quick Action.
Set the quick action workflow to accept ‘files or folders’, and set the in application option to be ‘Finder’ if that is your only file manager application, or leave as ‘in any application’ if you use other file management apps in addition, like Path Finder or Forklift. You can set the image and colour to be anything you like.
At this point, we will save the quick action as “Create Draft”. We have configured when we want it to be available to us, and now qwe just need to tell it what to do. Fortunately, although it might look complicated at first, it is actually quite simple.
In the action search on the left, search for AppleScript, to list the ‘Run AppleScript’ action, and then drag it into the build pane on the right.
In the Doctor Drafts workflow in Alfred, we can locate the drnewfile
external trigger for the drnewfile
flow.
Double clicking on it will open up a window that gives us some sample AppleScript to use if we want to call this trigger from outside of Alfred.
What we are going to do is to take that code and place it into our AppleScript action in Automator. We are going to keep the first and last lines, and we are also going to add in a little loop structure to account for if we have selected multiple files to process, and change the "test"
data to be a file path for the input files. The resulting script looks like this.
on run {input, parameters}
repeat with strFilePath in input
tell application id "com.runningwithcrayons.Alfred" to run trigger "drnewfile" in workflow "com.thoughtasylum.doctordrafts" with argument the POSIX path of strFilePath
end repeat
end run
That’s all there is to it. The final workflow should look something like this.
Note, if your text is all purple, don’t worry. If you click on the hammer icon, Automator will check and syntax highlight your code.
Save the quick action workflow, and now you can try it out.
Find one or more text-based files, select them, and then right-click (or CTRL + left click) to reveal the context menu for the files. Now select the “Services” menu, and you should see a list of quick actions (/services) you can use with the files. In the list, you should see “Create Draft”. Select it, and your quick action will run, pass the file paths to Doctor Drafts, which will then create a new draft from each of your files.