Skip to content

joetannenbaum/alfred-workflow-ruby

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ruby Helper for Alfred 3 Workflows

Latest Version Build Status

This package simplifies Ruby development for Alfred 3 workflows.

Installation

gem install alfred-3_workflow

Usage

To understand the following properties, please reference the official Alfred 3 documentation.

The library is not doing any validation for required properties, so all of the following are optional. Please refer to the documentation above for required properties. All of the properties will default to the official defaults if excluded.

require 'alfred-3_workflow'

workflow = Alfred3::Workflow.new

workflow.result
        .uid('bob-belcher')
        .title('Bob')
        .subtitle('Head Burger Chef')
        .quicklookurl('http://www.bobsburgers.com')
        .type('default')
        .arg('bob')
        .valid(true)
        .icon('bob.png')
        .mod('cmd', 'Search for Bob', 'search')
        .text('copy', 'Bob is the best!')
        .autocomplete('Bob Belcher')

workflow.result
        .uid('linda-belcher')
        .title('Linda')
        .subtitle('Wife')
        .quicklookurl('http://www.bobsburgers.com')
        .type('default')
        .arg('linda')
        .valid(true)
        .icon('linda.png')
        .mod('cmd', 'Search for Linda', 'search')
        .text('largetype', 'Linda is the best!')
        .autocomplete('Linda Belcher')

print workflow.output

Results in:

{
  "items": [
    {
      "arg": "bob",
      "autocomplete": "Bob Belcher",
      "icon": {
        "path": "bob.png"
      },
      "mods": {
        "cmd": {
          "subtitle": "Search for Bob",
          "arg": "search",
          "valid": true
        }
      },
      "quicklookurl": "http://www.bobsburgers.com",
      "subtitle": "Head Burger Chef",
      "text": {
        "copy": "Bob is the best!"
      },
      "title": "Bob",
      "type": "default",
      "uid": "bob-belcher",
      "valid": true
    },
    {
      "arg": "linda",
      "autocomplete": "Linda Belcher",
      "icon": {
        "path": "linda.png"
      },
      "mods": {
        "cmd": {
          "subtitle": "Search for Linda",
          "arg": "search",
          "valid": true
        }
      },
      "quicklookurl": "http://www.bobsburgers.com",
      "subtitle": "Wife",
      "text": {
        "largetype": "LINDA IS THE BEST!"
      },
      "title": "Linda",
      "type": "default",
      "uid": "linda-belcher",
      "valid": true
    }
  ]
}

Helper Methods

Just for clarity, some helper methods exist.

# This...
workflow.result.mod('cmd', 'Search for Bob', 'search')
# ...is the same as this.
workflow.result.cmd('Search for Bob', 'search')
# And these are all available as well:
workflow.result.shift('Search for Bob', 'search')
workflow.result.fn('Search for Bob', 'search')
workflow.result.ctrl('Search for Bob', 'search')
workflow.result.alt('Search for Bob', 'search')
# This...
workflow.result.text('largetype', 'Linda is the best!')
# ...is the same as this.
workflow.result.largetype('Linda is the best!')
# Also works:
workflow.result.copy('Linda is the best!')
# This...
workflow.result.icon('bob.png', 'fileicon')
# ...is the same as this.
workflow.result.fileicon_icon('bob.png')
# Also works:
workflow.result.filetype_icon('bob.png')

Sorting

If you'd like to sort your results:

# Default is by title asc:
workflow.sort_results
# Title desc:
workflow.sort_results('desc')
# By property asc:
workflow.sort_results('asc', 'subtitle')

Filtering

You can filter your results as well if Alfred isn't doing it for you:

Please note this is a very simple filtering, literally looking for the string within the string. For anything more complex filter before creating results.

# Default is searching in title:
workflow.filter_results('bob')
# By property:
workflow.filter_results('bob', 'subtitle')

About

Helper library for creating Alfred 3 Workflows with Ruby

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages