Skip to content

Instantly share code, notes, and snippets.

@andreasjansson
Last active March 11, 2016 18:37
Show Gist options
  • Save andreasjansson/ae878fddcd8cf6e45db7 to your computer and use it in GitHub Desktop.
Save andreasjansson/ae878fddcd8cf6e45db7 to your computer and use it in GitHub Desktop.
;; spotify-play-track
;; osx only 🙈
(defun osascript (script)
(shell-command-to-string (concat "osascript -e " (shell-quote-argument script))))
(defun spotify-uri-bounds-of-thing-at-point ()
(save-excursion
(skip-chars-backward "a-zA-Z0-9:")
(cons (point) (progn (skip-chars-forward "a-zA-Z0-9:") (point)))))
(put 'spotify-uri 'bounds-of-thing-at-point
'spotify-uri-bounds-of-thing-at-point)
(defun spotify-play-track (track-uri)
(interactive (list (read-string "Track URI: " (thing-at-point 'spotify-uri))))
(osascript (format "tell application \"Spotify\" to play track \"%s\"" track-uri))
(sit-for 0.5)
(message (string-trim-right (osascript "tell application \"Spotify\" to get artist of current track & \" - \" & name of current track"))))
(define-key global-map (kbd "<f8>") 'spotify-play-track)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment