Code Monkey home page Code Monkey logo

awgo's Introduction

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.

awgo's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

awgo's Issues

go get error

❯ go get -u github.com/deanishe/awgo
# github.com/deanishe/awgo/keychain
../go/src/github.com/deanishe/awgo/keychain/keychain.go:82:26: cmd.ProcessState.ExitCode undefined (type *os.ProcessState has no field or method ExitCode)

Question: what's the proper way to generate a workflow plist?

This question is not an issue but a help request.
I'm new to alfred workflow development, so happy to see a golang kit, thanks for your work!

Is there any tool or suggested way to generate the plist of a workflow?

I checked it's content, seems there are few UUIDs need to generate. Should I just copy some existing plist from other workflow and change necessary fields by hand? Or there is a tool to auto-generate it for me?

Not working for Alfred 5

It looks like the library determines that Version 4 is being used because we're using the non-numbered Alfred folder. This folder is apparently used for all new versions.

Two possible fixes:

  • Use the max version found in the version keys in that file
  • Always use "current"

I'm leaning towards the latter.

Unable to use

Hello,

Since the python 2 deprecation, a lot of my useful workflows does not work anymore, so I decided to rewrite the most useful using awgo.

I tried to install and make it run, but it fails :

~/Library/Application Support/Alfred/Alfred.alfredpreferences/workflows/user.workflow.4B2E1432-D6E1-414A-86B6-5A82D7DB37C2
❯ go get -u github.com/deanishe/awgo
go: downloading github.com/deanishe/awgo v0.29.1
go: downloading go.deanishe.net/env v0.5.1
go: downloading go.deanishe.net/fuzzy v1.0.0
go: downloading golang.org/x/text v0.3.6
go: downloading github.com/magefile/mage v1.11.0
go: downloading golang.org/x/text v0.3.7
go: downloading github.com/magefile/mage v1.13.0

~/Library/Application Support/Alfred/Alfred.alfredpreferences/workflows/user.workflow.4B2E1432-D6E1-414A-86B6-5A82D7DB37C2 2m 56s
❯ go run main.go
main.go:9:5: no required module provides package github.com/deanishe/awgo: go.mod file not found in current directory or any parent directory; see 'go help modules'

It seems that I missed something, but I cannot figure out what.
Can you help, please ?

`"valid": false` is a bad choice for the default for wf.NewItem

When calling wf.NewItem(title), the Item struct omits the Valid property in the Alfred JSON feedback with a value of false, which is really unfortunate because:

  1. In the example above, we did not specify a validity setting - if we had wanted one, a call to wf.NewItem(title).Valid(false) would be the way to accomplish this
  2. When you don't specify valid: false in Alfred's item JSON, it assumes you wanted true when omitted. The behavior of this library results in the opposite of the Alfred default behavior.
  3. The README and docs don't mention this explicitly, so this can be tricky to track down.
  4. With valid=false instead of valid=true as the default, the behavior of your workflow is to halt on the go script filter step you created, which can be very confusing a difficult to debug (I know, b/c I just wasted a lot of time finding that bug myself).

I understand that the go struct is likely just defaulting the boolean value to false, but for the reasons I outlined, I recommend that the correct default behavior of this property is use the omitempty JSON marshaling option. I'm happy to submit a fix/PR if you agree that this default is both incorrect and unintuitive.

Dependabot can't resolve your Go dependency files

Dependabot can't resolve your Go dependency files.

As a result, Dependabot couldn't update your dependencies.

The error Dependabot encountered was:

go: howett.net/[email protected]: unrecognized import path "howett.net/plist" (https fetch: Get https://howett.net/plist?go-get=1: EOF)

If you think the above is an error on Dependabot's side please don't hesitate to get in touch - we'll do whatever we can to fix it.

View the update logs.

Remove `BundleID` requirement for import

The choice of design on this line makes this package and any program that uses it unnecessarily hard to test. It gives no opportunity to check and prepare for a testing situation programmatically before awgo is imported.

A better approach would be to have a function like this:

func InitWorkflow() {
	wf = New()
}

This gives users an opportunity to set the environment variables in env.sh for testing after the package is imported. Here is one approach:

func main() {
	if len(os.Args) < 2 {
		InitEnvShVariables()
	}
	aw.InitWorkflow()
	aw.Run(run)
}

The way it is currently set up, I'm blocked by the BundleID error immediately on import if I run my program in a testing environment outside of Alfred without first running env.sh.

I'm currently trying to edit logic in my program that has nothing to do with awgo so it is annoying to be blocked by it simply because I'm importing it.

How I get this to run on Ventura?

Hello,

I've added Alfred to the Developer Tools like you say.
But where I can do this on Ventura??

Open System Preferences > Security & Privacy > General
Click the 🔒 to allow changes
Run the workflow in Alfred. When you get the dialog saying the binary cannot be verified, click "Cancel"
In System Preferences, you should now see an "Allow <binary-name>" option
Click "Allow" and the workflow should now work

Would it be possible to show the changelog of what was added in the Update?

When updating a workflow, it would be really nice to know what exactly was changed. Usually you add this change log to the release itself. However when updating, users just download the new workflow and that's it.

Perhaps it would be nice to direct users and open the URL of the latest release when updating so they see what was changed?

Provide a Workflow file for settings example

I need to setup some settings before my workflow can run but cannot get it working.
Your settings example looks good but it would be really helpful to have the workflow file as a reference

Remove Alfred 3 support

Supporting Alfred 3 adds a lot of complexity, while all later versions of Alfred (5+) should use same paths as Alfred 4.

Allow wf.Filter() to filter on subtitle

It appears that wf.Filter() only filters on information in the Title which is nice, however it would be nice if we could filter based on subtitle text as well.

Is this something you'd consider?

Split out `fuzzy` package as a separate repo

I'm using your great fuzzy package to do some sorting in one of my projects, but I'm not using the rest of the codebase. Is there any chance you'd split out the fuzzy package to its own repo/module so it can be consumed independently?

go get error with go 1.14.1 on MacOS 10.15.5

Run following cmd inside a go mod enabled project folder
go get -u github.com/deanishe/awgo

I got below error message

go: github.com/go-toolsmith/astp upgrade => v1.0.0
github.com/golangci/golangci-lint/pkg/golinters
../../../../../pkg/mod/github.com/golangci/[email protected]/pkg/golinters/gofumpt.go:49:41: cannot use "" (type string) as type format.Options in argument to format.Source

Goroutine log doesn't appear in log file

Hi,

I'm creating goroutines in a background job and I see the logs from the thread creating the goroutines but nothing from inside of the goroutines

I'm not sure if this Is it intended/by design?

EDIT: Closing because I stopped using the library

Big Sur / M1 Issue - hanging

When I try "Can you right-click on the Alfred Maestro workflow in Alfred, select Open in Terminal, run alfred_workflow_bundleid="net.deanishe.awgo" ./alfred-maestro command" all I get is - it seems to hang there and not do anything.

🍺
14:32:30 ----------------- (AwGo/0.17.0) -----------------

I've checked all the permissions and they seem ok. Not sure if a Big Sur or M1 Apple Silicon issue or something else

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.