Created
January 11, 2009 22:07
-
-
Save relrod/45816 to your computer and use it in GitHub Desktop.
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
| #!/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^ | |
| 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. The song lasts " & (round ((duration of current track)/60)) & " minutes and " & (round ((duration of current track) mod 60)) & "seconds. " & player position & " seconds have already been played." | |
| 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