Ecco qualcosa di veloce per iniziare. Se vuoi anche cambiare il nome del file, allora è facile aggiungere nella sezione copia ...
set dpath to "/some/path/some/where/"
set qdpath to quoted form of dpath
# Choices of apps to use depending what files you have
# mp3
set tapp3 to "/usr/local/bin/id3v2 -t "
# m4a
set tapp4 to "/usr/local/bin/mp4tags -s "
tell application "iTunes"
set iSel to selection
repeat with trk in iSel
set aloc to location of trk
set loc to quoted form of (POSIX path of aloc)
set tname to name of trk
set tartist to artist of trk
tell application "Finder"
set fname to name of file (aloc as alias)
set fext to name extension of file (aloc as alias)
end tell
# Copy
try
do shell script "cp " & loc & " " & qdpath
on error eStr
display dialog eStr
return
end try
# New path
set qnewfile to quoted form of (dpath & fname)
# Choose right tool...
if fext is "mp3" then
set tapp to tapp3
else if fext is "m4a" then
set tapp to tapp4
else
display dialog "Unknown file type. Don't know what to use..."
return
end if
# Tag
try
do shell script tapp & "'" & tartist & " - " & tname & "' " & qnewfile
on error eStr
display dialog eStr
return
end try
end repeat
end tell
Poiché non ti piace usare gli strumenti da riga di comando e Applescript non ha il supporto integrato per i tag audio, sei rimasto con iTunes. Quindi ecco una versione di quanto sopra con solo usando iTunes,
set dpath to "/some/path/"
set qdpath to quoted form of dpath
set listname to "MyList"
set adpath to (POSIX file dpath as alias)
# Copy selected itunes files
tell application "iTunes"
set iSel to selection
repeat with trk in iSel
set tloc to location of trk
set atloc to quoted form of (POSIX path of tloc)
set tname to name of trk
set tartist to artist of trk
tell application "Finder"
set fname to name of file (tloc as alias)
set fext to name extension of file (tloc as alias)
try
duplicate file tloc to folder adpath with replacing
on error eStr
display dialog "Copy failed for track: " & tname & return & return & eStr
return
end try
end tell
end repeat
end tell
# Get audio files in selected folder
# -- alas no recursive search results without a lot more code... :(
set afiles to {}
tell application "Finder"
repeat with ext in {".mp3", ".m4a"}
set l to (every file in adpath whose name contains ext)
repeat with f in l
set end of afiles to (f as text)
end repeat
end repeat
end tell
# Add to iTunes and change Tags...
#
tell application "iTunes"
if not (user playlist listname exists) then
make new user playlist with properties {name:listname}
end if
set view of window 1 to playlist listname
# Add and change tracks' names
repeat with afile in afiles
try
set tid to (add afile to playlist listname)
end try
set tname to name of tid
set aname to artist of tid
set name of tid to ((aname & " - " & tname) as text)
end repeat
# Clean up now?
set r to display dialog "Done. " & return & return & ¬
"Remove tracks and list now?" as text buttons {"No", "Yes"} with icon note
if button returned of r is not "Yes" then
return
end if
# Remove playlist tracks from library; will remove from playlist(s) too
# -- WARNING: If track added multiple times all entries will be removed!!
repeat with t in (every track in playlist listname)
try
set pid to persistent ID of t
# Thanks Doug Adams, it was driving me nuts....
delete (some file track of library playlist 1 whose persistent ID is pid)
end try
delay 1
end repeat
delay 30
# Remove all tracks from playlist v2
try
# Fast mass deletion - Thx to http://apple.stackexchange.com/a/56463
# but only removes from playlist.. they remain in the library!
#delete tracks of playlist listname
end try
try
delete playlist listname
end try
end tell