Hier bin ich wieder einmal mit einer anderen Frage zu iTunes AppleScript. Ich habe ein funktionierendes Skript, in dem Sie ein Werk auswählen (mehrere iTunes-„Lieder“) und ihm mitteilen, wie die Werkmetadaten für diese Auswahl eingestellt werden sollen. Sie sagen ihm auch, wo der Bewegungsname im Songnamen beginnt, und es kopiert alles nach dieser Position in das Bewegungs-Tag, mit Ausnahme aller römischen Ziffern. Es nummeriert natürlich auch die Bewegungen.
Hier ist der Code dafür:
tell application "iTunes"
set sel to selection of front browser window
if sel is {} then
try
display dialog "Nothing is selected…" buttons {"Quit"} with icon 0
end try
return
end if
set c to (count of sel)
set songName to (get name of item 1 of sel)
set workName to display dialog "Edit for Work name and then click OK." default answer songName --prompt for work name
set movementLength to display dialog "Edit to everything except the movement name. Do not include the roman numeral if one is present. If an arabic numeral is present, include it." default answer songName --prompt for movement length
repeat with i from 1 to c --set the movement numbers
set thisTrack to item i of sel
set songName to (get name of thisTrack)
set work of thisTrack to text returned of workName
set movement number of thisTrack to i
set movement count of thisTrack to c
set movement of thisTrack to my delRomNum(text ((length of text returned of movementLength) + 1) thru (length of songName) of songName as string) -- copy movement text from song name and delete roman numerals
end repeat
end tell
on delRomNum(t) -- the perl command search and delete any roman numeral (must be a word followed by the period and a space character)
do shell script "/usr/bin/perl -pe 's/\\b[IVXLCDM]+\\b. //g' <<< " & quoted form of t
end delRomNum
Sie können meinen Beitrag zu diesem Skript hier sehen: Find-and-replace AppleScript for iTunes Track Names
Jedenfalls ist dieses Skript für meine Verwendung (ich verarbeite viele klassische Tracks) jetzt nicht effizient genug geworden! Mit dem obigen Skript muss ich jede einzelne Arbeit auswählen und sie entsprechend für die Arbeit und dann für die Bewegung zuschneiden.
Was ich jetzt gerne erstellen würde, ist ein Skript, das den gesamten Prozess für mehrere Werke auf einmal ausführen kann, sagen wir, ein ganzes Album.
Es müsste jede Spur finden, die diese enthielt, I.
und sie als Ausgangspunkt für das oben skizzierte Skript festlegen, und auch die Position davon ermitteln I.
und die Work- und Movement-Tags für diese bestimmte Arbeit entsprechend trimmen - z. B. alles vor I.
und die der Raum davor würde als Werk gesetzt werden, und alles danach würde als Bewegung gesetzt werden.
Ich kann sehen, dass ich das tun muss, aber ich bin zu sehr ein AppleScript-Noob, um es tatsächlich zu implementieren! Für mich besteht die eigentliche Herausforderung ohnehin darin, festzustellen, ob eine Zeichenfolge innerhalb einer anderen Zeichenfolge liegt (z. B. prüfen, ob sie I.
innerhalb des Songnamens ist) und ihre Position innerhalb des Songnamens zu finden. Wenn ich wüsste, wie man diese beiden Dinge macht, könnte ich wahrscheinlich den Rest des Drehbuchs schreiben!
Irgendwelche Hinweise/Ideen wären sehr hilfreich. Und ich hoffe, meine Beschreibung macht Sinn. Danke!
Hinweis: Obwohl ich den Schlüsselteil beantwortet habe und den Rest des Skripts selbst schreiben kann, werde ich eine Beispieleingabe/-ausgabe hinzufügen.
Verwenden Sie is in
, um zu prüfen, ob „ I. “ im Songnamen enthalten ist, etwa so: if " I." is in someString
.
Verwenden Sie den offset
Befehl, um seine Position innerhalb des Songnamens zu erhalten
Hier ist ein Beispiel
set songName to (get name of thisTrack)
if " I." is in songName then -- " I." is inside this song name
set {theWork, theMovement} to my splitText(songName, " I.") -- split the string to get the Work and the Movement
end if
on splitText(t, theSearchString)
set x to the offset of theSearchString in t
set a to text 1 thru (x - 1) of t -- everything before theSearchString would be set as the work
set b to text x thru -1 of t -- this part would be set as the movement
return {a, b}
end splitText
Hier ist also mein vollständiges Skript, basierend auf der anderen Antwort, die gegeben wurde.
Ich weiß, dass meine Antwort höchstwahrscheinlich verworren und nicht effizient ist, aber es funktioniert!
tell application "iTunes"
set sel to selection of front browser window
if sel is {} then
try
display dialog "Nothing is selected…" buttons {"Quit"} with icon 0
end try
return
end if
set theSearchString to text returned of (display dialog "Enter the characters between the work name and movement name, for the first movement. Include spaces:" default answer ": I. ")
set c to (count of sel)
set songName to (get name of item 1 of sel)
set movementNumber to 0
set movementOffset to 0
set theSearchString_no_rn to my delRomNum(theSearchString)
repeat with i from 1 to c --set the movement numbers
set thisTrack to item i of sel
set songName to (get name of thisTrack)
if theSearchString is in songName then -- " I. " is inside this song name
set movementOffset to the offset of theSearchString in songName
set movementNumber to 0
end if
set theMovement to text (movementOffset + (length of theSearchString_no_rn)) thru -1 of songName -- this part would be set as the movement
set theWork to text 1 thru (movementOffset - 1) of songName -- everything before theSearchString would be set as the work
set movementNumber to movementNumber + 1
set movement number of thisTrack to movementNumber
set movement of thisTrack to my delRomNum(theMovement)
set work of thisTrack to theWork
end repeat
end tell
on delRomNum(t) -- the perl command search and delete any roman numeral (must be a word followed by the period and a space character)
do shell script "/usr/bin/perl -pe 's/\\b[IVXLCDM]+\\b. //g' <<< " & quoted form of t
end delRomNum