Skip to content

Instantly share code, notes, and snippets.

@relrod
Created January 11, 2009 22:35
Show Gist options
  • Save relrod/45824 to your computer and use it in GitHub Desktop.
Save relrod/45824 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
sub _osascript
{
my $script = shift;
require IPC::Open2;
my( $read, $write );
my $pid = IPC::Open2::open2( $read, $write, 'osascript' );
print $write $script;
close $write;
my $data = do { local $/; <$read> };
return $data;
}
$bold = chr(2);
sub np
{
my $script = qq^
on zeroPad(theNumber)
set theString to ""
if theNumber is less than 10 then set theString to "0"
set theString to theString & theNumber
return theString
end zeroPad
tell application "System Events"
if exists process "iTunes" then
tell application "iTunes"
set theCurrentState to player state
if theCurrentState is paused then
"is not listening to anything."
else if theCurrentState is stopped then
"is not listening to anything."
else
"is listening to $bold" & name of current track & "$bold by $bold" & artist of current track & "$bold. " & (round ((player position)/60)) & ":" & zeroPad ((round ((player position) mod 60))) & "/" & (round ((duration of current track)/60)) & ":" & zeroPad ((round ((duration of current track) mod 60))) & ". "
end if
end tell
else
"is not listening to anything."
end if
end tell
^;
my $a = _osascript( $script );
for ( $a ) {
s/^\s+//;
s/\s+$//;
}
IRC::command( "/me " . $a );
return 1;
}
IRC::register( "np", "1.0", "", "" );
IRC::add_command_handler( "np", "np" );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment