Better iTunes Data Insert

I’ve updated my Insert iTunes Data (HTML) script for generating a block of text that describes the current playing iTunes track. This version links to the iTunes Music Store, rather than Google. It is relatively smart, in that the track name link also has the artist name, and the album name does too, as long as the album isn’t a compilation. The only (slight) bug is that the track name seems to need to be just the way iTMS displays it, so having (Live) might stuff up a link. This might be only if there isn’t a Live version in the iTMS.

I Can’t Tell You Why (Live) • Eagles • Hell Freezes Over ★★★★★

Code after the jump.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
    -- Insert some data about the currently playing iTunes track into browser.
    
    property star : «data utxt2605» as Unicode text
    property half : «data utxt00BD» as Unicode text
    property quarter : «data utxt00BC» as Unicode text
    property threeq : «data utxt00BE» as Unicode text
    property browser : "Firefox"
    property URLprefix : "itms://phobos.apple.com/WebObjects/MZSearch.woa/wa/advancedSearchResults?"
    
    on run {}
    	
    	tell application "System Events"
    		try
    			get process "iTunes"
    		on error
    			return "No Track"
    		end try
    	end tell
    	
    	tell application "iTunes"
    		set theTrack to current track
    		set theArtist to artist of theTrack
    		set theAlbum to album of theTrack
    		set theRating to rating of theTrack
    		set theComp to compilation of theTrack
    		set theTrack to name of theTrack
    		--set trackInfo to {theTrack, theArtist, theAlbum, theRating}
    	end tell
    	
    	set trackLink to "<a href='" & URLprefix & "songTerm=" & HTMLify(theTrack) & "&amp;artistTerm=" & HTMLify(theArtist) & "'>" & theTrack & "</a>"
    	set artistLink to "<a href='" & URLprefix & "artistTerm=" & HTMLify(theArtist) & "'>" & theArtist & "</a>"
    	if theComp is true then
    		set theArtist to "" -- No Artist if album is compilation!
    	end if
    	set albumLink to "<a href='" & URLprefix & "albumTerm=" & HTMLify(theAlbum) & "&amp;artistTerm=" & HTMLify(theArtist) & "'>" & theAlbum & "</a>"
    	
    	set theString to "<p class='itunes'> " & trackLink & " • " & artistLink & " • " & albumLink & " " & myRating(theRating) & "</p>"
    	
    	set the clipboard to theString
    	
    	tell application browser
    		activate
    		tell application "System Events" to keystroke "v" using {command down}
    	end tell
    end run
    
    on HTMLify(someText)
    	set someText to replace(someText, "&", "&amp;")
    	set someText to replace(someText, "\"", "&quot;")
    	set someText to replace(someText, "<", "&lt;")
    	set someText to replace(someText, ">", "&gt;")
    	set someText to replace(someText, " ", "+")
    	set someText to replace(someText, "'", "&apos;")
    	return someText
    end HTMLify
    
    on replace(theText, find, replace)
    	-- Nice replace function
    	set OldDelims to AppleScript's text item delimiters
    	set AppleScript's text item delimiters to find
    	set newText to text items of theText
    	set AppleScript's text item delimiters to replace
    	set theResult to newText as text
    	set AppleScript's text item delimiters to OldDelims
    	return theResult
    end replace
    
    on myRating(theRating)
    	set theResult to ""
    	repeat 5 times
    		if theRating ≥ 20 then
    			set theResult to theResult & star
    		else if theRating ≥ 10 then
    			set theResult to theResult & half
    		end if
    		set theRating to theRating - 20
    	end repeat
    	return theResult
    end myRating

One More Time • Daft Punk • Triple J Hottest 100 - Volume 9 ★★★

Searching Zen

I googled for HTMLify Applescript, wanting to find out some simple code for how to escape the text in an AppleScript string, so I can pass it as arguments to a URL. My site came up with the top link. I was hoping for a better solution to the one I had come up with!

Unrated Tracks

I’ve been busily rating all of my iTunes tracks, and consider that I’ve done a very good job. My Unrated playlist (Rating is 0; Played Count is 0; Genre does not contain Classical; Podcast is false) has only 224 tracks. My total library is 7741 tracks, so it’s about 97% done. Not counting Classical tracks and Podcasts, obviously.

Actually, if I take this into account, my Music Library is only 5962 tracks, and I’ve rated about 96%.

Anyway, you get the picture. An overwhelming number of my tracks are rated. So now, I just sit back, and count the money as it rolls in let iTunes choose my music.

I’ve got a Smart Playlist called Party Shuffler, which I set my Party Shuffle to use as the source, and turn on Play higher rated songs more often. The Party Shuffler playlist has the following Logic:

  • Genre is not Classical
  • Last Played is not in the last 3 days
  • Genre is not Holiday
  • Comment does not contain re-import
  • Genre is not Books & Spoken
  • Genre is not Interview
  • Match only checked songs
  • Live Updating

I might be able to get rid of some of the Genre stuff, by having the Skip when shuffling item checked on various tracks, but then I’d need to remember to do this to new music I import.

Oh, and I keep my rating window open, and every now and then re-rate the track that’s playing - especially if I’ve decided I don’t like the track quite so much anymore.

Wipe Out • The Beach Boys • Still Cruisin' ★★

Commenting Bug

I’m not sure, but I think my script is doing something that stops comments going through the first time you submit them. I’ve only noticed it on my blog: except I just noticed it on another blog when I tried to comment. When I repeated the comment, it worked fine. Also, I think when I’ve already commented and then add another comment during the same session, it all works fine. Maybe that’s why I’m not getting too many comments anymore. Either that, or I’m just not posting stuff that’s interesting enough.

Turn It Around Again • Alexkid • [Chillout Sessions 8][2] ★★★

[2]: http://www.google.com/search?q=%22Chillout Sessions 8%22

Foreign Adsense Ad

I had the following Adsense Ad on a page I viewed from my own site tonight: I don’t even know what it’s trying to sell! I think it’s something to do with a chat system. Let’s ask google:

Free Cat Accesses Direct Dialogue free simply! www.Chat-Land.Org Free Cat www.Chat-Land.Org

Oh, excellent! I’d forgotten that Chat means Cat in French! Someone’s giving away cats, and for some reason, my site got picked! I gotta get one! Free talking, and a Free Cat. • But seriously, why am I getting a French Ad on my site? Have I written anything in my blog about France, or in French? How does Google Adsense even know I did a little bit of French at Uni to try and meet girls (well, now I know how Google knows this…).

Dr Karl uses a Mac!

Dr. Karl from Triple J uses a Mac. He talked about using Spotlight to index and search his files on his computer during the last 5 minutes of the February 23rd edition of his Radio segment.

Rating Podcasts

The iPod doesn’t allow for rating of a Podcast - I guess it assumes they are throwaway items, rather than worth keeping.

Resizing Images in AppleScript/Automator

I’ve already written a small Automator application that will resize an image to 640x480, but what about if I want to change it to a different size. There’s no way to set the resize amount on the fly in Automator, so I thought, it should be easy to do it in AppleScript. Except, for some reason, Preview.app isn’t scriptable. I do have Image Events.app floating around (not sure if it’s a standard part of the system), which can do what I want.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
    tell application "Finder"
    	set sels to selection
    end tell
    
    
    repeat with sel in sels
    	tell application "Image Events"
    		set img to open sel as alias
    		set dims to dimensions of img
    	end tell
    	
    	set cursize to "Current Size of Image: " & (first item of dims as integer as text) & " x " & (last item of dims as integer as text)
    	
    	display dialog cursize
    end repeat

This gets the current size, but I’m yet to find an easy way to get input from the user, and resize it according to this. I’m sure it can’t be that tricky!

Renovations Update

I know that a couple of people read this who are a bit interested in how my house renovations are coming along. Jaq and I have spent the last couple of months preparing the main living area: Kitchen, Dining, Lounge and Study. We knocked out about 3m of a wall which will have a table inserted into it, and replaced the floorboards, ceilings and fixed the walls. We have spent the last weekends doing some final prep for painting, and now painting the kitchen/study area. The edges of the wall where we had cut a big hole look great: we’ve use a Rondo Shadowline product to get lovely 10mm shadow lines around the framing, and now it’s all painted, you can’t see where the original plaster ends, and the cornice cement and top-cote start. It does look really nice. Similarly, where the old Air Conditioner was is almost invisible from the inside now. We’ll build the kitchen ourselves - Ikea have some good kitchen cabinets, and we’ll just get the doors made up. The kitchen will flow through into the study, although it will have a seperator that does distinguish between the two. We also got some new furniture in the past couple of days: a Hans Wegner Daybed and some nice Danish beds. Furniture Auctions are the best place to find great bargains.

Referer Counts

I’m just going to quickly stroke my own ego a little bit. Apologies. In my Popular Posts list, I have about 1800 page reads of various items, but only stuff that is viewed as a single page is recorded here. Thus, hits on the main site page, or a category index page, or even a daily page with only one post on it, would not count as a view. I assume that this value refers to the past month, as it doesn’t seem to increase forever. If I look at my referer list for the past month, I see there have been just over 9000 page views on my site. This includes all page views, such as those discussed above that are not counted. That means 7000 views are either index page views, or more interestingly, _Long Tail _posts. That is, posts that are not in the top band of popular posts.