Я создал следующий AppleScript для удаления всех выбранных треков:
property okflag : false
-- check if iTunes is running
tell application "Finder"
if (get name of every process) contains "iTunes" then set okflag to true
end tell
if okflag then
tell application "iTunes"
if selection is not {} then
repeat with this_track in selection
try
try
set cla to class of this_track
set floc to (get location of this_track)
delete this_track
on error error_message number error_number
display alert error_message message ("Error number: ") & error_number & "."
end try
if cla is file track then
my delete_the_file(floc)
end if
end try
end repeat
end if
end tell
end if
to delete_the_file(floc)
try
-- tell application "Finder" to delete floc
do shell script "mv " & quoted form of POSIX path of (floc as string) & " " & quoted form of POSIX path of (path to trash as string)
on error
display dialog "Track deleted, but could not be moved to trash" buttons {"Hmm"} default button 1 with icon 1
end try
end delete_the_file
Хорошо работает, когда я выбираю один элемент, но когда я выбираю более одного, я получаю: «Не удается найти местоположение элемента 2 выбора» (номер ошибки -1728) Я полагаю, это потому, что при удалении дорожки индекс скрипта в выделении поврежден.
Я подумал, что сначала попробую составить собственный список треков, которые нужно удалить:
tell application "iTunes"
if selection is not {} then
set to_delete to {}
repeat with this_track in selection
try
set cla to class of this_track
set floc to (get location of this_track)
if cla is file track then
set pair to {this_track, floc}
set to_delete to to_delete & pair
end if
end try
end repeat
repeat with pair in to_delete
set the_track to item 1 of pair
set floc to item 2 of pair
delete the_track
my delete_the_file(floc)
end repeat
end if
end tell
Но тогда я получаю «Не могу получить пункт 1 из пункта 1 выбора приложения« iTunes »». Я думаю, что проблема заключается в том, что this_track является не объектом класса Track, а элементом выбора. Как получить фактический объект отслеживания из элемента выбора?
Если вы не видите решения, я буду рад советам по отладке или любым другим предложениям.