GithubHelp home page GithubHelp logo

jk / alfred-workflow Goto Github PK

View Code? Open in Web Editor NEW

This project forked from joetannenbaum/alfred-workflow

0.0 3.0 0.0 29 KB

PHP helper class for Alfred Workflows

License: MIT License

PHP 100.00%

alfred-workflow's Introduction

Alfred 3 Workflows PHP Helper

Latest Version Software License Build Status Total Downloads

This package simplifies PHP development for Alfred 3 workflows.

Installation

composer require joetannenbaum/alfred-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.

use Alfred\Workflows\Workflow;

require 'vendor/autoload.php';

$workflow = new Workflow;

// add variables
$workflow->variable('fruit','apple')
         ->variable('vegetables','carrots');

$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');

echo $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
    }
  ],
  "variables": {
    "fruit": "apple",
    "vegetables": "carrots"
  }
}

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()->fileiconIcon('bob.png')
// Also works:
$workflow->result()->filetypeIcon('bob.png')

Sorting

If you'd like to sort your results:

// Default is by title asc:
$workflow->sortResults();
// Title desc:
$workflow->sortResults('desc');
// By property asc:
$workflow->sortResults('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->filterResults('bob');
// By property:
$workflow->filterResults('bob', 'subtitle');

alfred-workflow's People

Contributors

godbout avatar joetannenbaum avatar wensonsmith avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.