Created
November 20, 2011 01:18
-
-
Save jdan/1379654 to your computer and use it in GitHub Desktop.
Spotify Remote
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'sinatra' | |
get '/' do | |
head = '<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js"></script> | |
<script type="text/javascript"> | |
$(document).ready(function() { | |
$("a").click(function(e) { | |
e.preventDefault(); | |
$.get($(this).attr("data")); | |
if ($(this).attr("data") == "pause") { | |
$(this).attr("data", "play"); | |
$(this).text(">"); | |
} else if ($(this).attr("data") == "play") { | |
$(this).attr("data", "pause"); | |
$(this).text("||"); | |
} | |
}); | |
}); | |
</script>' | |
body = '<div style="font-size: 400%; text-decoration: none"><a href="#" data="prev"><<</a> - <a href="#" data="pause">||</a> - <a href="#" data="next">>></a></div>' | |
return head + body | |
end | |
get '/next' do | |
`osascript -e 'tell application "Spotify" to next track'` | |
end | |
get '/prev' do | |
`osascript -e 'tell application "Spotify" to previous track'` | |
end | |
get '/play' do | |
`osascript -e 'tell application "Spotify" to play'` | |
end | |
get '/pause' do | |
`osascript -e 'tell application "Spotify" to pause'` | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment