Skip to content

Commit bb4a1b6

Browse files
committed
Add reveal in Spotify through mod
1 parent 80c4881 commit bb4a1b6

File tree

4 files changed

+42
-0
lines changed

4 files changed

+42
-0
lines changed

alfred/alfred.go

+13
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,18 @@ type AlfredIcon struct {
1010
Path string `json:"path,omitempty"`
1111
}
1212

13+
type AlfredMod struct {
14+
Valid bool `json:"valid,omitempty"`
15+
Arg string `json:"arg,omitempty"`
16+
Subtitle string `json:"subtitle,omitempty"`
17+
}
18+
19+
type AlfredMods struct {
20+
Ctrl AlfredMod `json:"ctrl,omitempty"`
21+
Alt AlfredMod `json:"alt,omitempty"`
22+
Cmd AlfredMod `json:"cmd,omitempty"`
23+
}
24+
1325
type AlfredItem struct {
1426
Uid string `json:"uid,omitempty"`
1527
Type string `json:"type,omitempty"`
@@ -19,6 +31,7 @@ type AlfredItem struct {
1931
Autocomplete string `json:"autocomplete,omitempty"`
2032
Valid *bool `json:"valid,omitempty"`
2133
Icon AlfredIcon `json:"icon,omitempty"`
34+
Mods AlfredMods `json:"mods,omitempty"`
2235
}
2336

2437
type AlfredItems struct {

main.go

+6
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ func main() {
4343
log.Fatal(err)
4444
return
4545
}
46+
} else if action == "revealinspotify" {
47+
err := spotify.Reveal(*contextPtr)
48+
if err != nil {
49+
log.Fatal(err)
50+
return
51+
}
4652
} else if action == "auth" {
4753
err := setup.LaunchAuth()
4854
if err != nil {

menus/menus.go

+18
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,12 @@ func albumItem(album client.SimpleAlbum) alfred.AlfredItem {
178178
Icon: alfred.AlfredIcon{
179179
Path: "icons/album.png",
180180
},
181+
Mods: alfred.AlfredMods{
182+
Ctrl: alfred.AlfredMod{
183+
Arg: fmt.Sprintf("--action revealinspotify --context %s", album.URI),
184+
Subtitle: "Reveal in Spotify",
185+
},
186+
},
181187
}
182188
}
183189

@@ -205,6 +211,12 @@ func trackItem(track client.FullTrack, contextType int) alfred.AlfredItem {
205211
Path: "icons/track.png",
206212
},
207213
Arg: arg,
214+
Mods: alfred.AlfredMods{
215+
Ctrl: alfred.AlfredMod{
216+
Arg: fmt.Sprintf("--action revealinspotify --context %s", track.URI),
217+
Subtitle: "Reveal in Spotify",
218+
},
219+
},
208220
}
209221
}
210222

@@ -218,6 +230,12 @@ func artistItem(artist client.FullArtist) alfred.AlfredItem {
218230
},
219231
Valid: newFalse(),
220232
Autocomplete: fmt.Sprintf("-artist=\"%s\" ", artist.Name),
233+
Mods: alfred.AlfredMods{
234+
Ctrl: alfred.AlfredMod{
235+
Arg: fmt.Sprintf("--action revealinspotify --context %s", artist.URI),
236+
Subtitle: "Reveal in Spotify",
237+
},
238+
},
221239
}
222240
}
223241

spotify/spotify.go

+5
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ func PlayTrack(trackUri string, contextUri string) error {
7777
return cmd.Run()
7878
}
7979

80+
func Reveal(contextUri string) error {
81+
cmd := exec.Command("osascript", "-e", fmt.Sprintf("tell application \"Spotify\" to open location \"%s\" & (activate)", contextUri))
82+
return cmd.Run()
83+
}
84+
8085
func (c *Client) Search(searchStr string, st client.SearchType, limit int) (*client.SearchResult, error) {
8186
opts := client.Options{
8287
Limit: &limit,

0 commit comments

Comments
 (0)