Recently in Projects Category

outlook with itunes screenshot

Ok, here's one for the masses.

This post describes how to add info about the song currently playing in iTunes to emails you compose in Outlook. Anyone can do it!

First, create the macro. To do so:

  1. Open Outlook.
  2. From the Tools menu, select Macro, then Macros...
  3. In the Macro field, enter a name for your macro. "AddiTunesSig" is probably appropriate. [screenshot]
  4. Click "Create".
  5. A "code window" will open. This is where, in a minute, you will type the code that makes up the macro.
  6. But first, you need to tell Outlook how to talk to iTunes. To do so, go to the Tools menu and select References. Scroll down until you find "iTunes Type Library" or something similar. Select its checkbox and click OK. [screenshot]
  7. Back in the code window, you will see two lines of code: Sub AddiTunesSig() and End Sub. In between these lines, paste in the following code:
    
    
    ' purpose: opens a new mail message, 
    ' appends info re: currently playing track in iTunes
    
    Dim itunes As iTunesApp
    Dim strArtist As String
    Dim strTitle As String
    Dim strOutput As String
    Dim mail As Outlook.MailItem
    
    Set itunes = New iTunesApp
    
    'load the track info into easy-to-read variables
    strArtist = itunes.CurrentTrack.Artist
    strTitle = itunes.CurrentTrack.Name
    strAlbum = itunes.CurrentTrack.Album
    
    'assemble the signature
    strOutput = vbNewLine & "------------------------------"
    strOutput = strOutput & vbNewLine & "Now playing: " & vbCrLf _
         & strTitle & vbCrLf & strArtist & vbCrLf & strAlbum
    
    'create a new email message
    Set mail = Outlook.CreateItem(olMailItem)
    
    'put the signature in the body
    mail.Body = vbNewLine & vbNewLine & strOutput
    
    'show the message to the user
    mail.Display
    
    'clear up the memory
    Set itunes = Nothing
    
    

    See how easy programming is! [screenshot]

  8. To finish up: Click the Save button on the toolbar and close the code window.

Now, you need to add a toolbar button to your Outlook toolbar that will run this macro. To do so:

  1. Go to the Tools menu, and select Customize...
  2. In the dialog box that pops up, scroll down the left side, and click Macros. [screenshot]
  3. You will see your macro on the right ("Project1.AddiTunesSig"). Drag it up to a convenient location on your toolbar. (Next to the "New" button is probably a good place.)
  4. To rename the button, right-click the button and type the new name where it says "Name:" in the pop-up menu. "New (with music)" is probably a good name. [screenshot]
  5. Close the Customize window.

That's it! To use it, open iTunes, play a song, go back to Outlook, and click your new button. A new email will open with info about the currently playing song in the signature area.

Earlier: How to control iTunes from any Microsoft Office application.

Max OS X widget for Radio Paradise playlist

|

radio paradise widget

I made a Mac OS X Dashboard widget that displays the current playlist from RadioParadise.com, a great internet radio station. It's my first ever widget, so it's not very fancy, but it gets the job done.

The widget shows a scrollable list of the last 6 hours worth of music played, and if you click a song title, it opens the web page on RP's site dedicated to that song. Clicking the main logo takes you to RP's site. It refreshes when you show the Dashboard and you can manually refresh it by clicking the "refresh" link. I may add automatic refreshing in some future release.

Once you've downloaded the widget, unzip it by double-clicking it, then double-click the widget file. For older versions of Mac OS X, you might need to move the files into your home folder's /Library/Widgets folder first.

Apple doesn't seem to publicize this fact, but practically anyone can make a widget. Simple widgets are really just small web pages, and can be made using only HTML, JavaScript, and a couple of images. You should give it a try. I just read Apple's excellent tutorial, looked at the source code for one of their RSS-reading sample widgets, and went from there.

This widget uses JavaScript to extract data from an XML version of RP's playlist. I believe it is technically an AJAX-based widget, albeit a very simple one. A few weeks ago, I wrote a PHP script that generates an RSS feed from that XML.

I'm guessing it's trivial to convert Mac OS X widgets to Konfabulator/Yahoo! Widgets, so I will do that when I get a minute.

You may recall I half-wrote a script to do this a couple years ago, but I was mostly cribbing from some guy at Apple and really had no idea what i was doing.

Anyway, I'm taking another shot at parsing the iTunes library XML using PHP5's new "SimpleXML" library, which is a terrific feature that I never get tired of working with.

I cooked up this little script in about 10 minutes. The format of Apple's XML files makes it sort of a pain to process in the usual ways, but you can still get reasonable output with just a few lines of code. And most of that code is concerned with formatting, not the actual XML processing.

To use this script:

  1. Make sure you are using PHP5 with SimpleXML support. At Dreamhost, you can turn this on by clicking the "edit" link on the main domain management page. If you're hosting a site on your Mac, you can get an easy-to-install version of PHP5.
  2. In iTunes, select a Playlist or Library, choose "File:Export..." and export it as XML. Name it itunes.xml. (If your site is hosted on your Mac, you can just create a symlink called "itunes.xml" that points to your "iTunes Music Library.xml" file or the playlist file you just exported. Place this link in your website directory.)
  3. Upload itunes.phps and itunes.xml to your webserver.
  4. Rename itunes.phps to itunes.php.
  5. Open your browser and navigate to itunes.php.

Obviously there are lots of ways to enhance the functionality of this script, but this will get you started.

Nmap'ing Tivo

|

I don't know why I never thought of doing this before.

$ nmap -sT -sR -sV -I -O -PI -PT 192.168.1.103

results

This is probably the first of several posts that will deal with this topic.

The new Tivo system software upgrade brings many interesting features to Tivo, the most well-known of which is TivoToGo, which lets you copy the video files to your PC.

However, the software upgrade also includes a web server. This means you can interact with your Tivo via any web browser on any PC. I won't discuss all the ramifications of this right now, but one notable one is that Tivo can now produce your "Now Playing" list (a list of everything on your Tivo) as either an HTML or XML file.

The XML file is particularly exciting, because XML is very, very easy to parse nowadays. People have already parsed this XML into RSS, and I expect to be doing the same over the next couple of days.

To access your Tivo's Now Playing list as an XML file, use this URL:
https://192.168.1.103/TiVoConnect?Command=QueryContainer&Container=%2FNowPlaying
Just change the IP to the address of your Tivo, then login using the username tivo and your Media Access Key as your password.

Some of the scripts other people have released to parse this file are quite elaborate (and cool), but I wanted to demonstrate how easy it is to parse the Now Playing list into a simple HTML stream that could be easily included on any website. This took me about 10 mins to write, and it isn't very elegant.

Here you go:

<?php
function converttivodate($format, $input){
        //borrowed from A. Cassidy Napoli's Tivo_XML script
        return date($format, hexdec($input));}

$file = "nowplaying.xml";
$sxe = simplexml_load_file($file);
foreach($sxe->Item as $item) {
        $details = $item->Details;
        echo "$details->Title: $details->EpisodeTitle<br/> 
	$details->Description (" .
	converttivodate('n/d/y G:i',$details->CaptureDate) . 
	", $details->SourceStation, $details->SourceChannel)</p>\n"; } 
?>

That's about 6 lines of PHP, and it's easy to see the same (or even more) could probably be accomplished in about 2 lines. (See the update below.)

Just use include() or the Curl extensions to include the file on your site, and you're all set. This code snippet requires PHP5's SimpleXML support.

It produces something like this:

Law & Order: Merger
A scandal involving two wealthy families threatens McCoy and Carmichael's chances of a conviction in the murder of a drug-addicted girl of 15. (1/26/05 15:59, TNT, 3-0)

Seinfeld: The Doorman
A doorman (Larry Miller) tries to cause trouble for Jerry; Kramer develops a male undergarment. (1/26/05 15:29, TBS, 22-0)

Malcolm in the Middle: Reese's Apartment
Francis is determined to show his parents why they should not have kicked Reese out; Malcolm helps a football player writer a college essay. (1/26/05 14:59, WWOR, 9-0)

Here's a demo:

Update (1/27/05): Well, if you're willing to sacrifice readability in the code, you can implement the above with just 2 lines of PHP. I just took out the extra function call and variable assignments from the code above, and wound up with two lines.

About this Archive

This page is a archive of recent entries in the Projects category.

NYC is the previous category.

Sports is the next category.

Find recent content on the main index or look in the archives to find all content.

Powered by Movable Type 4.0