Delete remote playlist
  • Select a shared playlist and delete it--the tracks it contains will not be deleted

We just got finished creating a new playlist on a remote user's iTunes. You may want to delete it after you're finished with it.

This is a pretty simple script and it requires several of the handlers we've already used. The main routine in the run handler detects which shared playlist is selected and then an osascript is ssh'd to the remote iTunes that deletes that playlist (the full listing is on the next page; this is just the run handler):

tell application "iTunes"
	set selectedPlaylist to (get view of front browser window)
	if (kind of (get container of selectedPlaylist) is shared library) then
		tell selectedPlaylist
			set playlistName to (get name)
			set sharedLibName to (get name of container)
		end tell
		-- == optional "Are You Sure?" dialog
		display dialog "Are you SURE you want to delete the playlist \"" & playlistName & ¬
			"\" from \"" & sharedLibName & "\"?" & return & return & ¬
			"This action cannot be undone." buttons {"Cancel", "OK"} default button 2 with icon 2
		display dialog "Selected playlist is not a remote shared playlist." buttons {"Cancel"} ¬
			default button 1 with icon 0 giving up after 15
	end if
end tell

my get_login_info()

	set osaCom to quoted form of ¬
		("osascript -e 'tell application \"iTunes\" to delete playlist \"" & my escape_single_quotes(playlistName) & "\"'")
	do shell script ("ssh " & remAddr & space & osaCom)
on error m number n
	log m
	log n
end try

The selected playlist (view of front browser window) is a shared playlist if the kind of its container (a source) is shared library. We get the name of the playlist and the name of the source to use in the get_login_info() handler. Then an osascript uses the playlist name (with single-quotes escaped) in the delete command.

This is one of the few times that we must reference the remote playlist by its name; the persistent ID will not be the same on the local and remote iTunes, like it was for tracks. So, be very careful using this script. If there is more than one playlist with the selected playlist's name (a rare but apt possibility), the wrong one may get deleted.

(If 100% accuracy is an issue, then the script could display a choose from list box after gathering the names and persistent IDs of the remote user's iTunes via ssh.)

Site contents © 2001 - 2021 (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 interrupt the one doing it.