Jump to content

Simple Ideas: a de-count-structed workflow


Recommended Posts

Background
I thought it was time to bring together some of things we've covered in the the Simple Ideas posts and to deconstruct a simple workflow. The one I have chosen is my Word and character count workflow from the Alfred Gallery.

Be warned: this dissection is painfully slow and detailed which some readers may find distressing.

The skeletal workflow
SkeletalWorkflow.thumb.png.ef336918abd2b5a93911a831b79edab0.png

Explanation
1. We start with a simple Universal Action limited to Text and Single Input Arguments. It's called, unsurprisingly, Word and character count—because we want users to recognise it in the list of Universal Actions that appear when text is selected and the Universal Actions hotkey is pressed.

2. The first thing the workflow needs to do is to save the selected text as a variable because, as you'll see, we need to do something with the text later in the workflow. Thus a variable theText is created with the value {query} (because {query} is what Alfred passes out of the Universal Action and into the first Arg and Vars Utility.)

We have the text stored for subsequent retrieval.

In the Arg and Vars Utility we check Pass through input argument because we want the selected text to pass to the next item in the workflow. (Remember, we can't create a variable and, in the same Arg and Vars Utility, spit out that variable to be passed to the next item in the workflow. So the easiest way here, to avoid using an additional Arg and Vars Utility to pass on the text variable, is simply to pass through the input argument.)

3. The Text Metrics Automation Task, which we set to count Words (double click on the Automation Task to select that), eats the selected text and outputs the number of words in it.

4. We don't want to lose the word count so we immediately create a wordCount variable with the value {query} (the value that passed into this Arg and Vars Utility).
WCVar.thumb.png.9e555dacd1572de923787bb73edbe2c3.png

We have the word count stored for subsequent retrieval.

This time we don't want to pass through the input argument (i.e., the number of words) but we do want to feed the text to the next item in the workflow. We set the argument to be passed on as {var:theText}: the text variable we created in 2 above. (Remember, variables need to be packaged so that Alfred recognises them as variables; so we don't simply use theText but, rather, {var:theText}.)

5. The text ends up in a second Text Metrics Automation Task—this time set to count Characters. This Automation Task devours the text, digests it and regurgitates the number of characters in it…

6. …which we promptly save for later retrieval. We create a new variable charCount and assign to it {query} (which, for those of you still awake, is of course the character count passed in to the Arg and Vars Utility).

We have the character count stored for subsequent retrieval.

We choose not to pass anything out of this Arg and Vars utility because we now have all we need to assemble some helpful text for the user.

7. We're going to present the user with the analysis and also a couple of choices so we use a Dialog Conditional.
Dialog.thumb.png.c7667b27e3bf5da4e0684a0a197bcdbf.png

We provide the dialog with a title identical to that of the workflow. In the Description we set out what we wish to user to see in the dialog. In this case it's obviously a sensible summary of the result of running the workflow—interspersing with appropriate text the relevant two variables that we created so that the user will see something like this:
DialogDisplay.png.0896489843cfaf8ab8bbaf390f4509d1.png

It is worth noting two other things. First, we politely enquire what the user would like to do next—which directs the user's attention to the two options provided. Second, we ensure that the most likely option is that displayed for Button 1. The reason is that option will by default be highlighted by Alfred so that all the user has to do to select it is to press .

8. If the user does select to copy something to the clipboard we've chosen here, in the Copy to Clipboard object, to copy:
Words: {var:wordCount}
Characters: {var:charCount}.

Remember, the copy to the clipboard is going to happen silently so it's only polite to let the user know it's actually taken place.

9. Accordingly, here's a little Notification Output that contains simply the title of the workflow and the following for the Text: field:
The numbers of words ({var:wordCount}) and characters ({var:charCount}) have been copied to the clipboard.

Note we again use the variables we've saved in order to make the notification rather more informative that it might otherwise be.

In conclusion
I hope that leaving the tattered remains of this workflow for all to see might, for some at least, have proved useful. To those deeply distressed by the painstaking, and no doubt painful, dissection I apologise.

Stephen

The Simple Ideas posts

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...