Categorygithub.com/deanishe/awgo
modulepackage
0.29.1
Repository: https://github.com/deanishe/awgo.git
Documentation: pkg.go.dev

# README

AwGo Logo

AwGo — A Go library for Alfred workflows

Build Status Go Report Card Coverage Status Go Reference

Full-featured library to build lightning-fast workflows in a jiffy.

Features

Installation & usage

Install AwGo with:

go get -u github.com/deanishe/awgo

Typically, you'd call your program's main entry point via Workflow.Run(). This way, the library will rescue any panic, log the stack trace and show an error message to the user in Alfred.

program.go:

package main

// Package is called aw
import "github.com/deanishe/awgo"

// Workflow is the main API
var wf *aw.Workflow

func init() {
    // Create a new Workflow using default settings.
    // Critical settings are provided by Alfred via environment variables,
    // so this *will* die in flames if not run in an Alfred-like environment.
    wf = aw.New()
}

// Your workflow starts here
func run() {
    // Add a "Script Filter" result
    wf.NewItem("First result!")
    // Send results to Alfred
    wf.SendFeedback()
}

func main() {
    // Wrap your entry point with Run() to catch and log panics and
    // show an error in Alfred instead of silently dying
    wf.Run(run)
}

In the Script Filter's Script box (Language = /bin/bash with input as argv):

./program "$1"

Documentation

Read the docs on pkg.go.dev.

Check out the example workflows (docs), which show how to use AwGo. Use one as a template to get your own workflow up and running quickly.

Requirements

The library (and therefore the unit tests) rely on being run in a minimally Alfred-like environment, as they pull configuration options from the environment variables set by Alfred.

This means that if you want to run AwGo-based code outside Alfred, e.g. in your shell, you must set at least the following environment variables to meaningful values, or the library will panic:

  • alfred_workflow_bundleid
  • alfred_workflow_cache
  • alfred_workflow_data

And if you're using the update API, also:

  • alfred_workflow_version
  • alfred_version (not needed for Alfred 4+)

Development

To create a sufficiently Alfred-like environment, you can source the env.sh script in the project root or run unit tests via the run-tests.sh script (which also sets up an appropriate environment before calling go test).

Licensing & thanks

This library is released under the MIT licence. It was built with neovim and GoLand by JetBrains.

The icon is based on the Go Gopher by Renee French.

# Packages

Package keychain implements a simple interface to the macOS Keychain.
Package update implements an API for fetching workflow updates from remote servers.
Package util contains general helper functions for workflow (library) authors.

# Functions

AddMagic registers Magic Actions with the Workflow.
HelpURL sets link shown in debugger & log if Run() catches a panic ("Get help at http://…").
IsJobExists returns true if error is of type or wraps ErrJobExists.
LogPrefix is the printed to debugger at the start of each run.
MagicPrefix sets the prefix for "magic" commands.
MaxLogSize sets the size (in bytes) when workflow log is rotated.
MaxResults is the maximum number of results to send to Alfred.
New creates and initialises a new Workflow, passing any Options to Workflow.Configure().
NewAlfred creates a new Alfred from the environment.
NewArgVars returns an initialised ArgVars object.
NewCache creates a new Cache using given directory.
NewConfig creates a new Config from the environment.
NewFeedback creates a new, initialised Feedback struct.
NewFromEnv creates a new Workflows from the specified Env.
NewSession creates and initialises a Session.
NewSessionID returns a pseudo-random string based on the current UNIX time in nanoseconds.
RemoveMagic unregisters Magic Actions with Workflow.
SessionName changes the name of the variable used to store the session ID.
SortOptions sets the fuzzy sorting options for Workflow.Filter().
SuppressUIDs prevents UIDs from being set on feedback Items.
TextErrors tells Workflow to print errors as text, not JSON.
Update sets the updater for the Workflow.

# Constants

AwGoVersion is the semantic version number of this library.
Beer mug.
Prefix to call "magic" actions.
1 MiB.
No limit, i.e.
Workflow variable session ID is stored in.
Alfred's build number.
Alfred's version number.
Bundle ID.
For temporary data.
For permanent data.
Set to 1 when Alfred's debugger is open.
Machine-specific hash.
Name of workflow.
Path to "Alfred.alfredpreferences" file.
ID of user's selected theme.
Background colour.
BG colour of selected item.
Random UID assigned by Alfred.
Workflow version.
Indicates that Icon.Value points to an object whose icon should be show in Alfred, e.g.
Indicates that Icon.Value is a UTI, e.g.
Indicates that Icon.Value is the path to an image file that should be used as the Item's icon.
Alternate action for ⌥↩.
Alternate action for ⌘↩.
Alternate action for ^↩.
Alternate action for fn↩.
Synonym for ModAlt.
Alternate action for ⇧↩.
values are paths.
values are just text.
values are URLs.

# Variables

System icons.
Ready-to-use icons based on macOS system icons.
Ready-to-use icons based on macOS system icons.
Ready-to-use icons based on macOS system icons.
Ready-to-use icons based on macOS system icons.
Ready-to-use icons based on macOS system icons.
Ready-to-use icons based on macOS system icons.
Ready-to-use icons based on macOS system icons.
Ready-to-use icons based on macOS system icons.
Ready-to-use icons based on macOS system icons.
Ready-to-use icons based on macOS system icons.
Ready-to-use icons based on macOS system icons.
Ready-to-use icons based on macOS system icons.
Ready-to-use icons based on macOS system icons.
Ready-to-use icons based on macOS system icons.
Ready-to-use icons based on macOS system icons.
Ready-to-use icons based on macOS system icons.
Ready-to-use icons based on macOS system icons.
Ready-to-use icons based on macOS system icons.
Ready-to-use icons based on macOS system icons.
Ready-to-use icons based on macOS system icons.
Ready-to-use icons based on macOS system icons.
Ready-to-use icons based on macOS system icons.
Workflow's own icon.

# Structs

Alfred wraps Alfred's AppleScript API, allowing you to open Alfred in various modes or call External Triggers.
ArgVars lets you set workflow variables from Run Script actions.
Cache implements a simple store/load API, saving data to specified directory.
Config loads workflow settings from Alfred's environment variables.
ErrJobExists is the error returned by RunInBackground if a job with the given name is already running.
Feedback represents the results for an Alfred Script Filter.
Icon represents the icon for an Item.
Item is a single Alfred Script Filter result.
Modifier encapsulates alterations to Item when a modifier key is held when the user actions the item.
Session is a Cache that is tied to the `sessionID` value passed to NewSession().
Workflow provides a consolidated API for building Script Filters.

# Interfaces

Env is the data source for configuration lookups.
MagicAction is a command that is called directly by AwGo (i.e.
Updater can check for and download & install newer versions of the workflow.

# Type aliases

IconType specifies the type of an aw.Icon struct.
Option is a configuration option for Workflow.