godbout/alfred-workflow-scriptfilter
Composer 安装命令:
composer require godbout/alfred-workflow-scriptfilter
包简介
Generate Alfred 3 or 4 Workflow Results in PHP with a laugh.
README 文档
README
Why
Starting with Alfred 3.4.1 you can define variables for individual items and variables and icon for each various modifiers (ctrl, cmd, shift, fn, alt) of each item. That makes rendering the results for Alfred a little tougher than usual with the current tools available, hence this package.
If you don't need the new fields introduced by Alfred 3.4.1 and 3.5, you might want to use Joe Tannenbaum's package. His API might be a little less heavier than mine.
Installation
composer require godbout/alfred-workflow-scriptfilter
Usage
The main ScriptFilter class is a singleton. You can create many
instances of all the other classes: Item, Variable, Icon, and the Mod classes: Ctrl, Fnn, Shift, Alt, and Cmd.
You may check the structure and options of the Alfred Script Filter JSON Format here: https://www.alfredapp.com/help/workflows/inputs/script-filter/json/
require __DIR__ . '/../vendor/autoload.php'; use Godbout\Alfred\Workflow\ScriptFilter; echo ScriptFilter::output();
will result in:
{"items":[]}
You can add items, variables, rerun automatically your script:
ScriptFilter::add( Item::create() ->uid('uidd') ->title('titlee') ->subtitle('subtitlee') ->arg('argg') ->icon( Icon::create('icon path') ) ->valid() ->match('matchh') ->autocomplete('autocompletee') ->mod( Ctrl::create() ->arg('ctrl arg') ->subtitle('ctrl subtitle') ->valid() ) ->copy('copyy') ->largetype('largetypee') ->quicklookurl('quicklookurll') ); ScriptFilter::add( Variable::create('food', 'chocolate'), Variable::create('dessert', 'red beans') ); ScriptFilter::rerun(4.5); $anotherItem = Item::create() ->icon( Icon::createFileicon('icon pathh') ) ->mods( Shift::create() ->subtitle('shift subtitle'), Fnn::create() ->arg('fn arg') ->valid(true) ); $thirdItem = Item::create() ->variables( Variable::create('guitar', 'fender'), Variable::create('amplifier', 'orange') ) ->mod( Alt::create() ->icon( Icon::createFileicon('alt icon path') ) ->variables( Variable::create('grade', 'colonel'), Variable::create('drug', 'power') ) ); ScriptFilter::add($anotherItem, $thirdItem); echo ScriptFilter::output();
will result in:
{
"rerun":4.5,
"variables":{
"food":"chocolate",
"dessert":"red beans"
},
"items":[
{
"uid":"uidd",
"title":"titlee",
"subtitle":"subtitlee",
"arg":"argg",
"icon":{
"path":"icon path"
},
"valid":true,
"match":"matchh",
"autocomplete":"autocompletee",
"mods":{
"ctrl":{
"arg":"ctrl arg",
"subtitle":"ctrl subtitle",
"valid":true
}
},
"text":{
"copy":"copyy",
"largetype":"largetypee"
},
"quicklookurl":"quicklookurll"
},
{
"icon":{
"path":"icon pathh",
"type":"fileicon"
},
"mods":{
"shift":{
"subtitle":"shift subtitle"
},
"fn":{
"arg":"fn arg",
"valid":true
}
}
},
{
"mods":{
"alt":{
"icon":{
"path":"alt icon path",
"type":"fileicon"
},
"variables":{
"grade":"colonel",
"drug":"power"
}
}
},
"variables":{
"guitar":"fender",
"amplifier":"orange"
}
}
]
}
You can sort your results ascendingly, descendingly, by title or anything else:
/** * Will sort the items ascendingly * based on titles. */ ScriptFilter::add(...); ScriptFilter::sortItems(); ScriptFilter::output(); /** * Will sort the items descendingly * based on subtitles. */ ScriptFilter::add(...); ScriptFilter::sortItems('desc', 'subtitle'); ScriptFilter::output();
You can filter your results (you might want to do this with the input from the user) based on any field from your items:
/** * Only items with a title that contains * 'start' will show up in the output. */ ScriptFilter::add(...); ScriptFilter::filterItems('start'); ScriptFilter::output(); /** * Only items with a subtitle that contains * 'end' will show up in the output. */ ScriptFilter::add(...); ScriptFilter::filterItems('end', 'subtitle'); ScriptFilter::output();
Helpers
There's a couple of helpers that should make your code a bit more enjoyable to write. (Or not.)
ScriptFilter
The ScriptFilter can be written using a fluent interface:
ScriptFilter::create() ->item($item) ->variable(Variable::create('gender', 'undefined')) ->items($anotherItem, $oneMoreItem) ->variables($aVariable, $anotherVariable) ->rerun(4) ->item(Item::create());
Item
Item::createDefault(); // same same Item::create()->default(); // same same Item::create()->type('default'); Item::createFile(); // same same Item::create()->file(); // same same Item::create()->type('file'); Item::createSkipcheck(); // same same Item::create()->skipcheck(); // same same Item::create()->type('file:skipcheck'); Item::create()->copy('text to copy'); // same same Item::create()->text('copy', 'text to copy'); Item::create()->largetype('show large'); // same same Item::create()->text('largetype', 'show large');
Icon
Icon::create('~/Desktop'); // same same Icon::create()->path('~/Desktop'); Icon::createFileicon('~/Desktop'); // same same Icon::create('~/Desktop')->fileicon(); Icon::createFiletype('~/Desktop'); // same same Icon::create()->path('~/Desktop')->filetype();
Variable
Variable::create('guitar', 'fender'); // same same Variable::create()->name('guitar')->value('fender'); /** * Anywhere you use the ->variable(...) fluent interface * you can pass the name and value arguments directly * if this is your thing. */ ...->variable(Variable::create('gender', 'unknown')); // same same ...->variable('gender', 'unknown');
Full API
You might want to check the tests to see the full API: tests
The API should mostly help you avoid typing too much and putting wrong data where Alfred is expecting something strict.
Alternatives
- alfred-workflow by Joe Tannenbaum
godbout/alfred-workflow-scriptfilter 适用场景与选型建议
godbout/alfred-workflow-scriptfilter 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.73k 次下载、GitHub Stars 达 17, 最近一次更新时间为 2019 年 02 月 25 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「workflow」 「results」 「alfred」 「scriptfilter」 「alfred-workflow」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 godbout/alfred-workflow-scriptfilter 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 godbout/alfred-workflow-scriptfilter 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 godbout/alfred-workflow-scriptfilter 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Workflow for NetCommons Plugin
Workflow logger
Extension providing tools to export results.
Approval Workflow Engine for Filament
Operational approvals engine for Laravel applications.
A presentable result printer for PHPUnit
统计信息
- 总下载量: 3.73k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 17
- 点击次数: 8
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-02-25