Ich möchte in iTunes basierend auf einem bestimmten Ordner eine intelligente Wiedergabeliste erstellen (ich verwalte meine Medienbibliothek manuell).
Ist das in ITunes 12 irgendwie noch möglich (auch wenn es um Scripting geht)?
Ich glaube nicht. Sie scheinen Informationen aus der iTunes-Datenbank/Bibliothek zu verwenden, wie könnten sie also etwas über einen zufälligen Ordner auf Ihrem Computer wissen?
Sie könnten es zwar entweder mit Ordneraktionen oder mit launchd simulieren, aber beides ist nicht perfekt.
Ordneraktionen funktionieren nur für neue Dateien in einem Verzeichnis und stellen eine Liste der Dateien bereit, die dem auszuführenden Programm/Skript hinzugefügt wurden, damit Sie wissen, was sich geändert hat.
launchd hingegen führt Ihr Skript/Ihre App aus, wenn sich etwas in den Ordnern ändert, Sie können mehrere überwachen, aber es wird Ihnen nicht sagen, welcher Pfad geändert wurde oder wie - hinzugefügt oder entfernt usw.
Ich würde mich persönlich für launchd entscheiden. Wenn es sich nur um einen einzelnen Ordner handelt, können Sie ihn fest in Ihr Skript codieren.
Was das Skript betrifft, versuchen Sie Folgendes ...
set dpath to "/some/path/test/"
set qdpath to quoted form of dpath
set listname to "MyList"
set adpath to (POSIX file dpath as alias)
# Get audio files in selected folder
# -- alas no recursive search results without a lot more code... :(
# -- or use mdfind or other command line tool using `do shell script...`
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 alias)
end repeat
end repeat
end tell
tell application "iTunes"
if not (user playlist listname exists) then
make new user playlist with properties {name:listname}
end if
# Built a list of existing list tracks so we don't have duplicates...
set itracks to {}
try
set itracks to (get location of every track in playlist listname)
end try
set view of window 1 to playlist listname
# Add not already in playlist
repeat with afile in afiles
if afile is not in itracks then
try
set tid to (add afile to playlist listname)
end try
end if
end repeat
# Remove any tracks from the itunes playlist not in the folder
# and from the iTunes database else they still show up as invalid tracks...
set iItems to (every track in playlist listname)
set iLib to library playlist named "Library"
repeat with iItem in iItems
set loc to location of iItem
if loc is not in afiles then
set pid to persistent ID of iItem
log "Removing: " & loc
try
# 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 if
end repeat
end tell
Es macht tatsächlich Spaß zu sehen, wie es auf das Hinzufügen und Entfernen von Dateien aus dem Ordner reagiert. Genießen.... :)
Abschließend empfehle ich Ihnen, diese URLs zu überprüfen.
www.macissues.com/2015/02/02/how-to-use-launchagents-to-monitor-folder-contents-in-os-x/apple.stackexchange.com/questions/6658/
Hecke
launchd
.Vic