Forums
New posts
Articles
Product Reviews
Policies
FAQ
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Menu
Log in
Register
Install the app
Install
Forums
Apple Computing Products:
macOS - Operating System
Script to duplicate Apple Lossless iTunes library as MP3 files
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="nick_harambee" data-source="post: 1120002" data-attributes="member: 27767"><p>Thanks.</p><p></p><p>I now have a script that does everything I want, including deleting superfluous tracks from the destination folder, except where there are characters in the track name in iTunes that aren't supported in filenames in Finder (i.e. ? / <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite1" alt=":)" title="Smile :)" loading="lazy" data-shortname=":)" />. This means that all tracks which contain these characters in the name are re-converted every time I run the script.</p><p></p><p>Is there a way I wonder of adapting the script so that when it is checking to see if the track already exists in the destination folder, it replaces these characters in the track name with an _ (which is what happens in Finder) for the purposes of the comparison?</p><p></p><p>Nick</p><p></p><p>[CODE]tell application "iTunes"</p><p> activate</p><p> </p><p> set sel to every track of playlist "1 music library"</p><p> set encoderBackup to name of current encoder</p><p> set this_folder to "Macintosh HD:Users:nick:Desktop:music:" as text</p><p> set current encoder to encoder "MP3 Encoder"</p><p> </p><p> repeat with this_track in sel</p><p> set trackComposer to this_track's composer</p><p> set trackAlbum to this_track's album</p><p> set trackName to this_track's name</p><p> tell application "Finder"</p><p> </p><p> set path1 to "Macintosh HD:Users:nick:Desktop:music:" & trackComposer as text</p><p> </p><p> if not (folder path1 exists) then</p><p> make new folder at this_folder with properties {name:trackComposer}</p><p> end if</p><p> </p><p> local path2</p><p> set path2 to this_folder & trackComposer & ":" & trackAlbum as text</p><p> </p><p> if not (folder path2 exists) then</p><p> make new folder at path1 with properties {name:trackAlbum}</p><p> end if</p><p> </p><p> if exists file (path2 & ":" & trackName & ".mp3") then</p><p> set file2 to (path2 & ":" & trackName & ".mp3") as alias</p><p> set modDate to modification date of file2</p><p> set modDate2 to this_track's modification date</p><p> if not (modDate is greater than modDate2) then</p><p> my convertTrack(this_track, path2)</p><p> end if</p><p> else</p><p> my convertTrack(this_track, path2)</p><p> end if</p><p> end tell</p><p> </p><p> end repeat</p><p> </p><p> set current encoder to encoder encoderBackup</p><p> display dialog "done"</p><p>end tell</p><p></p><p>on convertTrack(this_track, path2)</p><p> tell application "iTunes"</p><p> try -- skip on failure</p><p> set new_track to item 1 of (convert this_track)</p><p> set loc to new_track's location</p><p> -- move the file to new location</p><p> do shell script "mv " & (quoted form of POSIX path of loc) & " " & (quoted form of POSIX path of path2 as string)</p><p> </p><p> -- delete the track</p><p> delete new_track</p><p> end try</p><p> end tell</p><p>end convertTrack[/CODE]</p></blockquote><p></p>
[QUOTE="nick_harambee, post: 1120002, member: 27767"] Thanks. I now have a script that does everything I want, including deleting superfluous tracks from the destination folder, except where there are characters in the track name in iTunes that aren't supported in filenames in Finder (i.e. ? / :). This means that all tracks which contain these characters in the name are re-converted every time I run the script. Is there a way I wonder of adapting the script so that when it is checking to see if the track already exists in the destination folder, it replaces these characters in the track name with an _ (which is what happens in Finder) for the purposes of the comparison? Nick [CODE]tell application "iTunes" activate set sel to every track of playlist "1 music library" set encoderBackup to name of current encoder set this_folder to "Macintosh HD:Users:nick:Desktop:music:" as text set current encoder to encoder "MP3 Encoder" repeat with this_track in sel set trackComposer to this_track's composer set trackAlbum to this_track's album set trackName to this_track's name tell application "Finder" set path1 to "Macintosh HD:Users:nick:Desktop:music:" & trackComposer as text if not (folder path1 exists) then make new folder at this_folder with properties {name:trackComposer} end if local path2 set path2 to this_folder & trackComposer & ":" & trackAlbum as text if not (folder path2 exists) then make new folder at path1 with properties {name:trackAlbum} end if if exists file (path2 & ":" & trackName & ".mp3") then set file2 to (path2 & ":" & trackName & ".mp3") as alias set modDate to modification date of file2 set modDate2 to this_track's modification date if not (modDate is greater than modDate2) then my convertTrack(this_track, path2) end if else my convertTrack(this_track, path2) end if end tell end repeat set current encoder to encoder encoderBackup display dialog "done" end tell on convertTrack(this_track, path2) tell application "iTunes" try -- skip on failure set new_track to item 1 of (convert this_track) set loc to new_track's location -- move the file to new location do shell script "mv " & (quoted form of POSIX path of loc) & " " & (quoted form of POSIX path of path2 as string) -- delete the track delete new_track end try end tell end convertTrack[/CODE] [/QUOTE]
Verification
Post reply
Forums
Apple Computing Products:
macOS - Operating System
Script to duplicate Apple Lossless iTunes library as MP3 files
Top