Close a Playlist Window and Select Its Playlist
If it really drives you crazy that after closing a playlist window iTunes is compelled to put focus on the entire Music library, use the following script to close the frontmost playlist window and thereafter select the playlist it had contained in the main window:
tell application “iTunes”
set frontPlaylistWindow to front playlist window
set thePlaylist to view of frontPlaylistWindow
Click on the little AppleScript icon above to open the script in Script Editor at your house—don’t copy the text in the browser.
Save the script as a Compiled “.scpt” with Script Editor named whatever you like in your [home]/Library/iTunes/Scripts/ folder so it can be launched from the iTunes Script menu. You may want to assign it a keyboard shortcut.
When run, it will get a reference to the front playlist window; if none is open, the script will fail silently. It will proceed to get a reference to the playlist contained by the playlist window, close the playlist window and finally select (reveal) the playlist.