Reading and displaying file tags from iTunes

Hi

I am working on a Cocoa Applescript App to append text/tags to the comments field of the currently playing track in iTunes. This basically consists of a HUD Window with buttons that append the text via Applescript. I would like to have a section of the HUD Window that displays the text currently written to the comments field, but I’m not sure how to go about this. Would someone be able to point me in the right direction?

Thanks

Nick

What part are you unsure of?

Well, presumably I would be able to use AppleScript to call the tags, but I’m not sure how to script this. And then I’m not sure how to display the results of this in a text area object in my HUD Window.

Have a look in the general AS forum, or a place like Doug’s scripts for iTunes. Or just look in iTunes’s dictionary – it’s not hard.

Once you have the tag, you call setValue_ on the text field.

Thanks

I added this applescript, based on another similar project I came across on the internet:

property commentTag : missing value

on CommentsTag_(sender)
	tell application "iTunes"
		tell commentTag to setValue_(current track's comment)
	end tell
end CommentsTag_

I then added a text field to the HUD Window, and linked it with the commentTag outlet in the App Delegate, but no comments Tags are showing up when I build and run.

I know ‘current track’s comment’ returns the comments field of the currently playing track in iTunes, but I’m not sure about the construction of the rest of the applescript

Do it like this:

    on CommentsTag_(sender)
        tell application "iTunes"
             set theComment to current track's comment
        end tell
       tell commentTag to setValue_(theComment)
   end CommentsTag_

iTunes knows nothing about setValue_.

Thanks.

Still no comments showing though. Do I need to link both the ‘CommentTag’ outlet and the ‘CommentsTag’ received action to the text field? At the moment the Text field is showing as blank with a cursor in it. Perhaps I am not using the correct object. It won’t be a field for entering any text, just displaying text.

When/how do you want the comments updated? Something has got to trigger it.

I’d like the field to display the comments tag for the currently playing track in iTunes. So presumably I would need a script that refreshes every second to pull in this information. Then when a track changes it would automatically update.

Every second is probably too often – it might be pushing things. But you need either an NSTimer or performSelector:withObject:afterDelay:. Hunt around here and you’ll see they’ve been covered before.