Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Our Archives > General Archives > Delicious Monster > AppleScript: Simple list of titles

 
AppleScript: Simple list of titles
Thread Tools
Delicious Monster
Dedicated MacNNer
Join Date: Jun 2006
Status: Offline
Dec 11, 2007, 02:51 PM
 
After yet another user asking me for a way to print a simple list of titles from Delicious Library I whipped up an AppleScript to create a title list. Feel free to adapt it for your own use, and if you are an AppleScript guru, feel free to add your corrections.

set pathToXMLFile to POSIX path of ((path to application support from user domain) & "Delicious Library:Library Media Data.xml" as string)

tell application "System Events"
tell contents of XML file pathToXMLFile
-- Get selected shelf element
set rootElement to first XML element
set shelvesElement to a reference to XML element "shelves" of rootElement
set shelfNames to value of XML attribute "name" of every XML element of shelvesElement
set selectedShelfName to (choose from list shelfNames with prompt "Select a shelf:" without multiple selections allowed) as text
set selectedShelfElement to a reference to (first XML element of shelvesElement where the value of its XML attribute "name" is selectedShelfName)

-- For each shelf item, find the matching medium and write out its title
set shelfElements to a reference to XML elements of selectedShelfElement
set itemElements to a reference to XML element "items" of rootElement
set pathToTextFile to choose file name
set textFile to open for access pathToTextFile with write permission
set eof textFile to 0 -- clear file just in case
repeat with shelfElement in shelfElements
try
set mediumUUID to value of XML attribute "uuid" of shelfElement
set itemElement to (a reference to (first XML element of itemElements where the value of its XML attribute "uuid" is mediumUUID))
set itemTitle to value of XML attribute "title" of itemElement
write itemTitle & return to textFile
end try
end repeat
close access textFile

display alert "Done creating title list" as informational giving up after 10
end tell
end tell
     
 
   
Thread Tools
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 05:10 AM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,