Jump to content
Sign in to follow this  
adayzdone

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.

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  
×
×
  • Create New...