Ok, for iTunes (which IMHO is far better for manually managing music) here's the Apple Script.
iTunes via
Retroactive even works on Ventura.
There are two parameters to be set:
- the list of device names that the script should look for
- optional: the resolution of the artwork depending on the device (matched only by the name of the device)
Once the artwork of a track on the device has been updated, the flag "artworked;" gets appended to the (local) comment. This way on the next run only newly added files are processed.
AppleScript:
--> Force update of all artwork on iPod/iPhone/iPad from local iTunes library #####
#######################################################
set knownDevices to {"insert_device_name_1","insert_device_name_2", "insert_device_name_3"}
set iPodClassicPixelWidth to 240 # matched if device name contains "iPod-Classic"
set iPodPixelWidth to 480 # matched if device name contains "iPod"
set iPhonePixelWidth to 640 # matched if device name contains "iPhone"
#######################################################
fix_iPod_artwork_mod(knownDevices, iPodClassicPixelWidth, iPodPixelWidth, iPhonePixelWidth)
##### Module: Detect connected iPod #####
on locateiPods(knownDevices)
-- check if an item of knownDevices is connected
tell application "iTunes"
repeat with i from 1 to the count of the knownDevices
set this_known_iPod to item i of the knownDevices
try
set known_ipod_src to (some source whose name is this_known_iPod)
set this_iPod to this_known_iPod
return this_iPod
go to end
end try
end repeat
end tell
--
try
tell application "System Events" to display dialog "No known iDevices are mounted." buttons {"Cancel"} with icon 0 giving up after 15
error number -128
on error
error number -128
end try
end locateiPods
##### Module: Force update of artwork on iPod from local library #####
on fix_iPod_artwork_mod(knownDevices, iPodClassicPixelWidth, iPodPixelWidth, iPhonePixelWidth)
tell application "iTunes"
set the_iPod to my locateiPods(knownDevices) -- this is a path
set the_iPod_name to the_iPod
set ipod_src to some source whose name is the_iPod_name
set allTracks to every track in library playlist 1 of ipod_src
set totalTracks to count of allTracks
set lib to name of library playlist 1
set oldArtworkList to every track in library playlist 1 of ipod_src whose (comment does not contain "artworked")
if oldArtworkList is not {} then
tell application "System Events" to display notification "Refreshing artwork…"
repeat with i from 1 to count of oldArtworkList
set currentTrack to item i of oldArtworkList
set fileType to kind of currentTrack as string
if i ≤ 100 and i mod 50 is 0 then # push notification at 50 and 100 tracks
display notification "Cover-Scan iPod: " & i & "/" & totalTracks
else
if i mod 100 is 0 then # push notification every 100 tracks
display notification "Cover-Scan iPod: " & i & "/" & totalTracks
end if
end if
-- get track info for matching with main library
set name1 to currentTrack's name
set album1 to currentTrack's album
set artist1 to currentTrack's artist
set tracknumber1 to currentTrack's track number
if album1 is not "Voice Recordings" then
try
-- get current track's ID in iTunes
set newID to (database ID of first track of library playlist 1 whose (album is album1) and (artist is artist1) and (name is name1) and (track number is tracknumber1))
-- scale Artwork-file depending on device
if the_iPod_name contains "iPod" or the_iPod_name contains "iPhone" then
-- define resolution
if the_iPod_name contains "iPod-Classic" then
set pixelWidth to iPodClassicPixelWidth
else
if the_iPod_name contains "iPod" then set pixelWidth to iPodPixelWidth
if the_iPod_name contains "iPhone" then set pixelWidth to iPhonePixelWidth
end if
-- get the raw bytes of the artwork into a var
tell application "iTunes" to tell artwork 1 of (some track of library playlist 1 whose database ID is newID)
set srcBytes to raw data
end tell
-- export Artwork to temp. file
set tempImage to (((path to desktop) as text) & "temp_artwork")
#set tempImage to ("Volumes:customVolume:customFolder:temp_artwork")
-- write to file
set outFile to open for access file tempImage with write permission
-- truncate the file
set eof outFile to 0
-- write the image bytes to the file
write srcBytes to outFile
close access outFile
-- import and scale Artwork-file depending on device
set tempImagePath to quoted form of POSIX path of tempImage
do shell script "sips --resampleWidth " & pixelWidth & " " & tempImagePath
-- embed resized artwork into audio file
tell application "iTunes"
set data of artwork 1 of currentTrack to read file tempImage as picture
end tell
-- remove temp. file
do shell script "rm -rf " & tempImagePath
else
set data of artwork 1 of currentTrack to (get raw data of artwork 1 of (some track of library playlist 1 whose database ID is newID))
end if
set commentOld to currentTrack's comment
set currentTrack's comment to "artworked;" & commentOld
display notification "Updated artwork for: " & artist1 & " - " & name1 & " (" & album1 & ")"
#on error errMsg
# display dialog "Track not found in local library or not local artwork: " & artist1 & " - " & name1 & " (" & album1 & ")"
end try
end if
end repeat
end if
end tell
tell application "System Events"
display dialog the_iPod_name & ":" & return & "Finished updating artwork." giving up after 3
end tell
end fix_iPod_artwork_mod
#####################################################