jdfwarrior

Generating Feedback in Workflows

98 posts in this topic

The Format

 

** This will be an evolving document. Check here for updates and new documentation. **

 

There is also an XML format example available in Alfred 2 preferences. To see it, open Alfred Preferences, navigate to Workflows. Click the + i nthe bottom right corner of the installed workflows list, select Examples->Script Filter XML format.

 

Result feedback is generated by returning an XML string back to Alfred from a Script Filter item in your Workflow. Script Filters are the only way to pass feedback to Alfred. The following is an example XML string that would be returned to Alfred.

<?xml version="1.0"?>
<items>
  <item uid="rdioartist" arg="r96664" valid="yes" autocomplete="Incubus">
    <title>Incubus</title>
    <subtitle>Artist</subtitle>
    <icon>rdio-artist.png</icon>
  </item>
  <item uid="albumart" arg="/Users/user/Documents/album.jpg" type="file">
    <title>Incubus Album Art</title>
    <subtitle>Album Art for Science</subtitle>
    <icon type="filetype">public.jpeg</icon>
  </item>
</items>

Results will be returned as a list of "items", with each one being an "item" inside. Each item has several arguments and pieces of information associated with it.

 

Item Attributes

 

uid (optional in Alfred 2.0.3+)

The uid attribute is a value that is used to help Alfred learn about your results. You know that Alfred learns based on the items you use the most. That same mechanism can be used in feedback results. Give your results a unique identifier and Alfred will learn which ones you use the most and prioritize them by moving them up in the result list.

 

As of Alfred 2.0.3, this attribute is now optional. If no uid is provided, Alfred will simply generate a UUID. This will allow you to maintain a specific order of generated feedback. Previously, the uid (if not unique for each result) would be added to Alfred's knowledge and would be prioritized in later executions.

 

arg

The arg attribute is the value that is passed to the next portion of the workflow when the result item is selected in the Alfred results list. So if you pressed enter on the sample item above, the value 'r96664' would be passed to a shell script, applescript, or any of the other Action items.

 

type

The type attribute allows you to specify what type of result you are generating. Currently, the only value available for this attribute is file. This will allow you to specify that the feedback item is a file and allows you to use Result Actions on the feedback item.

 

 

valid ( optional - Defaults to 'yes' )

The valid attribute allows you to specify whether or not the result item is a "valid", actionable item. Valid values for this attribute are 'yes' or 'no'. By setting a result's valid attribute to 'no', the item won't be actioned when this item is selected and you press Return. This allows you to provide result items that are only for information or for help in auto completing information (See autocomplete flag below).

 

autocomplete ( optional - Only available when valid = no )

The autocomplete attribute is only used when the valid attribute has been set to 'no'. When attempting to action an item that has the valid attribute set to 'no' and an autocomplete value is specified, the autocomplete value is inserted into the Alfred window. When using this attribute, the arg attribute is ignored.

 

Elements

 

title

The title element is the value that is shown in large text as the title for the result item. This is the main text/title shown in the results list.

 

subtitle

The subtitle element is the value shown under the title in the results list. When performing normal searches within Alfred, this is the area where you would normally see the file path.

 

icon ( optional - If not icon value is available, the icon will be blank. If the icon element is not present, a folder icon will be used )

The icon element allows you to specify the icon to use for your result item. This can be a file located in your workflow directory, an icon of a file type on your local machine, or the icon of a specific file on your system. To use the icons of a specific file type or another folder/file, you must provide a type attribute to the icon item. 

Example: <icon type="fileicon">/Applications</icon> - Use the icon associated to /Applications

Example: <icon type="filetype">public.folder</icon> - Use the public.folder (default folder) icon

Share this post


Link to post

This is possibly one the most awaited features for me. I've got one or two extensions in mind that weren't yet possible due to this "limitation" and one or two more that will benefit greatly from this addition.

 

Quick question,wWould it be possible (feature request anybody ;) ) to be able to pass more data, say like a screenshot, preview image etc?

 

Use case example:

I've got an extension that will generate a iTunes App Store affiliate link base on a query. Sometimes the first result isn't the most accurate so as a workaround I can ask to get say ten results. Currently I'll paste them in the text editor and delete what I don't need.

 

With this new feature I'll return those ten results to Alfred, action the one I want and that will just generate the correct link. It would be great to be able to pass the apps screenshot, icon etc to Alfred (maybe using the quicklook feature)

 

Cheers,

Pedro

Share this post


Link to post

Not really following what you're asking to accomplish.

 

With the multiple results, you could set them as invalid and set the autocomplete flag so that when you try to action it, it will fill Alfred's input with the value that you want then edit it there and then use a modifier key to send it to another script for working with it.

 

If it's that you are wanting to pass multiple values through Alfred, which is what it sounds like, you could pass all the data you need through the arg value with some form of delimiter then split it up when it goes through the next step.

 

Does that make sense?

Share this post


Link to post

Thanks to your help a little earlier I've been messing around and have made some headway into this. It's starting to take shape and quite possibly, what you suggest here could be one way of going.

Share this post


Link to post

Thanks for posting this, and for posting your first few workflows.  With this info I was able to write my first few workflows today.  Not only did it help me replace some of my previously written extensions but improve them big time.

Share this post


Link to post

Something I would like is if the icon parameter could take a URL to an image and load it asynchronously.

Been working on an extension of the spotify workflow and it's search, and have Alfred showing album covers in the results, but would be nice not having to download and store the thumbs before returning the search results to Alfred.

Tyler Eich and untidey like this

Share this post


Link to post
Something I would like is if the icon parameter could take a URL to an image and load it asynchronously.

Been working on an extension of the spotify workflow and it's search, and have Alfred showing album covers in the results, but would be nice not having to download and store the thumbs before returning the search results to Alfred.

 

Yeah, that would be cool. For my App Store Linker I'm currently downloading the images to a temp destination. This puts a little more overhead making it run a little slower than I'd like. 

 

Alternatively, pass the image as  Base64 string (this would have the added benefit of storing the image in a DB for cache.) ;)  

Enhorn likes this

Share this post


Link to post
Something I would like is if the icon parameter could take a URL to an image and load it asynchronously.

Been working on an extension of the spotify workflow and it's search, and have Alfred showing album covers in the results, but would be nice not having to download and store the thumbs before returning the search results to Alfred.

 

That would be very good to have.

Share this post


Link to post

I can't get the autocomplete flag working. Am I doing something wrong or is this not supported yet? This is what I am doing.

When an invalid result is chosen, the Alfred window will disappear.

{ "uid": "someUID",
   "title": "Demo Title",
   "subtitle": "",
   "valid": "no",
   "autocomplete": "Demo Title",
   "icon": "icon.png" }

Share this post


Link to post

I can't get the autocomplete flag working. Am I doing something wrong or is this not supported yet? This is what I am doing.

When an invalid result is chosen, the Alfred window will disappear.

{ "uid": "someUID",
   "title": "Demo Title",
   "subtitle": "",
   "valid": "no",
   "autocomplete": "Demo Title",
   "icon": "icon.png" }

 

I'm running into this same issue. Every time I hit enter on an invalid item, Alfred just disappears. I'll file a report in the Bug Report forum.

Share this post


Link to post

Is the <valid> tag enabled yet? Because I've tried setting it to <valid>no</valid> and the argument is still getting actioned by the next stage of the workflow. Hmm...

Share this post


Link to post
Is the <valid> tag enabled yet? Because I've tried setting it to <valid>no</valid> and the argument is still getting actioned by the next stage of the workflow. Hmm...

 

According to Andrew valid and autocomplete are flags on the item so..

 

<item uid="this" arg="this" valid="no" autocomplete="this">
     <title>Title</title>
     <subtitle>Subtitle Text</subtitle>
     <icon>icon.png</png>
</item>

 

I'll update the documentation. I could have sworn it was different before?

Share this post


Link to post
According to Andrew valid and autocomplete are flags on the item so..

 

<item uid="this" arg="this" valid="no" autocomplete="this">
     <title>Title</title>
     <subtitle>Subtitle Text</subtitle>
     <icon>icon.png</png>
</item>

 

I'll update the documentation. I could have sworn it was different before?

 

Great. That works. Thanks for the help.

 

I have updated Peter Okmas Feedback class to do set the valid and autocomplete flags in this way. You can download it here.

Share this post


Link to post

I have a question. If I'm using the valid="no" attribute for an informational line, what can I do to make sure this line is always at the top of the list. Alfred is prioritising based on previous choices, but you're never going to actually select an informational line, so it's dropping down the list. Surely an info line needs to always go at the top of the list? Any way to control this?

Share this post


Link to post
I have a question. If I'm using the valid="no" attribute for an informational line, what can I do to make sure this line is always at the top of the list. Alfred is prioritising based on previous choices, but you're never going to actually select an informational line, so it's dropping down the list. Surely an info line needs to always go at the top of the list? Any way to control this?

 

 

I don't think there is a way to do this right now, giving all the items the same or empty UID don't seem to return the items in the order they are written... 

 

I would also like to be able to manually select the order of the items in Script Filters. This would be very useful with items that only provide information.

Share this post


Link to post
I have a question. If I'm using the valid="no" attribute for an informational line, what can I do to make sure this line is always at the top of the list. Alfred is prioritising based on previous choices, but you're never going to actually select an informational line, so it's dropping down the list. Surely an info line needs to always go at the top of the list? Any way to control this?

 

In another thread, Florian suggested using a timestamp as the uid. That way you get a different uid each time, which should prevent Alfred from remembering which results you select the most. Not a perfect solution, but if you just want to control the order of your results, it should work well enough.

Share this post


Link to post
In another thread, Florian suggested using a timestamp as the uid. That way you get a different uid each time, which should prevent Alfred from remembering which results you select the most. Not a perfect solution, but if you just want to control the order of your results, it should work well enough.

That's a good idea. Will try it out. Thanks for the tip. :)

Share this post


Link to post

Hey, I'm being helpful ! That was unexpected  :D

 

If I may, I use [timestamp + n] where n is the # of the item and timestamp is the timestamp at the beginning of the script. That way, I'm sure that even with a low precision timestamp (seconds) and a high generation of items, i won't have twice the same ID (both within a query and across several calls).

 

 

Cheers ;)

Share this post


Link to post

I add my xml items to an array which is then json encoded and returned. This way you can use the size of the return array as your uids as it will incrememnt each time a new item is added.

Share this post


Link to post

Yes but that way, the uid are only unique within a call, not in an absolute way. So alfred will memorize the IDs and use them to sort  your items at the next call.

Share this post


Link to post

Is it possible for one script to return feedback multiple times? My Kindle search workflow is a little slow, and it would be handy if I could present some kind of update to indicate that the input was recognized and the script is running before returning the results. I tried using multiple `print` statements in a Python script and found that Alfred would only pay attention to the first one.

Share this post


Link to post

Nope, that's not possible. What you can do though is try having a placeholder subtitle that indicates whatever "loading" text you want. But that's pretty much as far as you can go.

Share this post


Link to post
Nope, that's not possible. What you can do though is try having a placeholder subtitle that indicates whatever "loading" text you want. But that's pretty much as far as you can go.

 

Gotcha. Thanks for the info! I'll have to pick a better subtitle in the next update.

Share this post


Link to post

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