Skip to content

Commit

Permalink
Merge pull request #9 from joetannenbaum/additional-features
Browse files Browse the repository at this point in the history
v1.0.0
  • Loading branch information
joetannenbaum authored Aug 25, 2022
2 parents 8e5f3bf + 07e2f36 commit e2c6252
Show file tree
Hide file tree
Showing 34 changed files with 4,360 additions and 1,661 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
.phpunit.result.cache
vendor
.idea
sandbox.php
5 changes: 5 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"tabWidth": 4,
"useTabs": false,
"printWidth": 80
}
50 changes: 50 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
## v1.0.0 - 2022-08-24

This is a huge re-write of the existing library. It removes a lot of the "magic" that was happening in pre-1.0.0
releases
and opts instead for increased clarity and a better IDE experience. It also catches the library up to speed with the
latest Alfred
features.

For a complete upgrade guide, please
visit [https://www.alfredphpworkflows.com/docs/upgrading](https://www.alfredphpworkflows.com/docs/upgrading)

### Breaking

- Bump minimum PHP version to 7.4
- `result` method renamed to `item` ([docs](https://www.alfredphpworkflows.com/docs/upgrading#result-method-renamed))
- `mod` method refactored to accept less arguments and increase
clarity ([docs](https://www.alfredphpworkflows.com/docs/upgrading#modifier-key-methods))
- `largetype` helper function renamed to `largeType`
- Argument order for the `text` method has been
reversed ([docs](https://www.alfredphpworkflows.com/docs/upgrading#copy-and-large-text))
- `fileiconIcon` method renamed
to `iconForFilePath` ([docs](https://www.alfredphpworkflows.com/docs/upgrading#icons))
- `filetypeIcon` method renamed
to `iconForFileType` ([docs](https://www.alfredphpworkflows.com/docs/upgrading#icons))
- `type` method refactored to helper methods ([docs](https://www.alfredphpworkflows.com/docs/upgrading#item-type))
- `output` method now echoes JSON by default ([docs](https://www.alfredphpworkflows.com/docs/upgrading#outputting))
- Sorting is now a method off of the `items` method, and no longer returns an `item` (is no longer chainable)
. ([docs](https://www.alfredphpworkflows.com/docs/upgrading#sorting))
- Filtering is now a method off of the `items` method, and no longer returns an `item` (is no longer chainable)
. ([docs](https://www.alfredphpworkflows.com/docs/upgrading#filtering))

### Added

Full documentation for all of these new features can be found
at [alfredphpworkflows.com](https://www.alfredphpworkflows.com/).

- Ability to use combo modifier keys (e.g. `shift` + `cmd`)
- Ability to add an icon, arguments, and variables to a modifier key
- Ability to specify match text for items
- Ability to specify Universal Actions for items
- Ability to add variables by associative array
- Ability to read and write from a cache
- Ability to read and write data
- Item `invalid` helper method (as opposed to writing `valid(false)`)
- Logger to aid in debugging
- `argument` and `arguments` methods to base `Workflow` class to easily retrieve workflow arguments
- Ability to re-run workflow automatically after an interval
- `skipKnowledge` method
- Ability to easily retrieve Alfred-specific environment variables
- Ability to easily retrieve environment variables
176 changes: 6 additions & 170 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,175 +5,11 @@
[![Build Status](https://travis-ci.org/joetannenbaum/alfred-workflow.svg?branch=master)](https://travis-ci.org/joetannenbaum/alfred-workflow)
[![Total Downloads](https://img.shields.io/packagist/dt/joetannenbaum/alfred-workflow.svg?style=flat)](https://packagist.org/packages/joetannenbaum/alfred-workflow)

This package simplifies PHP development for **Alfred** workflows.
<p align="center">
<img src="https://www.alfredphpworkflows.com/images/logo.svg" style="width: 300px; margin: 50px auto; display: block;" />
</p>

## Installation
This package simplifies PHP development for [**Alfred**](https://alfredapp.com) workflows.

```
composer require joetannenbaum/alfred-workflow
```

## Usage

To understand the following properties, please reference the [official Alfred documentation](https://www.alfredapp.com/help/workflows/inputs/script-filter/json/).

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.

```php
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:

```json
{
"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.

```php
// 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');
```

```php
// 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!');
```

```php
// 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:

```php
// 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.

```php
// Default is searching in title:
$workflow->filterResults('bob');
// By property:
$workflow->filterResults('bob', 'subtitle');
```
You can find installation directions and full documentation
at [alfredphpworkflows.com](https://alfredphpworkflows.com)
12 changes: 10 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,22 @@
"issues": "https://github.com/joetannenbaum/alfred-workflow/issues"
},
"require": {
"php": "^7.4.0||^8.0"
"php": "^7.4.0||^8.0",
"ext-json": "*"
},
"autoload": {
"psr-4": {
"Alfred\\Workflows\\": "src/"
}
},
"require-dev": {
"phpunit/phpunit": "^9.5"
"phpunit/phpunit": "^9.5",
"laravel/pint": "^1.1",
"pestphp/pest": "^1.21"
},
"config": {
"allow-plugins": {
"pestphp/pest-plugin": true
}
}
}
Loading

0 comments on commit e2c6252

Please sign in to comment.