godbout / alfred-workflow-scriptfilter
用PHP轻松生成Alfred 3或4工作流程结果,让人忍俊不禁。
2.4.0
2022-05-06 16:15 UTC
Requires
- php: ^8.0.2
Requires (Dev)
- codedungeon/phpunit-result-printer: ^0.32
- hassankhan/config: ^3.0
- phpunit/phpunit: ^9.5.20
- scrutinizer/ocular: ^1.9
- symfony/yaml: ^5.4.3
README
为什么
从Alfred 3.4.1开始,您可以为每个项目的单个项定义变量,并为每个项目的各种修饰符(ctrl、cmd、shift、fn、alt)定义变量和图标。这使得使用当前工具渲染Alfred的结果比以往更加困难,因此有了这个包。
如果您不需要Alfred 3.4.1和3.5引入的新字段,您可能想使用Joe Tannenbaum的包。他的API可能比我的轻量级一些。
安装
composer require godbout/alfred-workflow-scriptfilter
用法
主要的ScriptFilter
类是一个单例。您可以创建所有其他类的多个实例:Item
、Variable
、Icon
,以及Mod
类:Ctrl
、Fnn
、Shift
、Alt
和Cmd
。
您可以在以下位置查看Alfred脚本过滤器JSON格式结构和选项:https://www.alfredapp.com/help/workflows/inputs/script-filter/json/
require __DIR__ . '/../vendor/autoload.php'; use Godbout\Alfred\Workflow\ScriptFilter; echo ScriptFilter::output();
将导致
{"items":[]}
您可以添加项目、变量,自动重新运行您的脚本
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();
将导致
{ "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" } } ] }
您可以按升序、降序、按标题或其他任何方式排序结果
/** * 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();
您可以根据项目中的任何字段过滤结果(您可能想使用用户的输入来完成此操作)
/** * 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();
助手
有几个助手可以让您的代码编写起来更加愉快。(或者不。)
ScriptFilter
ScriptFilter可以使用流畅的接口编写
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');
完整API
您可能想查看完整的API测试:[测试](https://github.com/godbout/alfred-workflow-scriptfilter/tree/master/tests)
API应该主要帮助您避免输入太多,并将错误的数据输入到Alfred期望的严格位置。
替代方案
- [alfred-workflow](https://github.com/joetannenbaum/alfred-workflow) by Joe Tannenbaum