Jump to content
deanishe

AwGo — Workflow library for Go

Recommended Posts

Icon.png 

 

AwGo — A Go library for Alfred workflows

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

 

https://github.com/deanishe/awgo


Features

 

  1. Easy access to Alfred configuration, including populating a struct from workflow variables and persisting settings back to info.plist.
  2. Straightforward generation of Alfred JSON feedback.
  3. Support for all applicable Alfred features up to v3.5.
  4. Fuzzy sorting/filtering.
  5. Simple API for caching/saving workflow data.
  6. Catches panics, logs stack trace and shows user an error message.
  7. Workflow updates API with built-in support for GitHub releases.
  8. Built-in logging for easier debugging.
  9. "Magic" queries/actions for simplified development and user support.
  10. macOS system icons.

 

Installation & usage


Install AwGo with:

go get -u github.com/deanishe/awgo/...


Typically, you'd call your program's main entry point via 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 GoDoc.
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.

 

Running/testing

 

The library, and therefore the unit tests, rely on being run in an Alfred-like environment, as they pull configuration options from environment variables (which are set by Alfred).
As such, you must 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 then calls go test).

 

Licensing & thanks

 

This library is released under the MIT licence.
The icon is based on the Go Gopher by Renee French.

 

Edited by deanishe
Fix links again

Share this post


Link to post

I think I posted this to the wrong forum previously. Apologies!

 

Hey, @Deanishe thanks very much for bringing out AwGo. I'm pleased to report that I've just tried the example program, and after creating a symbolic link to the Golang app, it worked. I am really excited by this package because, although  I have used Python quite a bit, nowadays I much prefer Golang, so this is perfect for me. I'm going to try to port that Lazarus Docs searching tool that you kindly worked on for me and the look at extending it as you suggested.59c4e778cd5c6_ScreenShot2017-09-21at23_15_23.png.eec7e33bc51492546b73cb5eb77f52fe.png

Share this post


Link to post
5 hours ago, carlcaulkett said:

 

I think I posted this to the wrong forum previously. Apologies!

 

 

Yeah. I merged it with the AwGo thread. Which I’ve done again. I’ll delete the first post.

 

5 hours ago, carlcaulkett said:

thanks very much for bringing out AwGo

 

Glad you like it. 

 

5 hours ago, carlcaulkett said:

after creating a symbolic link to the Golang app, it worked

 

That’s not necessary. Are you using “go run” to execute your workflow?

 

You should compile it instead with “go build”.

 

 

Share this post


Link to post

Quite a hefty update to v0.14 today.

 

Bad news first:  I've changed a lot of the API.

 

Good news: I've added support for Alfred's entire AppleScript API, so you can call Alfred directly from Go code, and best of all, you can now populate a struct from workflow variables via Config.To() and save settings back to info.plist with Config.Set() or Config.From() (the counterpart to Config.To()).

 

Edited by deanishe

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...