All specifications from the Alfred Script Filter JSON Format page are shown here along with the Go code to produce them and the resulting JSON output.
Wherever it makes sense, struct members are listed in the order they are defined in the specification, so their JSON will sometimes be in a different order than the official document but will still function in Alfred.
- Standard Example
valid
,match
, andquicklookurl
Examplemods
Exampletext
Examplererun
andvariables
Example- Other
variables
andmods
sub-objecticon
Example
package main
import (
"github.com/drgrib/alfred"
)
func main() {
alfred.Add(alfred.Item{
UID: "desktop",
Title: "Desktop",
Subtitle: "~/Desktop",
Arg: "~/Desktop",
Icon: &alfred.Icon{
Type: "fileicon",
Path: "~/Desktop",
},
Autocomplete: "Desktop",
Type: "file",
})
alfred.Run()
}
{
"items": [
{
"uid": "desktop",
"title": "Desktop",
"subtitle": "~/Desktop",
"arg": "~/Desktop",
"icon": {
"type": "fileicon",
"path": "~/Desktop"
},
"autocomplete": "Desktop",
"type": "file"
}
]
}
Addition of the valid
, match
, and quicklookurl
fields, as well as a custom alfred.Indent
value.
package main
import (
"github.com/drgrib/alfred"
)
func main() {
alfred.Indent = "\t"
alfred.Add(alfred.Item{
UID: "desktop",
Title: "Desktop",
Subtitle: "~/Desktop",
Arg: "~/Desktop",
Icon: &alfred.Icon{
Type: "fileicon",
Path: "~/Desktop",
},
Autocomplete: "Desktop",
Type: "file",
Valid: alfred.Bool(false),
Match: "my desktop",
QuicklookURL: "https://www.alfredapp.com/",
})
alfred.Run()
}
{
"items": [
{
"uid": "desktop",
"title": "Desktop",
"subtitle": "~/Desktop",
"arg": "~/Desktop",
"icon": {
"type": "fileicon",
"path": "~/Desktop"
},
"autocomplete": "Desktop",
"type": "file",
"valid": false,
"match": "my desktop",
"quicklookurl": "https://www.alfredapp.com/"
}
]
}
Addition of the mods
object.
package main
import (
"github.com/drgrib/alfred"
)
func main() {
alfred.Add(alfred.Item{
UID: "desktop",
Title: "Desktop",
Subtitle: "~/Desktop",
Arg: "~/Desktop",
Icon: &alfred.Icon{
Type: "fileicon",
Path: "~/Desktop",
},
Autocomplete: "Desktop",
Type: "file",
Valid: alfred.Bool(false),
Mods: map[string]alfred.Mod{
"alt": {
Valid: alfred.Bool(true),
Arg: "alfredapp.com/powerpack",
Subtitle: "https://www.alfredapp.com/powerpack/",
},
"cmd": {
Valid: alfred.Bool(true),
Arg: "alfredapp.com/powerpack/buy/",
Subtitle: "https://www.alfredapp.com/powerpack/buy/",
},
},
})
alfred.Run()
}
{
"items": [
{
"uid": "desktop",
"title": "Desktop",
"subtitle": "~/Desktop",
"arg": "~/Desktop",
"icon": {
"type": "fileicon",
"path": "~/Desktop"
},
"autocomplete": "Desktop",
"type": "file",
"valid": false,
"mods": {
"alt": {
"valid": true,
"arg": "alfredapp.com/powerpack",
"subtitle": "https://www.alfredapp.com/powerpack/"
},
"cmd": {
"valid": true,
"arg": "alfredapp.com/powerpack/buy/",
"subtitle": "https://www.alfredapp.com/powerpack/buy/"
}
}
}
]
}
Addition of the text
object.
package main
import (
"github.com/drgrib/alfred"
)
func main() {
alfred.Add(alfred.Item{
UID: "desktop",
Title: "Desktop",
Subtitle: "~/Desktop",
Arg: "~/Desktop",
Icon: &alfred.Icon{
Type: "fileicon",
Path: "~/Desktop",
},
Autocomplete: "Desktop",
Type: "file",
Text: &alfred.Text{
Copy: "https://www.alfredapp.com/ (text here to copy)",
Largetype: "https://www.alfredapp.com/ (text here for large type)",
},
})
alfred.Run()
}
{
"items": [
{
"uid": "desktop",
"title": "Desktop",
"subtitle": "~/Desktop",
"arg": "~/Desktop",
"icon": {
"type": "fileicon",
"path": "~/Desktop"
},
"autocomplete": "Desktop",
"type": "file",
"text": {
"copy": "https://www.alfredapp.com/ (text here to copy)",
"largetype": "https://www.alfredapp.com/ (text here for large type)"
}
}
]
}
Addition of rerun
value and variables
object at the script filter level.
package main
import (
"github.com/drgrib/alfred"
)
func main() {
alfred.Rerun = 0.5
alfred.Variables["fruit"] = "banana"
alfred.Variables["vegetable"] = "carrot"
alfred.Add(alfred.Item{
UID: "desktop",
Title: "Desktop",
Subtitle: "~/Desktop",
Arg: "~/Desktop",
Icon: &alfred.Icon{
Type: "fileicon",
Path: "~/Desktop",
},
Autocomplete: "Desktop",
Type: "file",
})
alfred.Run()
}
{
"rerun": 0.5,
"variables": {
"fruit": "banana",
"vegetable": "carrot"
},
"items": [
{
"uid": "desktop",
"title": "Desktop",
"subtitle": "~/Desktop",
"arg": "~/Desktop",
"icon": {
"type": "fileicon",
"path": "~/Desktop"
},
"autocomplete": "Desktop",
"type": "file"
}
]
}
Alfred 3.4.1 adds variables
object support at the items
and mods
sub-object level, as well as a custom icon
for mods
sub-objects. Here is an example of it all.
package main
import (
"github.com/drgrib/alfred"
)
func main() {
alfred.Variables = map[string]string{
"fruit": "banana",
"vegetable": "carrot",
}
alfred.Add(alfred.Item{
Variables: map[string]string{
"fruit": "orange",
"vegetable": "asparagus",
},
UID: "desktop",
Title: "Desktop",
Subtitle: "~/Desktop",
Arg: "~/Desktop",
Icon: &alfred.Icon{
Type: "fileicon",
Path: "~/Desktop",
},
Mods: map[string]alfred.Mod{
"alt": {
Variables: map[string]string{
"fruit": "apple",
"vegetable": "radish",
},
Arg: "alfredapp.com/powerpack",
Subtitle: "https://www.alfredapp.com/powerpack/",
Icon: &alfred.Icon{
Type: "powericon",
Path: "~/Desktop/power",
},
},
},
})
alfred.Run()
}
{
"variables": {
"fruit": "banana",
"vegetable": "carrot"
},
"items": [
{
"variables": {
"fruit": "orange",
"vegetable": "asparagus"
},
"uid": "desktop",
"title": "Desktop",
"subtitle": "~/Desktop",
"arg": "~/Desktop",
"icon": {
"type": "fileicon",
"path": "~/Desktop"
},
"mods": {
"alt": {
"variables": {
"fruit": "apple",
"vegetable": "radish"
},
"arg": "alfredapp.com/powerpack",
"subtitle": "https://www.alfredapp.com/powerpack/",
"icon": {
"type": "powericon",
"path": "~/Desktop/power"
}
}
}
}
]
}