Created
May 6, 2015 16:48
-
-
Save mpolichette/f2517ed5577ce30c41a4 to your computer and use it in GitHub Desktop.
Alfred holla workflow
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env node | |
var alfredo = require('alfredo') | |
var exec = require('child_process').exec; | |
var _ = require('lodash'); | |
var team = require('./team.json') | |
function fuzzyFindUsers(query) { | |
var names = _(team).pluck('name').value() | |
var matches = alfredo.fuzzy(query, names) | |
return _.map(matches, function(name){ return _.findWhere(team, {name: name})}) | |
} | |
function userToItem (user) { | |
return new alfredo.Item({ | |
title: user.name, | |
subtitle: "Holla at " + user.name, | |
autocomplete: user.name, | |
uid: user.name, | |
arg: user.name | |
}) | |
} | |
const COMMANDS = { | |
lookup: function (query) { | |
var users = fuzzyFindUsers(query) | |
var userItems = _.map(users, userToItem) | |
return alfredo.feedback(userItems) | |
}, | |
holla: function(query){ | |
var user = _.findWhere(team, {name: query}) | |
if (user.host) exec('open vnc://' + user.host) | |
if (user.phone) exec('open facetime://' + user.phone) | |
}, | |
help: function () { | |
console.log("Usage: node index.js command query\n Commands:\n lookup {query}\n holla {user}\n help\n") | |
} | |
} | |
var command = process.argv[2], | |
query = process.argv[3] | |
if (COMMANDS[command]) { | |
return COMMANDS[command](query) | |
} else { | |
return COMMANDS.help(command, query) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment