Jump to content

AppleScript handler to be used as a Template to Generate Feedback


Recommended Posts

This workflow demonstrates several feedback scenarios and can be used as a template for your AppleScript projects. I will maintain an updated copy of this post on my blog: http://www.johneday.com/617/generate-feedback-in-alfred-2-workflows

 

feedback.png

 

Overview:
To generate feedback in Alfred, we use a Script Filter to pass a query to the xml.scpt AppleScript. The script then processes the query and returns a properly formatted XML string containing information for each item to be displayed. After you import the Generate Feedback workflow, launch it with the gf keyword to view my five examples. To reveal the xml.scpt you will need to edit, open the gf Script Filter and click the Open workflow folder button at the bottom of the window.


Basic Usage:
Add each item you would like to be displayed in your workflow to the itemList by passing a record containing the required labels to the xmlItem handler. For an in-depth description of each attribute, I have included pieces of David’s tutorial in the script’s comments.

on run argv
    -- coerce the argv list to text
    set query to argv as text
 
    -- create an empty list to hold the items
    set itemList to {}
 
    -- Feedback item 1
    set end of itemList to xmlItem({uid:"My uid", arg:"My arg", title:"My Title"})
 
    -- Wrap the elements of the list with a declaration and return the list to Alfred
    return giveFeedback(itemList)
end run

 

xmlItem Handler
Required labels:

{uid:"My uid", arg:"My arg", title:"My Title"}

Optional labels:

subtitle:"My Subtitle"
valid:"no"
autocomplete:"Autocompleted text"
icon:"icon.png"
icon:"public.plain-text", iconAttribute:"filetype"  -- iconAttribute must be used with icon
icon:"/Applications", iconAttribute:"fileicon"       -- iconAttribute must be used with icon

Advanced Usage:
Characters < > & " need to be escaped properly for XML. To insert items that may contain these characters, pass the string to the clean handler along with a true/false value to remove leading and trailing whitespace.

clean("     Title with leading whitesplace & < > \" characters, trimming true", true)

Alfred uses the uid attribute to learn which results are selected the most and then uses this information to sort your feedback. If you would like to manually arrange the returned items, use the uuid handler to generate a unique uid. In Alfred’s next release (after 2.0.2), this issue will be resolved and the item UID attribute will be optional.

uid:uuid()

Along with the workflow, I have included a list of file types that may be used as values for the icon label when paired with iconAttribute:”filetype”. See http://imgur.com/a/0zXVX for the corresponding icons.

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...