https://github.com/benchr267/goalfred
Go package to simplify writing Alfred workflows
https://github.com/benchr267/goalfred
Last synced: 9 months ago
JSON representation
Go package to simplify writing Alfred workflows
- Host: GitHub
- URL: https://github.com/benchr267/goalfred
- Owner: BenchR267
- License: mit
- Created: 2016-09-08T17:24:18.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2017-02-16T08:48:43.000Z (over 9 years ago)
- Last Synced: 2025-04-23T22:28:31.067Z (about 1 year ago)
- Language: Go
- Homepage:
- Size: 74.2 KB
- Stars: 8
- Watchers: 3
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# goalfred #
goalfred is a helper package to create workflows for Alfredapp.
[](https://godoc.org/github.com/BenchR267/goalfred) [](https://travis-ci.org/BenchR267/goalfred) [](https://coveralls.io/github/BenchR267/goalfred?branch=master)
## Get ##
```bash
go get -u github.com/BenchR267/goalfred/...
```
## Usage ##
```go
import "github.com/BenchR267/goalfred"
```
Construct your data like you want it to appear in the script filter output.
You can then either use the given Item struct to add elements to the output or provide your custom types:
Using Item:
```go
func main() {
defer goalfred.Print()
item := goalfred.Item {
Title: "aTitle",
Subtitle: "aSubtitle",
Arg: "https://www.example.com",
}
item.Mod.Alt = &goalfred.ModContent {
Arg: "https://www.google.de",
Subtitle: "Open Google!",
}
goalfred.Add(item)
}
```
Using a custom type like Link:
```go
type Link struct {
Name string
Link1 string
Link2 string
}
func (l Link) Item() goalfred.Item {
item := goalfred.Item {
Title: l.Name,
Arg: l.Link1,
}
item.Mod.Cmd = &goalfred.ModContent {
Arg: l.Link2,
Subtitle: "Something special!",
}
return item
}
func main() {
defer goalfred.Print()
link := Link{
Name: "Google",
Link1: "https://www.google.com",
Link2: "https://www.google.de/search?q=hello+world",
}
goalfred.Add(link)
}
```
# Customization
Each Item has many properties, most of them are optional. To get more information about them, take a look at the [official documentation](https://www.alfredapp.com/help/workflows/inputs/script-filter/json/) at Alfred.
# Complex Arguments
Sometimes it's necessary to output more than one parameter by the workflow. For example if you want to schedule a notification like [alfred_dvb](https://github.com/kiliankoe/alfred_dvb) does. If an entry was selected there are multiple informations that should be outhanded. The first one is the time after which the notification should be triggered and the second one is the text for the notification. You could add a script that splits a given string into pieces, but with goalfred you can also add complex arguments that contain a query AND parameters.
You can achieve this by doing the following:
```Go
item := goalfred.Item{
Title: "a title",
Subtitle: "a subtitle",
}
item.SetComplexArg(goalfred.ComplexArg{
Arg: "A nice query that can be used as {query} in Alfred actions",
Variables: map[string]interface{}{
"time": 5,
"output": "this text will replace {var:output} in Alfred actions!",
},
})
```
As you can already see in the code, you can specify variables as well. You can use then the variables value by writing {var:VARIABLENAME} in an Alfred action. Very handy!
# Workflow variables
Alfred added a new functionality in 3.2 which makes it possible to add variables to your script filter. To do this just set the variables via your Go script filter:
```Go
SetVariable("aKey1", 5)
SetVariable("aKey2", "aValue")
```
The variables are then exposed as environment variables to your following scripts.
# Rerun
Sometimes you want to rerun your workflow after a given amount of time. Set this value with
```Go
Rerun(2)
```
before printing your output to Alfred. This will then rerun the workflow after the given amount of seconds.
## CLI Tool ##
WARNING: Still in Alpha status!
goalfred also comes with a great cli tool to automate releases of your workflow. To install the tool, type in your terminal
```Bash
go get github.com/BenchR267/goalfred/...
```
and run it by calling
```Bash
$GOPATH/bin/goalfred release -v 1.0.0 DIRECTORY_PATH
```
with DIRECTORY_PATH replaced by the directory your files are located. Possible options are also `-i` and `-g`.
`-i` or `--infoplist` stands for bumping the version to the argument you specify at the `-v` option.
`-g` or `--git` creates also a git tag and pushes that to your origin git remote.
## License ##
This library is distributed under the MIT-style license found in the [LICENSE](./LICENSE)
file.