Hi, I’m currently working on this Applescript to create an XML file from 21 separate iTunes playlists for an online music library. I’ve run into a couple of stumbling blocks and was hoping someone might have an answer.
-
I would like the main section to repeat. Is there a way to enclose both the “getting info from iTunes part” and the “write to a text file part” in a repeat statement? I have to have an “end tell” before the “on write_to_file” so enclosing everything in a repeat statement doesn’t work.
-
As the script repeats, when it gets to the last track of the first playlist (“subgenre_1”), it will move on to the next playlist (“subgenre_2”). I’d like to define a vairable called “current_plist” that will change through the different playlist names I defined (e.g. “01. Test Name 1”, “02. Test Name 2”, etc.) so that the line:
set track_name to (get name of file track Plist_count of user playlist subgenre_1)
would be:
set track_name to (get name of file track Plist_count of user playlist current_plist)
I tried:
set current_plist to (“subgenre_” & Plist_count)
but that returns a literal value of “subgenre_1”. I’d like it to be seen as the VARIABLE “subgenre_1” which would then return a literal value of “01. Test Name 1”.
I hope that makes some kind of sense.
Thanks.
--set these variables
set subgenre_1 to "01. Test Name 1"
set subgenre_2 to "02. Test Name 2"
set subgenre_3 to "03. Test Name 3"
set subgenre_4 to "04. Test Name 4"
set subgenre_5 to "05. Test Name 5"
set subgenre_6 to "06. Test Name 6"
set subgenre_7 to "07. Test Name 7"
set subgenre_8 to "08. Test Name 8"
set subgenre_9 to "09. Test Name 9"
set subgenre_11 to "10. Test Name 10"
set subgenre_12 to "11. Test Name 11"
set subgenre_13 to "12. Test Name 12"
set subgenre_14 to "13. Test Name 13"
set subgenre_15 to "14. Test Name 14"
set subgenre_16 to "15. Test Name 15"
set subgenre_17 to "16. Test Name 16"
set subgenre_18 to "17. Test Name 17"
set subgenre_19 to "18. Test Name 18"
set subgenre_20 to "19. Test Name 19"
set subgenre_21 to "20. Test Name 20"
set Plist_num to 21
--end set variables
--begin script
set Plist_count to 1
tell application "iTunes"
get count of file tracks of user playlist subgenre_1
set track_name to (get name of file track Plist_count of user playlist subgenre_1)
set track_genre to (get grouping of file track Plist_count of user playlist subgenre_1)
set track_subgenre to (get genre of file track Plist_count of user playlist subgenre_1)
--write to TEXT file
set this_data to "<genre>" & track_genre & "</genre>" & return & "<subgenre>" & track_subgenre & "</subgenre>" & return & "<track>" & track_name & "</track>"
set this_file to (((path to desktop folder) as text) & "Library.xml")
my write_to_file(this_data, this_file, true)
end tell
on write_to_file(this_data, target_file, append_data)
try
set the target_file to the target_file as text
set the open_target_file to ¬
open for access file target_file with write permission
if append_data is false then ¬
set eof of the open_target_file to 0
write this_data to the open_target_file starting at eof
close access the open_target_file
return true
on error
try
close access file target_file
end try
return false
end try
end write_to_file