Skip to content

A suit of tools can help you write alfred workflow with Node.js

Notifications You must be signed in to change notification settings

liangzr/alfred-tools

Repository files navigation

Alfred Tools

npm version

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()

output.append(title, arg, subtitle, params)

  • title: <string> option title
  • arg: <string> option arg, pass to next node as an argument
  • subtitle: <string> option subtitle
  • params: <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)

Shortcut for output.append().append()

output.tips(title, subtitle, icon)

  • title: <string> option title
  • subtitle: <string> option subtitle
  • icon: <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)

  • title: <string> option title
  • subtitle: <string> option subtitle

Shortcut for output.tips(), built-in icon for information

output.alert(title, subtitle)

  • title: <string> option title
  • subtitle: <string> option 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)

  • filename: <string> history file path
  • maxNum: <number> max number of histories

Returns an instance of RecentlyUsed

recently.read(limit)

  • limit: <number> maximum limit of the records
  • returns: <object[]>

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)

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) {

Setup the default configuration of the history options

history.reset() {

Clean up all of the histories

License

MIT

About

A suit of tools can help you write alfred workflow with Node.js

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published