@@ -29,6 +29,13 @@ const (
29
29
ModFn string = "fn" // Alternate action for fn↩
30
30
)
31
31
32
+ // Types understood by Alfred's `action` API call and item field. Added in Alfred 4.5.
33
+ const (
34
+ TypeFile = "file" // values are paths
35
+ TypeURL = "url" // values are URLs
36
+ TypeText = "text" // values are just text
37
+ )
38
+
32
39
// Item is a single Alfred Script Filter result.
33
40
// Together with Feedback & Modifier, Item generates Script Filter feedback
34
41
// for Alfred.
@@ -48,6 +55,7 @@ type Item struct {
48
55
ql * string
49
56
vars map [string ]string
50
57
mods map [string ]* Modifier
58
+ actions map [string ][]string
51
59
icon * Icon
52
60
noUID bool // Suppress UID in JSON
53
61
}
@@ -142,6 +150,27 @@ func (it *Item) Icon(icon *Icon) *Item {
142
150
return it
143
151
}
144
152
153
+ // Action sets the value(s) to be passed to Alfred's Universal Actions if
154
+ // the user actions this item. Alfred will auto-detect the type of the value(s).
155
+ //
156
+ // Added in Alfred 4.5.
157
+ func (it * Item ) Action (value ... string ) * Item { return it .ActionForType ("" , value ... ) }
158
+
159
+ // ActionForType sets the value(s) to be passed to Alfred's Universal Actions if
160
+ // the user actions this item. Type may be one of "file", "url" or "text".
161
+ //
162
+ // Added in Alfred 4.5.
163
+ func (it * Item ) ActionForType (typ string , value ... string ) * Item {
164
+ if typ == "" {
165
+ typ = "auto"
166
+ }
167
+ if it .actions == nil {
168
+ it .actions = map [string ][]string {}
169
+ }
170
+ it .actions [typ ] = value
171
+ return it
172
+ }
173
+
145
174
// Var sets an Alfred variable for subsequent workflow elements.
146
175
func (it * Item ) Var (k , v string ) * Item {
147
176
if it .vars == nil {
@@ -244,6 +273,7 @@ func (it *Item) MarshalJSON() ([]byte, error) {
244
273
Quicklook string `json:"quicklookurl,omitempty"`
245
274
Variables map [string ]string `json:"variables,omitempty"`
246
275
Mods map [string ]* Modifier `json:"mods,omitempty"`
276
+ Actions map [string ][]string `json:"action,omitempty"`
247
277
}{
248
278
Title : it .title ,
249
279
Subtitle : it .subtitle ,
@@ -257,6 +287,7 @@ func (it *Item) MarshalJSON() ([]byte, error) {
257
287
Quicklook : ql ,
258
288
Variables : it .vars ,
259
289
Mods : it .mods ,
290
+ Actions : it .actions ,
260
291
}
261
292
// serialise single arg as string
262
293
if len (it .arg ) == 1 {
0 commit comments