Skip to content

Instantly share code, notes, and snippets.

@soh335
Created November 11, 2011 08:17
Show Gist options
  • Save soh335/1357491 to your computer and use it in GitHub Desktop.
Save soh335/1357491 to your computer and use it in GitHub Desktop.
use strict;
use warnings;
use Amon2::Lite;
my %actions = (
"start" => qq(tell application "Keynote" \nstart\n end tell),
"stop" => qq(tell application "Keynote" \nstop slideshow\n end tell),
"next" => qq(tell application "Keynote" \nshow next\n end tell),
"back" => qq(tell application "Keynote" \nshow previous\n end tell),
);
get '/' => sub {
my ($c) = @_;
$c->render('index.tt');
};
get '/api' => sub {
my ($c) = @_;
my $res = { result => "error" };
if ( my $action = $actions{$c->req->parameters->{action}} ) {
my $err = `/usr/bin/osascript -e '$action'`;
$res->{result} = $err ? $err : "ok";
}
$c->render_json( $res );
};
__PACKAGE__->load_plugin('Web::JSON');
__PACKAGE__->to_app;
__DATA__
@@ index.tt
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script src="http://www.google.com/jsapi"></script>
<script type="text/javascript">google.load("jquery", "1.7");</script>
<meta name="viewport" content="width=device-width" />
<script>
$(function() {
$.each( [ "start", "stop", "next", "back" ], function(i, val) {
$("#" + val).click(function() {
$.getJSON("/api", { "action": val }, function(json) {
console.log(json);
});
});
});
});
</script>
</head>
<body>
<input type="button" id="start" value="start" />
<input type="button" id="stop" value="stop" />
<input type="button" id="next" value="next" />
<input type="button" id="back" value="back" />
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment