My Quest For Notes

I’m getting a new iPod via a trade in from Smalldog. I send my battered 5 gigger to them, they give me $65 store credit for the new one. It’s actually a better deal to get the iPod photo than the generic gen 4 iPod, which stunned me. Also, as I pointed out to the Mrs, it’s likely that the Photo is going to be the baseline for all future iPods, so from an upgradability perspective, it’s better. And since I don’t plan on carrying photos on it, I get 40-gigs which means I can carry all our CDs (currently 13.4 Gigs and counting as I back ’em up) and character information to our GM’s for an RPG session.

Anyway, as I was looking into the iPod, and the possible transition from Palm to Pod (which has more to do with PalmPilot hocking the loogie to Mac and saying they won’t support us than anything else). As I puttered about the net, I determined that 90% of the software out there is for getting music off your iPod (which officially isn’t something Mac wants you to do, fine). I have FileBuddy, which I use for legit purposes (sometimes Windows and *nix CDs are insane to view on a Mac), and really I’ve backed up my iPod on my spare hard drive. (This is good since I’m sans iPod until Friday or Monday at this rate *sniff*)

What I want, sadly, is something like Plucker for my iPod. I want to download a book and have it there on my iPod. There are a few ways to do this, but generally it involves copying everything into plain text format and chunking it all out in one go.

This isn’t exactly what I want, but it’s a start. I want something to take the webpage, plus the links I want it to follow, and convert that into plain text. Then I want that plain text whacked into a note and put on my iPod. Since I want to do this on my Mac, I started by limited my search to Macintosh Applescripts (first because I have a book on it, second cause I thought that I could hack them all together). Note to the reader, I have never written my own Applescript, and while I did make one today, I doubt I would have without the examples I found on the web.

I go to TWoP a lot. They have recaps on 9-21 webpages. One of my desires is to take TWoP’s recaps I haven’t read and ‘port’ them to my iPod. So I need a script that goes to, copies it to a plain text file, and for every link that matches* (where * is a number between 2 and 99), append the new page to the text file.

I couldn’t find anything that consolidated multiple pages, but I did find a guy who had figured out how to copy selected text in Safari and save it as a file. Using that logic, I puttered about and wrote the following applescript:

set temp to display dialog "File Name (Show_2-5)" default answer ""
set filename_ to text returned of temp

set temp to display dialog "Show Number" default answer ""
set shownum_ to text returned of temp

set temp to display dialog "Recap Number" default answer ""
set recap_ to text returned of temp

set temp to display dialog "Recap Pages" default answer ""
set pages_ to text returned of temp

set twop_url to "" & shownum_ & 
	"&story=" & recap_ & "&page="

set fPath to path to desktop
set fName to filename_ & ".txt"

set myFile to open for access file ((fPath as string) & fName) �
	with write permission

repeat with counter from 1 to pages_
	tell application "Safari"
		set the URL of the front document to twop_url & counter
		delay 7
		set myData to text of the front document
	end tell
	write myData & return to myFile starting at eof
	set counter to counter + 1
	delay 2
end repeat

close access myFile

display dialog "Done!" buttons {"Okay"} default button 1

Now this works okay. Two problems I have is that sometimes the page doesn’t load in seven seconds (TWoP is a heavily hit website, this isn’t abnormal). Second problem is that the output is nasty. All I want is the ‘main’ story, but I get a lot of trash data. Now, it’s a moments work to write a BBEdit find/replace function for it, but wish I could look for the text between <span class=”story_text”> and <span> and copy THAT to a file.

Funny enough, I did find that if I change
  set myData to text of the front document
  set myData to source of the front document
if will copy over the source code! So that’s a possible avenue to research.

Still, the fact that I made it this far in one evening without knowing any Applescript is heartening. My O’Reilly Applescript book barely touching on OS X? Not so much.

%d bloggers like this: