Tutorials

XML on OS X

By: Jon Gales

There aren’t many more computer acronyms more popular than XML. Go to the bookstore
and check out the internet section—it’s all XML. What happened to plain
old HTML? It’s old hat! Most people are probably wondering, "What can this
XML thing do for me?". Well basically for most of us, it saves us time.
Lots of time.

Meet NetNewsWire
Lite
; it’s a lightweight cocoa application that you will soon fall in love
with. What it does is take in XML feeds (in a flavor known as RSS
or really simple syndication) from the sites you choose and display it in beautiful
aqua. Sound lame? How about reading 30+ sites in under 10 minutes? Most of your
favorite sites are available in RSS (Yes, even MacMerc) which makes scanning
the Mac web a cinch. Want something besides Mac news? Well there are plenty
of choices from all genres that can be added in just a few clicks right from
NNW. Have a site you want to see a feed for, but can’t find one? Well there
probably is one at NewsIsFree.com
or Syndic8.com. Below is
a screen shot of my set up, viewing MacMerc’s feed

 

nnw1 XML on OS X

If you still aren’t convinced consider the fact that Radio,
Manilla, Movable
Type
, LiveJournal,
Blogger, pMachine,
Blosxom,
PHPNuke, PostNuke
and many more Content Management Systems all support RSS by default! That comes
out to millions of sites that all support a technology that is almost unknown
to anyone out of the closely knit blogosphere.

I improved the RSS support of MacMerc to
include our story summaries (what you see on the front page) in the feed. That
means right in NetNewsWire you can see if we’ve updated, read what the stories
are about and choose what to read up on further. You can set NNW to update every
30 minutes which lets you keep up to date and still get work done icon razz XML on OS X . It’s got
a dock icon that updates like Mail’s (a little red number showing the number
of unread items).

Any site that updates daily and doesn’t support RSS should think about it. The
easiest way to add support for your site is just to use one of the web publishing
tools that support it to make your web site. That way you don’t have to sling
code yourself. However, if you’re feeling lucky here is the format that your
file should follow and a few pointers:

 

<?xml version="1.0"
encoding="ISO-8859-1" ?>
<rss version="VERSION NUMBER">
<channel>
  <title>MacMerc.com – Start using RSS</title>
  <link>http://www.macmerc.com/rss</link>
  <description>You may already be a MacMerc!</description>

  <language>en-us</language>
<item>
  <title>This is the first story</title>
  <link>http://firstlink.com</link>
  <description>This is a description of the first item!</description>

</item>
</channel>
  </rss>

I added full RSS support to my AIM
Quotes
site by following the above format. It was such a simple script it
only took a few minutes to code. I was even able to include the IM’s with their
colors. To include HTML in your feed just convert the HTML to HTML entities.
If you are writing in PHP (like I usually am) there is a function for this,
htmlentities()
.

This is really basic as far as RSS is concerned but it shows the
premises of what is going on. You’ll notice that it looks like HTML with different
tags. That’s basically what it is, RSS just is a collection of standard tags.
That’s how a reader like NetNewsWire can parse these files. Although this demo
is really simple, you can do more advanced things with it such as including
permanent links, copyright information, last build dates, and a ton of other
information. To get the scoop check out UserLand’s RSS
page
. They are busy working on version 2.0 right now!

Tips for authoring:

  • Make sure to send the headers out as text/xml or your feeds will never
    work
  • Include new lines (
    ) after each line
  • To speed things up author the xml file when things are published, not
    upon request (you’ll save a ton of CPU cycles)
  • Include a button on your web page that points to your feed, no one benefits
    from a secret feed
  • If you feel the need you can include advertising in the feeds, just add
    it to your code base. Most likely it won’t be effective but you never know.
  • If you don’t have a good statistical traffic monitor on your web server,
    build a counter into the file that is used to serve the XML. That way you’ll
    know if people are taking advantage of your feed.
  • Convert HTML to HTML Entities to make it work in your feeds.

Tips for using feeds:

  • Subscribe to LOTS of sites in the beginning, find out what you like after
    a few days. This is a good way to find new sites (NetNewsWire has a bunch
    of sites built in).
  • To add LiveJournals, just add /rss to the journal’s address. (http://www.livejournal.com/users/USERNAME/rss)
  • MacMerc is by default in the sites drawer of NetNewsWire but our syndication
    address is: http://www.macmerc.com/backend.php
  • MacMinute (our favorite Mac news site) has an unlinked feed: http://www.macminute.com/headlines.xml.
    This isn’t built into NetNewsWire yet so make sure to add this one ASAP!
  • MacUpdate (our favorite Mac Download site) has an OS X feed: http://www.macupdate.com/mommy/macsurferx.php.
    This isn’t built into NetNewsWire yet so make sure to add this one ASAP!

 

Optimize Your DeliciousExport

Brought to you by: James

Clearly, the problem with DeliciousExporter is that it exports your images as their original size and uses CSS to resize them in your browser. Why not resize these images before uploading? Why not indeed…. The following are the exact steps that I took to shrink my library from 13.8mb to 2.6mb.

1. Download and purchase EasyBatchPhoto ($18). Why purchase? Because you get a very ugly watermark thrown on every image if you don’t. Why EasyBatchPhoto? Because I’ve tried the rest and they just don’t work. Skip to step 1a, right after step 5, for special instructions on using Automator instead of EasyBatchPhoto.

2. Backup Delicious Library. You can do this by copying ~/Library/Application Support/Delicious Library/ to an external hard disk or burn a CD with that directory.

3. Now, open ~/Library/Application Support/Delicious Library/Images/ on your hard disk and delete every folder but “Plain Covers”.

4. Open your newly purchased EasyBatchPhoto. Choose whatever destination you want, set the scaling to “Stretch to fit” at 113×155 pixels, choose your desired scaling quality, set the format to “JPEG”, the quality to “80″, and make sure that “Preserve EXIF” is checked. At this point, you may want to add all of this as a preset. Why 113×155 pixels? Because that’s the size of the small, plastic-like image that will be displayed over your images in your newly exported library. Consequently, that is the size that the original images would have been resized to. Your settings should similar to the screenshot below.

ebp Optimize Your DeliciousExport

5. Find your “Plain Covers” folder at ~/Library/Application Support/Delicious Library/Images/Plain Covers/ and drag it into the small box on the top-left corner of EasyBatchPhoto. Continue through the dialogue box and your photos will begin to convert. Move onward to step 6.

Use Automator instead of EasyBatchPhoto

1a. If you have Mac OS X v10.4.x, you can use Automator instead of EasyBatchPhoto for steps 1-5.

2a. Duplicate the “Plain Covers” folder in ~/Library/Application Support/Delicious Library/ and drag this duplicate folder to your desktop.

3a. Launch Automator, select the contents of the Plain Covers duplicate, and drag them into the Workflow area.

4a. From the action area, select Preview/Scale Images and make sure that it occurs after the retrieval of the image files. Set this action to “To Size (pixels): 155″. Your settings should similar to the screenshot below.

asp Optimize Your DeliciousExport

5a. Execute the workflow and save it for later use.

6. Replace ~/Library/Application Support/Delicious Library/Images/Plain Covers/ with your newly created “Plain Covers” folder.

7. Launch Delicious Library. You will be shocked by how pixelated your cover images are, but that’s why you made a backup of your library in step 2. Now, quit Delicious Library.

8. Launch DeliciousExporter. Make sure that “Export images” is checked, enter your desired email address, and export your library.

9. Once your library is exported, open one of the .html files in your browser. Your cover images are no longer pixelated. That’s because they are exactly the size that they would have been resized to via the CSS.

10. Congratulations, your exported library is now as optimized as it could get (unless you lower the image quality any further). You may now upload your library and restore Delicious Library by replacing ~/Library/Application Support/Delicious Library/ with your backup copy.

Just for fun, here’s what mine looks like:
library Optimize Your DeliciousExport

Smarten up iTunes’ Smart Playlists with nesting

This is one of those "here’s my situation and what I did about it, if you’re even a little like my, you might give this a try" kind of tutorials.

I drive a half hour to 45 minute commute to work and I like to listen to my iPod and sing along with the music as I go until someone notices and laughs (then I pretend I’m talking to someone on my hands free cell phone …poking at the imaginary buttons on my dashboard sells the illusion, I think). The problem I had was that my iTunes library, though rather modest, is diverse and not all of the content is even music let alone stuff I’d want to sing along to.

Like anyone in this situation, I set up a playlist to hold all the music I like to listen to while driving. That was fine for a while, but as you probably realize, a playlist never changes. When I added music to my collection, I’d have to add it to any playlists I wanted it to be in by hand. To have a playlist automatically grab newly added music, it would have to be smart…like a Smart Playlist.

Smart Playlists gave me another problem. Smart as they are, they’re not bright enough to know that podcasts like Jonathan Coulton’s Thing A Week and Geoff Smith’s Ones and Os are actually music delivered via RSS–they only let me listen to them with other podcasts. If Iwas going to be able to rock out to Re: Your Brains or Digg the Code on my way to work, I was going to have to educate my Smart Playlists. It was an arduous task and maybe someone out there knows a way that makes this system seem even more laughably over complicated (and I certainly hope there is) but here’s what I did: I nested them …and then I made them even smarter.

Teach iTunes to look for audio by file type

audiofiles 20080803 101049 Smarten up iTunes Smart Playlists with nesting

The first playlist, which I titled "___Just the Audio", searches my whole iTunes Library for MP3, AAC and "MPEG audio file" formats. You may have to add a few other file formats depending on what kind of audio you have in your collection, but this worked for me.

Narrowing it down to Music

justmusic 20080803 102143 Smarten up iTunes Smart Playlists with nesting

Next, I set up a Smart Playlist to weed out the Genres and other Playlists that I don’t want to listen to on the way to work. This Smart Playlist is a long list of "is not" rules that are ended with "Playlist is ___Just the Audio". I named this one "__Just the Music".

I was getting closer; I had all my music in one Smart Playlist. I still found that I was shuffling through to a lot of songs that I just didn’t want to hear. I was at a loss because iTunes doesn’t have a rule for "Kind is what I want to hear" …or does it?

Smarten up the Smart Playlist

skippedsongs 20080803 103018 Smarten up iTunes Smart Playlists with nesting

iTunes does keep track of the songs you skip–even on your iPod. So I set up this Smart Playlist (named "_Skipped Songs") that keeps track of the songs that I’ve skipped more than four times in the last four months. To get add a point to a song’s Skip Count, you must hit the Next button no earlier than 2 seconds into the song and no later than 20 seconds in.

The smart part of this Smart Playlist comes when I apply it to one of the other ones.

The Smart Smart Playlist

magicplaylist 20080803 103735 Smarten up iTunes Smart Playlists with nesting

This is the playlist I rock out to on the way to and from work.

Each file in my iTunes Library is first checked to make sure it is in fact an audio file, then it is compared to a list of genres and playlists that I don’t want to listen to with my list’nin’ music, and finally the song’s "permanent record" is checked to see if it is a "repeat offender" in that it has been skipped repeatedly in the last little while.

This keeps me from being bothered by music I always skip while not being so strict as to put a black mark on a song I just didn’t feel like listening to that day or one I skipped accidentally. It also gives every skipped song a bit of a probationary hearing so that they get another chance to win me over in the future.

Your milage may vary.

The audio file format types, the list of restricted genres and the "four skip/four month" thing will be factors that you will have to adjust to match your personal listening tastes, the size of your library and how fast you cycle through it. This works pretty well for me, but I expect I will be making adjustments to it in the future as new factors come to light.

The real lesson here is that Smart Playlists can be played off each other to make them smarter and to better suit your needs. It’s all good.