alfred-tools
v2.0.5
Published
Alfred Tools === [![npm version](https://img.shields.io/npm/v/alfred-tools.svg?style=flat)](https://www.npmjs.org/package/alfred-tools) ![](https://img.shields.io/bundlephobia/minzip/alfred-tools)
Downloads
4
Readme
Alfred Tools
A more elegant way to develop with Alfred Workflow
TOC
API
class: AlfredOutputBuilder
AlfredOutputBuilder can help you build a standard Alfred Workflow output easily. Natural IntelliSense auto-complete with TypeScript and no longer need to look at the official Script Filter JSON Format document all the time
import { AlfredOutputBuilder } from 'alfred-tools'
const output = new AlfredOutputBuilder()
output
.append('My first item', 'https://google.com', 'subtitle of first item', {
valid: false,
icon: {
path: './icon.png'
}
})
.append('Second item')
.print()
constructor()
params
: <AlfredOutputItem> optional Alfred output option config- returns: <AlfredOutput>
output.append(title, arg, subtitle, params)
title
: <string> option titlearg
: <string> option arg, pass to next node as an argumentsubtitle
: <string> option subtitleparams
: <AlfredOutputItem> optional alfred output option config
Append a single option
output
.append('first option', 'A', 'choose this one will get A')
.print()
output.append(items)
items
: <AlfredOutputItem[]> array of alfred output option
Shortcut for output.append().append()
output.tips(title, subtitle, icon)
title
: <string> option titlesubtitle
: <string> option subtitleicon
: <string> absolute path of icon for option
Append a static option more easily
output.tips('Not support', 'Please install dependencies first', path.resolve(__dirname, './icon.png'))
output.info(title, subtitle)
Shortcut for output.tips(), built-in icon for information
output.alert(title, subtitle)
Shortcut for output.tips(), built-in icon for alarm
output.clear()
Clear all existing options
output.print()
Show output with Alfred options
class: RecentlyUsed
Storage your history options or just read common links from config.
const { RecentlyUsed, AlfredOutputBuilder } = require('alfred-tools');
const { detectURL } = require('./endpoint');
const pageHistory = RecentlyUsed.use('history.json', 10);
const output = new AlfredOutputBuilder()
output.append('First Row')
const histories = pageHistory.read().map(url => ({
title: url,
arg: url,
subtitle: detectURL(url),
icon: {
path: './assets/ic_history.png',
},
}));
output.append(histories)
use(filename, maxNum)
Returns an instance of RecentlyUsed
recently.read(limit)
Read the recently used list from the local file, you can specify a maximum limit
recently.record(nextRecord) {
nextRecord
: <object> object to be store
Updating a new record item into the local file
recently.replace(data) {
data
: <object[]> the whole data to replace
Overwrite all of the data
recently.reset() {
Clean up all of the data
const: history
Provide a constant history to read, record, and replace the operation history, defaults save at .cache/history.json
const { history } = require('alfred-tools');
const output = new AlfredOutputBuilder()
output.append('First Row')
output.append(history.read())
history.read(limit)
limit
: <number> maximum limit of the records- returns: <AlfredOutputItem[]>
Read the history list from the local file, you can specify a maximum limit
history.record(data) {
data
: <HistoryConfig> object to be store
Updating a new record item into the local file
history.config(params) {
params
: <AlfredOutputItem> optional Alfred output option config
Setup the default configuration of the history options
history.reset() {
Clean up all of the histories
License
MIT