Alfred-workflow-js

网友投稿 275 2022-09-20

Alfred-workflow-js

​​#​​ 1. 基本运行

var AlfredNode = require('alfred-workflow-nodejs');var actionHandler = AlfredNode.actionHandler;var workflow = AlfredNode.workflow;var Item = AlfredNode.Item; (function main() { actionHandler.onAction("action1", function(query) { // your code to handle action 1 here }); actionHandler.onAction("action2", function(query) { // your code to handle action 2 here }); actionHandler.onMenuItemSelected("action2", function(query, selectedTitle,) { // your code to handle manu item selected of action 2 here }); AlfredNode.run();})();

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

​​#​​ 2. 日志打印

console.warn("action1, 参数:" + query)

1

​​#​​ 3. 菜单

使用脚本当使用tab键,会进行跳转的操作。

//输入tab键会把上一个选中的参数翻到这里 actionHandler.onMenuItemSelected("action1", function (query, title,) { console.warn("data:" + data) console.warn("title:" + title) console.warn("query:" + query) var item1 = new Item({ title: "Item 1 of " + title, arg: "item 1 of " + title + " which has alias ", subtitle: "data", // we can get data of selected item valid: true }); var item2 = new Item({ title: "Item 2 of " + title, arg: "item 2 of " + title + " which has alias ", subtitle: data, valid: true }); workflow.addItem(item1); workflow.addItem(item2); var item3 = new Item({ title: "Item 3 of " + storage.get("key1"), arg: "item 3 of " + title + " which has alias ", subtitle: data, valid: true }); workflow.addItem(item3); var item4 = new Item({ title: "Item 4 of " + storage.get("key2").name, arg: "item 4 of " + title + " which has alias ", subtitle: data, valid: true }); workflow.addItem(item4); workflow.feedback(); });

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43

​​#​​ 4. 使用本地缓存进行CURD

var AlfredNode = require('alfred-workflow-nodejs');var actionHandler = AlfredNode.actionHandler;var workflow = AlfredNode.workflow;var Item = AlfredNode.Item;workflow.setName("example-alfred-workflow-using-nodejs");//类似本地的缓存var storage = AlfredNode.storage;var storage = AlfredNode.storage;storge.set("key", "value");storage.set("key", {name: "node"}, 1000);storage.get("key");storage.remove("key");storage.clear();

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17

​​#​​ 5. 获取Alfred-workflow中的配置

//获取系统外部配置 console.warn("系统环境变量:" + utils.envVars.get("outSetting"))

1 2 3

​​#​​ 6. 异常图标

可以是图片地址,也可以是系统icns地址

(ACCOUNT, BURN, CLOCK, COLOR, EJECT, ERROR, FAVORITE, GROUP, HELP, HOME, INFO, NETWORK, NOTE, SETTINGS, SWIRL, SWITCH, SYNC, TRASH, USER, WARNING, WEB)

icon: AlfredNode.ICONS.INFOicon: AlfredNode.ICONS.ERROR

1 2 3 4

​​#​​ 7. 传递给下一个的变量

AlfredNode.utils.generateVars({arg: 'xyz', variables: {key: value}};

1 2

​​#​​ 8. 获取mac的钥匙串

var settings = AlfredNode.settings; // 将账户密码添加到钥匙串 settings.setPassword("alfred-liuxin", "password"); // 获取mac的钥匙串中的,密码 settings.getPassword("alfred-liuxin", function(error, password){ console.warn("获取密码:" + password); });

1 2 3 4 5 6 7

​​#​​ 9. 自动黏贴APP中

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:dubbo 2.5.3 升级记录 to 2.7.10
下一篇:Reactive 反应式编程
相关文章

 发表评论

暂时没有评论,来抢沙发吧~