Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/15cm/Alfred-Workflow-JXA
A library for Alfred Workflow written in JXA
https://github.com/15cm/Alfred-Workflow-JXA
Last synced: 6 days ago
JSON representation
A library for Alfred Workflow written in JXA
- Host: GitHub
- URL: https://github.com/15cm/Alfred-Workflow-JXA
- Owner: 15cm
- Created: 2016-04-21T03:21:48.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-06-13T04:42:07.000Z (over 6 years ago)
- Last Synced: 2024-08-02T15:51:23.018Z (3 months ago)
- Language: JavaScript
- Size: 3.91 KB
- Stars: 5
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Alfred Workflow JXA
An alfred workflow library written in JXA(JavaScript for Automation on Mac OS).# Features
- Script filter with cache# Quick Start
```javascript
// Require Hack
ObjC.import('Foundation');
var fm = $.NSFileManager.defaultManager;
var require = function (path) {
var contents = fm.contentsAtPath(path.toString()); // NSData
contents = $.NSString.alloc.initWithDataEncoding(contents, $.NSUTF8StringEncoding);var module = {exports: {}};
var exports = module.exports;
eval(ObjC.unwrap(contents));return module.exports;
};// Import lib
var lib = require('./lib/workflow.js');// Fetch item list from Finder Services
function genList(){
var itemList = [];
var se = Application('System Events');
var finder = se.processes.byName('Finder');
var finderMenu = finder.menuBars[0].menuBarItems.byName('Finder');
var serviceList = finderMenu.menus[0].menuItems.byName('Services').menus[0].menuItems();for(var i in serviceList){
var mItem = serviceList[i];
if(mItem.enabled())
itemList.push(new lib.Item({
uid: i,
arg: i,
autocomplete: mItem.title()
},{
title: mItem.title()
}));
};
return itemList;
}var workflow = new lib.WorkFlow(workflowName = 'FinderService');
var query = "{query}";
var regexp = new RegExp(query + '.*','i');
workflow.cacheData(genList,maxAge = 30);
workflow.filter(regexp);
workflow.alfredXML();
```# Thanks
The `require hack` quotes from [JXA-cookbook](https://github.com/dtinth/JXA-Cookbook/wiki)Interface of this lib is inspired by [alfred-workflow](https://github.com/deanishe/alfred-workflow)