>You need to look at the dictionary to understand the terms that Music.app expects (File -> Open Dictionary, then select the app).
I was aware of the dictionary thanks-I was just trying to get my head around the properties syntax.
>You might have been confused by the fact I used almost identical names for my variables as the properties they're assigned to. That's just a convention, and your variable can be anything at all:
This wasn't the issue as it turns out, my error as I hadn't put a space in where I should've done initially!
>The trickier issue is deleting them from the Music library - as you've seen, when you convert a track like this you get both the original .wav and the lossless copy of the track in your library.
...
>Note that this could delete other tracks that have no artist data, so be careful. You can refine this, though, by adding other clauses
>tell application "Music"
delete (every track whose artist is "" and kind is "WAV audio file")
end tell
This trick worked perfectly well for me as I don't have keep any .wav files in this music library.
The script works absolutely great for me now, in terms of:
getting a folder of .wav files
importing these into the music application
converting these to apple lossless
deleting the redundant .wav files from the music library.
I have now adopted your code (much appreciated) and incorporated this within a short Automator script using a 'Run AppleScript' action, having looked at other examples. This allows me to drop a folder of files onto the app for processing. It also now gets around the Automator 'time-out' error -1712.
You will see from the code that I have simply given the album name a placeholder name – the reason being I still need to 'Set the Info of the Music Songs' and artwork, so it's easier to do it from a single interface once converted and in Music, rather than asking for these individually when the AppleScript code runs. Plus I also need to run a separate script that embeds the track numbering for the album.
I'm currently trying to work out how to pass the required information from the AppleScript code into 'Set the Info of the Music Songs' Automator action...but this is something to keep me occupied.
As you are probably aware, it's significantly quicker to encode files external to music by selecting the files from a Finder > Control click > Encode Selected Audio Files, but this requires more clicking and selection from menus.
The Automator & AppleScript code may not be the fastest or most elegant solution and can probably be refined, but it works and in any case, this is all new to me and the start of a fruitful journey hopefully. Many Thanks.
on run {input, parameters}
--get the source files
set source_files to {}
repeat with f in input
set end of source_files to contents of f
end repeat
set _albumname to "Lossless"
tell application "Music"
-- save the current encoder settings to restore later
set _prev_enc to (get current encoder)
-- set the app to use lossless
set current encoder to encoder "Lossless Encoder"
-- loop through the files
with timeout of 3600 seconds -- one hour limit to import the folder
--set new_tracks to add source_files
set new_tracks to convert source_files
end timeout
-- update the imported tracks with the album/artist info
repeat with each_track in new_tracks
tell each_track
set album to _albumname
end tell
end repeat
-- clean up and delete .wav files from music library
tell application "Music"
delete (every track whose artist is "" and kind is "WAV audio file")
end tell
set current encoder to _prev_enc
end tell
return source_files
return input
end run