From bb4a1b646ef76ecbacb44314887d1322c5cbb13f Mon Sep 17 00:00:00 2001 From: Sheel Choksi Date: Thu, 27 Jul 2017 21:37:06 -0700 Subject: [PATCH] Add reveal in Spotify through mod --- alfred/alfred.go | 13 +++++++++++++ main.go | 6 ++++++ menus/menus.go | 18 ++++++++++++++++++ spotify/spotify.go | 5 +++++ 4 files changed, 42 insertions(+) diff --git a/alfred/alfred.go b/alfred/alfred.go index 2b91afa..c8baa53 100644 --- a/alfred/alfred.go +++ b/alfred/alfred.go @@ -10,6 +10,18 @@ type AlfredIcon struct { Path string `json:"path,omitempty"` } +type AlfredMod struct { + Valid bool `json:"valid,omitempty"` + Arg string `json:"arg,omitempty"` + Subtitle string `json:"subtitle,omitempty"` +} + +type AlfredMods struct { + Ctrl AlfredMod `json:"ctrl,omitempty"` + Alt AlfredMod `json:"alt,omitempty"` + Cmd AlfredMod `json:"cmd,omitempty"` +} + type AlfredItem struct { Uid string `json:"uid,omitempty"` Type string `json:"type,omitempty"` @@ -19,6 +31,7 @@ type AlfredItem struct { Autocomplete string `json:"autocomplete,omitempty"` Valid *bool `json:"valid,omitempty"` Icon AlfredIcon `json:"icon,omitempty"` + Mods AlfredMods `json:"mods,omitempty"` } type AlfredItems struct { diff --git a/main.go b/main.go index 1048714..e9b54d8 100644 --- a/main.go +++ b/main.go @@ -43,6 +43,12 @@ func main() { log.Fatal(err) return } + } else if action == "revealinspotify" { + err := spotify.Reveal(*contextPtr) + if err != nil { + log.Fatal(err) + return + } } else if action == "auth" { err := setup.LaunchAuth() if err != nil { diff --git a/menus/menus.go b/menus/menus.go index dd79b65..16096c5 100644 --- a/menus/menus.go +++ b/menus/menus.go @@ -178,6 +178,12 @@ func albumItem(album client.SimpleAlbum) alfred.AlfredItem { Icon: alfred.AlfredIcon{ Path: "icons/album.png", }, + Mods: alfred.AlfredMods{ + Ctrl: alfred.AlfredMod{ + Arg: fmt.Sprintf("--action revealinspotify --context %s", album.URI), + Subtitle: "Reveal in Spotify", + }, + }, } } @@ -205,6 +211,12 @@ func trackItem(track client.FullTrack, contextType int) alfred.AlfredItem { Path: "icons/track.png", }, Arg: arg, + Mods: alfred.AlfredMods{ + Ctrl: alfred.AlfredMod{ + Arg: fmt.Sprintf("--action revealinspotify --context %s", track.URI), + Subtitle: "Reveal in Spotify", + }, + }, } } @@ -218,6 +230,12 @@ func artistItem(artist client.FullArtist) alfred.AlfredItem { }, Valid: newFalse(), Autocomplete: fmt.Sprintf("-artist=\"%s\" ", artist.Name), + Mods: alfred.AlfredMods{ + Ctrl: alfred.AlfredMod{ + Arg: fmt.Sprintf("--action revealinspotify --context %s", artist.URI), + Subtitle: "Reveal in Spotify", + }, + }, } } diff --git a/spotify/spotify.go b/spotify/spotify.go index 97e9934..68450b7 100644 --- a/spotify/spotify.go +++ b/spotify/spotify.go @@ -77,6 +77,11 @@ func PlayTrack(trackUri string, contextUri string) error { return cmd.Run() } +func Reveal(contextUri string) error { + cmd := exec.Command("osascript", "-e", fmt.Sprintf("tell application \"Spotify\" to open location \"%s\" & (activate)", contextUri)) + return cmd.Run() +} + func (c *Client) Search(searchStr string, st client.SearchType, limit int) (*client.SearchResult, error) { opts := client.Options{ Limit: &limit,