Alfredo: A Node.js Module for Alfred Workflows
Alfredo's primary features include:
- Functions for finding your bundle ID, cache and storage paths, and query arguments.
- Functions for reading and writing JSON and plist files.
- A function to perform fuzzy searching operations.
- A class to simplify generating feedback XML for Alfred.
Installation
npm install alfredo
Core Functions
These are intended to make some basic rote tasks easier and faster to code. alfredo defines the following functions:
alfredo.bundleSync()
This function returns the bundle ID for your workflow by reading it from itsInfo.plist
file.alfredo.readPlistSync(path)
,alfredo.writePlistSync(path, obj)
,alfredo.readJSONSync(path)
,alfredo.writeJSONSync(path, obj)
These functions will read from and write to the plist or JSON files located atpath
.
Feedback System
Alfredo uses a robust and complete implementation of Alfred's feedback system, generating and outputting the required XML for the attributes you specify. This breaks down into a class called Item
and a function called feedback
.
-
alfredo.Item(args)
TheItem
class is initialized with an object of keys and values, and returns oneItem
which can then be passed to thefeedback
function. The following keys are currently understood by Alfredo and Alfred:title
: The title string to show in the feedback list.subtitle
: The subtitle string to show below the title.uid
: A unique identifier string for Alfred's sorting functions.valid
: Eithertrue
,false
, or a string. Tells Alfred whether the item is actionable.autocomplete
: A string to autocomplete Alfred's query to when an invalid item is chosen.icon
: A path to an icon image, a path to a file, or a file type (default:icon.png
).fileIcon
: If you wish to use a particular file's icon, seticon
to its path andfileIcon
totrue
.fileType
: If you wish to specify a type of file whose icon Alfred should use, seticon
to the type andfileType
toTrue
.arg
: The argument to be passed as{query}
if the item is valid and actioned. If it contains newlines, it will be passed as a separate XML key rather than an attribute of<item></item>
.type
: Currently, can only be set tofile
, which tells Alfred to treat the result as a file.
A nifty trick is to pass an object with some or all of
Alfredo.Item
's keys and values into the initializer. So you could conceivably do this:var i = alfredo -
Item.get()
Returns the current values for the item in the following format. Primarily used with thefeedback()
function below.If
autocomplete
ortype
is set, that value will be added to the"attrib"
dictionary, as will anarg
that does not contain newlines. -
Item.feedback()
,alfredo.feedback(items)
Takes either an individual item or a list of items foritems
and prints a UTF-8-encoded XML string for Alfred to interpret.
Fuzzy Search
Alfredo's fuzzy search is powered by the fuzzy-filter node module by DJG.
alfredo
Parameters
pattern - The fuzzy String to match against.
items - An Array of String.
options - (optional)
* pre - String to insert before matching text.
* post - String to insert after matching text.
* limit - Integer maximum number of results.
* separator - String separator. Match against the last
section of the String by default.
* ignorecase - Boolean (default: true).
* ignorespace - Boolean (default: true).
* separate - Boolean (default: false). If set to true, the
function returns an array of an array of strings,
where each array is
[beforeLastSeparator, afterLastSeparator].
If set, `separator` must also be passed.
Note: If pre
is passed, you also have to pass post
(and vice-versa).
Example
alfredo// => ["cs!!", "cheese", "crackers"]
Keychain Interface
If your workflow needs to store a user's sensitive data, particularly a username--password pair, the safest way to do so is with the Mac OS X Keychain. The Keychain is normally an utter pain in the behind, but Alfredo makes working with it a breeze using the node-keychain module.
alfredo.keychain.getPasswordSync(opts)
Searches the Keychain for an account matching the passedopts.account
andopts.service
, returning the password.alfreo.keychain.setPasswordSync(opts)
Saves or changes the saved password foropts.account
andopts.service
toopts.Password
.alfredo.keychain.deletePasswordSync(opts)
Removesopts.account
andopts.service
's password from the Keychain.
Help and Support
The Alfred v2 forums are a good place to look for answers, but you can also file an issue or reach me on Twitter at @npenree.
Contributors
The following are the major contributors of Alfredo (in no specific order).
This module is heavily inspired by alfredo, from Daniel Shannon.
License
(The MIT License)
Copyright (c) 2014 Nicholas Penree <nick@penree.com>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.