Skip to content

Commit

Permalink
Add reveal in Spotify through mod
Browse files Browse the repository at this point in the history
  • Loading branch information
sheelc committed Jul 28, 2017
1 parent 80c4881 commit bb4a1b6
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
13 changes: 13 additions & 0 deletions alfred/alfred.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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 {
Expand Down
6 changes: 6 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
18 changes: 18 additions & 0 deletions menus/menus.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
},
}
}

Expand Down Expand Up @@ -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",
},
},
}
}

Expand All @@ -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",
},
},
}
}

Expand Down
5 changes: 5 additions & 0 deletions spotify/spotify.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit bb4a1b6

Please sign in to comment.