Thanks very much.
I have now got an applescript that will take the playlist and music files from this exported network share and import them into iTunes on my Mac.
For this to work the Device Configuration must be set to
* Library Playlists
* Destination directory = \
* Force Relative Paths
* Use Unicode
* Use Linux Folder Separator
Code: Select all
(*
*)
on readFile(unixPath)
set foo to (open for access (POSIX file unixPath))
set txt to (read foo for (get eof foo))
close access foo
return txt
end readFile
tell application "Finder"
activate
set playlistFolder to choose folder with prompt "Please choose the folder containing the Playlists"
set playlistFiles to name of every file of folder playlistFolder
set playlistcount to count of files in folder playlistFolder
--display dialog playlistcount
end tell
--
--
tell application "iTunes"
activate
set root to playlistFolder as string
repeat with i from 1 to the playlistcount
-- the filename
set theFile to item i of playlistFiles
--if type of theFile is file then
set theSuffix to text ((offset of "." in theFile) + 1) thru -1 of theFile
--display dialog theSuffix
if theSuffix = "m3u" then
tell application "iTunes"
-- build the playlist name
set theName to text 1 thru ((offset of "." in theFile) - 1) of theFile
display dialog "Playlist to import " & theName giving up after 10
-- find or create the playlist in iTunes
try
set new_playlist to (some playlist whose name is theName)
on error errmesg number errn
--display dialog errmesg & return & return & "error number: " & ¬
(errn as text)
log "Create " & theName
set new_playlist to (make new user playlist with properties {name:theName})
end try
end tell
-- read the file contents
set thePlaylist to {root & theFile} as alias
my readFile(POSIX path of thePlaylist)
set thecontents to result
set thelines to every paragraph of thecontents
my checkLInes(thelines)
set thePathCount to result
-- loop through the lines
tell application "iTunes"
set i to 1
-- Get the list of tracks
set theTracks to (get a reference to every track of new_playlist)
set k to count of items of theTracks
--display dialog k
--display dialog thePathCount
if not k = thePathCount then
repeat with j from 1 to the count of thelines
set thetrack to (item j of thelines) as string
if not thetrack = "" then
set thetrack to POSIX path of (root) & thetrack
repeat while (i ≤ k)
-- Find the path on this track
set theLocation to (location of (item i of theTracks)) as text
set theLocation to POSIX path of theLocation
--log i & k
--log thetrack & " " & theLocation
-- compare the new and old location
if not theLocation = thetrack then
-- remove the offending track
log "delete " & i & theLocation
delete item i of theTracks
set k to k - 1
else
exit repeat
end if
end repeat
if not (i ≤ k) then
try
set thetrack to POSIX file thetrack as string
log "Add " & thetrack
--display dialog "Add " & thetrack
add thetrack to new_playlist
end try
end if
set i to i + 1
end if
end repeat
end if
end tell
end if
end repeat
end tell
on checkLInes(thelines)
set k to 0
repeat with j from 1 to the count of thelines
set thetrack to (item j of thelines) as string
if not thetrack = "" then
set k to k + 1
end if
end repeat
return k
end checkLInes
While we're on the subject of wishlisting it would be good to be able to trigger scripts before or after synchronisation too.
Thanks very much. :-)
I have now got an applescript that will take the playlist and music files from this exported network share and import them into iTunes on my Mac.
For this to work the Device Configuration must be set to
* Library Playlists
* Destination directory = \
* Force Relative Paths
* Use Unicode
* Use Linux Folder Separator
[code](*
*)
on readFile(unixPath)
set foo to (open for access (POSIX file unixPath))
set txt to (read foo for (get eof foo))
close access foo
return txt
end readFile
tell application "Finder"
activate
set playlistFolder to choose folder with prompt "Please choose the folder containing the Playlists"
set playlistFiles to name of every file of folder playlistFolder
set playlistcount to count of files in folder playlistFolder
--display dialog playlistcount
end tell
--
--
tell application "iTunes"
activate
set root to playlistFolder as string
repeat with i from 1 to the playlistcount
-- the filename
set theFile to item i of playlistFiles
--if type of theFile is file then
set theSuffix to text ((offset of "." in theFile) + 1) thru -1 of theFile
--display dialog theSuffix
if theSuffix = "m3u" then
tell application "iTunes"
-- build the playlist name
set theName to text 1 thru ((offset of "." in theFile) - 1) of theFile
display dialog "Playlist to import " & theName giving up after 10
-- find or create the playlist in iTunes
try
set new_playlist to (some playlist whose name is theName)
on error errmesg number errn
--display dialog errmesg & return & return & "error number: " & ¬
(errn as text)
log "Create " & theName
set new_playlist to (make new user playlist with properties {name:theName})
end try
end tell
-- read the file contents
set thePlaylist to {root & theFile} as alias
my readFile(POSIX path of thePlaylist)
set thecontents to result
set thelines to every paragraph of thecontents
my checkLInes(thelines)
set thePathCount to result
-- loop through the lines
tell application "iTunes"
set i to 1
-- Get the list of tracks
set theTracks to (get a reference to every track of new_playlist)
set k to count of items of theTracks
--display dialog k
--display dialog thePathCount
if not k = thePathCount then
repeat with j from 1 to the count of thelines
set thetrack to (item j of thelines) as string
if not thetrack = "" then
set thetrack to POSIX path of (root) & thetrack
repeat while (i ≤ k)
-- Find the path on this track
set theLocation to (location of (item i of theTracks)) as text
set theLocation to POSIX path of theLocation
--log i & k
--log thetrack & " " & theLocation
-- compare the new and old location
if not theLocation = thetrack then
-- remove the offending track
log "delete " & i & theLocation
delete item i of theTracks
set k to k - 1
else
exit repeat
end if
end repeat
if not (i ≤ k) then
try
set thetrack to POSIX file thetrack as string
log "Add " & thetrack
--display dialog "Add " & thetrack
add thetrack to new_playlist
end try
end if
set i to i + 1
end if
end repeat
end if
end tell
end if
end repeat
end tell
on checkLInes(thelines)
set k to 0
repeat with j from 1 to the count of thelines
set thetrack to (item j of thelines) as string
if not thetrack = "" then
set k to k + 1
end if
end repeat
return k
end checkLInes
[/code]
While we're on the subject of wishlisting it would be good to be able to trigger scripts before or after synchronisation too.