私はiTunesで曲の選択を削除するには、私のAppleScriptをどのように修正すればよいですか?

StackOverflow https://stackoverflow.com/questions/1455011

  •  12-09-2019
  •  | 
  •  

質問

私はすべての選択したトラックを削除するため、以下の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

私は、単一の項目を選択すると、それが正常に動作しますが、私は複数を選択したときに私が取得:(エラー番号-1728)「を選択の項目2の位置を取得できません」。私はトラックを削除することによって、選択へのスクリプトのインデックスが破損しているためであると考えています。

私が最初に削除されるように、トラックの私自身のリストを作ってみたいと思っます:

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

しかし、私は、「アプリケーション 『のiTunes』の選択項目1の項目1を取得できません。」取得私はこの問題は、「this_trackは、」クラスのトラックのオブジェクトが、選択の項目ではありませんだと思います。どのように私は、選択項目から実際のトラックオブジェクトを取得できますか?

あなたが解決策が表示されない場合は、

、私はデバッグのヒントや他の提案を歓迎します。

役に立ちましたか?

解決

変数this_trackは、オブジェクト指定子への参照です。あなたは、囲まれたオブジェクトの指定を取得するためにcontentsプロパティを使用する必要があります。同じことは、第二のループ内の変数pairにアクセスするための事実です。 referenceにクラスリファレンス部href="http://developer.apple.com/mac/library/documentation/AppleScript/Conceptual/AppleScriptLangGuide" rel="nofollow noreferrer">アップルスクリプト言語ガイド

もう一つの問題は、リストto_deleteが構築されている方法に存在します。ステートメントset to_delete to to_delete & pairはペアのリストが、フラットなリストを生成しません。 listにクラスリファレンス部href="http://developer.apple.com/mac/library/documentation/AppleScript/Conceptual/AppleScriptLangGuide" rel="nofollow noreferrer">アップルスクリプト言語ガイド

ここでは、これらのバグが削除されている2番目のスクリプトのバージョンでは、です

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 {contents of this_track, floc}
                    copy pair to end of to_delete
                end if
            end try
        end repeat
        repeat with pair in to_delete
            set the_track to item 1 of contents of pair
            set floc to item 2 of contents of pair
            delete the_track
            my delete_the_file(floc)
        end repeat
    end if
end tell
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top