-
Notifications
You must be signed in to change notification settings - Fork 23
/
main.go
76 lines (60 loc) · 1.4 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package main
import (
"time"
"github.com/deanishe/awgo"
)
var wf *aw.Workflow
func run() {
var kmMacroErr error
reload := func() (interface{}, error) {
macrosIndex, err := getKmMacros()
if err != nil {
kmMacroErr = err
}
var macros []KmMacro
for _, macro := range macrosIndex {
macros = append(macros, macro)
}
return macros, err
}
// Cache KM macros for 15 seconds
maxCache := 15 * time.Second
var macros []KmMacro
err := wf.Cache.LoadOrStoreJSON("kmMacros", maxCache, reload, ¯os)
if err != nil {
// LoadOrStoreJSON() generates a new error message
// Therefore use kmMacroErr to get the original error message
if kmMacroErr == nil {
wf.Fatal(err.Error())
} else {
wf.Fatal(kmMacroErr.Error())
}
return
}
var item *aw.Item
for _, macro := range macros {
item = wf.NewItem(macro.Name).UID(macro.UID).Valid(true).Arg(macro.UID)
item.NewModifier("cmd").Subtitle("Reveal macro in Keyboard Maestro").Arg(macro.UID)
if macro.Hotkey != "" {
item.Subtitle(macro.Hotkey)
}
}
args := wf.Args()
var searchQuery string
if len(args) > 0 {
searchQuery = args[0]
}
if searchQuery == "" {
wf.WarnEmpty("No macros found", "It seems that you haven't created any macros yet.")
} else {
wf.Filter(searchQuery)
wf.WarnEmpty("No macros found", "Try a different query.")
}
wf.SendFeedback()
}
func init() {
wf = aw.New()
}
func main() {
wf.Run(run)
}