dougscripts.com

Tips and Info

September 16 2009 - 8:51 am

Get Current Track from iTunes LP

When you're playing an iTunes LP the Command-L shortcut to reveal/select the track in iTunes doesn't work. Unless.

Place the iTunes LP "booklet" in its own playlist (select it and press Shift-Command-N) and open that playlist in its own window by double-clicking the name of the playlist (or choose "Open in New Window" by Control-clicking the playlist name). Double-click the booklet to open the iTunes LP in the playlist window just opened. Now you have access to the main iTunes browser while the iTunes LP stuff is playing in the separate window.

This script will emulate the Command-L shortcut providing the iTunes LP is in a separate window:

tell application "iTunes"
	if player state is stopped then return
	set pID to (get current track's persistent ID)
	set mLib to (some playlist whose special kind is Music)
	reveal (some track of mLib whose persistent ID is pID)
end tell


September 6 2009 - 8:21 pm

Target QuickTime Player by application id

If you've got a script that needs to target QuickTime Player in Snow Leopard you probably really want to target "QuickTime Player 7". Otherwise, if you target "QuickTime Player" the QuickTime Player X app will run and it doesn't have the AppleScript Goodness like QTP7. However, if the script also has to run in Leopard, you have to target "QuickTime Player"--without the "7". But you don't need to write two scripts.

In OS 10.5 and later you can target an app by its application id. I remember seeing that in the AppleScript Release Notes for 10.5 thinking "Hmm. Now how can I use that" and never really thought of anything. Until I needed to access QTP in both 10.5 and 10.6.

This tell block:

tell application id "com.apple.quicktimeplayer"
	-- do something in QuickTime Player
end tell


...will target "QuickTime Player" in OS 10.5 and "QuickTime Player 7" in OS 10.6. The application id is the same for each, so it makes no difference what their names are. And the AppleScript architecture is virtually the same in both operating systems. (Remember that "QuickTime Player 7" is an optional install either during installation or from the "Optional Installs" folder on your installation disc.)

"QuickTime Player X" is a drastically different version of the player app and scripts written for QTP7 will not play well with it. However, it is scriptable to a modest extent. Its application id is "com.apple.QuickTimePlayerX" in case you need to target QTPX specifically.

July 13 2009 - 11:35 am

DIY: Remote Management Assortment, Part 5

I've added a Part 5 to DIY: Remote Management Assortment that describes how to create and delete playlists on a remote user's iTunes with ssh and osascript. If you haven't been following along in this series of projects, you may want to start at the beginning; this newest addition builds on routines and concepts from earlier in the series.

June 24 2009 - 4:29 pm

DIY: iTunes Remote Management Assortment

DIY: Remote Management Assortment is a tutorial suggesting several methods of manipulating iTunes files among users on a network, with particular emphasis on using AppleScript to swing passwordless ssh, rsync, scp, osascript, and other utilities. Rather than develop a batch of scripts for you to download (and have to support), you can use the fundamentals described here as the basis for your own AppleScript projects.

June 10 2009 - 8:15 am

It's a None/All Bug

The "none" bug I described yesterday turns out to be a bit more extensive: it's a "none/all" bug.

iTunes 8.2 introduces a bug whereby the the use of the none value with special kind and video kind, and the all value with song repeat in AppleScripts compiled in iTunes 8.1.1 and earlier will not work correctly in iTunes 8.2. I understand that Apple is aware of this situation and assume a fix will be forthcoming in a future version.

If you encounter an error caused by this bug, chances are you are running iTunes 8.2 and the script had been compiled and saved with an earlier version of iTunes.

The fix is to open the script in Script Editor, look for chevron-bound raw constants, and replace them with the appropriate bare-word value. For example, if you see «constant eSpKkSpN» change this to none. (I'm afraid I don't know what the raw constant for "all" is, but it would appear with a song repeat command; song repeat takes the values "off", "one", and "all"). Then re-save the script; it will compile referencing iTunes 8.2 aete and will work fine. Such recompiled scripts, however, will then not work with pre-iTunes 8.2.

March 16 2009 - 7:46 pm

iTunes AppleScript Keyboard Shortcuts Activate Twice

Correspondent Peter Kappesser noticed that under iTunes 8.1 AppleScripts to which he had assigned keyboard shortcuts (via the Keyboard Shortcuts tab in Keyboard & Mouse of System Preferences) would be activated twice when launched by the keyboard shortcut. Thus, they will perform their task twice in a row. I can verify it happens at my house, too. File a bug report.

March 11 2009 - 9:12 pm

iTunes DJ is Still Party Shuffle

Although you will see it listed as "iTunes DJ" in iTunes 8.1, it's the same thing as "Party Shuffle" (AppleScript-wise it has the same playlist special kind) with a few new behaviors.

January 13 2009 - 2:52 pm

NEW: Change Hidden iTunes Preferences

Change Hidden iTunes Preferences is an application that will let you invoke some so-called "hidden" iTunes preferences: Show "Library" playlist, Show genre while browsing, Allow half-stars in ratings, Show arrow links -- to either search the iTunes Store or search your library, Load complete iTunes Store preview before playing, Play songs while importing or converting, and Create file names with track number. Some of these preferences, as some users may recognize, used to be available in iTunes' Preferences. Others, like the "Library" and half-stars prefs, have recently been discovered. This is for use with iTunes 8 or better only.

The download disk image contains the actual application (which is not an AppleScript) and an AppleScript to launch the app from your iTunes Script menu. Make sure you copy both of them off the .dmg.

January 1 2009 - 1:59 pm

Show the iTunes Library Old School

I'm not certain if this has been mentioned anywhere--I haven't seen it--but I found the defaults command for displaying the entire iTunes library. Remember when you actually had a large playlist named "Library", before Apple split it up into--what I call--"Master" libraries of "Music", "Movies", "Podcasts", and so on? The "Library" listed everything in your iTunes library. Well, you can get that back using this command in Terminal:

defaults write com.apple.iTunes show-library-playlist -bool TRUE

Quit iTunes before entering the command. When you restart you'll have a new playlist named "Library" at the top of your Source list, above "Music".

If you want to remove the "Library" again, use this command in Terminal:

defaults write com.apple.iTunes show-library-playlist -bool FALSE

There is a second preference called "hide-library-playlist", which I at first thought would have to be set in tandem with the opposite of "show-library-playlist", but this doesn't seem necessary. In fact, you can set one or the other, apparently, and get the desired result; that is setting "show-library-playlist" to TRUE or setting "hide-library-playlist" to FALSE amounts to the same thing. Also, for AppleScript purposes, this playlist can be referenced as library playlist 1; it always could be, but now it is visible.

December 30 2008 - 2:40 pm

Artificial Skip Counts/Skip Dates

Recently, Mac OS X Hints ran a hint about overcoming iTunes' criteria for increasing a track's skipped count and skipped date via AppleScript. See, iTunes will only increase these properties if the track is advanced to another track during the first 2 to 20 seconds of play, and the hint tried to work around this so the skip properties could be increased anytime during play. Nothing personal, but I thought the OP at Mac OS X Hints kind of went overboard. This script on the Missing Menu Commands page will get the job done without a lot of fuss.

Site contents © 2001 - 2024 (that's right: 2001) Doug Adams and weblished by Doug Adams. Contact support AT dougscripts DOT com. About.
All rights reserved. Privacy.
AppleScript, iTunes, iPod, iPad, and iPhone are registered trademarks of Apple Inc. This site has no direct affiliation with Apple, Inc.
The one who says "it cannot be done" should not be interrupting the one who is doing it.