1

ファイルを自動的に iTunes に追加し、メタデータを埋める簡単な AppleScript を作成しました。エディターから直接実行すると動作しますが、iTunes から実行すると「AppleEvent Timed Out」が発生します。

コードは次のとおりです。

set mainFolder to choose folder

tell application "Finder"
    -- Loop through all shows
    set shows to every folder of mainFolder
    repeat with show from 1 to count of shows

        -- Set Show Name
        set showName to name of item show of shows

        -- Set Artist
        display dialog "Who is the artist for " & showName & "?" default answer showName
        set showArtist to the text returned of the result

        -- Set Genre
        display dialog "What is the genre for " & showName & "?" default answer ""
        set showGenre to the text returned of the result

        -- Loop through all season
        set seasons to every folder in item show of shows
        repeat with season from 1 to count of seasons

            set seasonName to name of item season of seasons

            -- Set Season Number
            set seasonNumber to text 1 thru ((offset of "-" in seasonName) - 2) of seasonName as integer

            -- Set Year
            display dialog "What year was Season " & seasonNumber & " of " & showName & " in?" default answer "2012"
            set showYear to the text returned of the result

            -- Set Season Name      
            set seasonName to text ((offset of "-" in seasonName) + 2) thru ((offset of "." in seasonName) - 1) of seasonName as text

            -- Set Total Episodes in Season
            set totalEpisodes to count of every file in item season of seasons

            -- Loop through all episodes
            set episodes to every file in item season of seasons
            repeat with episode from 1 to count of episodes

                set episodeName to name of item episode of episodes

                -- Set Episode Number
                set episodeNumber to text 1 thru ((offset of "-" in episodeName) - 2) of episodeName as integer

                -- Set Episode Name
                set episodeName to text ((offset of "-" in episodeName) + 2) thru ((offset of "." in episodeName) - 1) of episodeName as text

                tell application "iTunes"
                    set newAddition to (add (item episode of episodes as alias))
                    tell newAddition
                        set video kind to TV show
                        set name to episodeName
                        set album to seasonName
                        set track number to episodeNumber
                        set track count to totalEpisodes
                        set disc number to "1"
                        set disc count to "1"
                        set show to showName
                        set season number to seasonNumber
                        set episode number to episodeNumber

                        -- Manual Entries
                        set artist to showArtist
                        set genre to showGenre
                        set year to showYear


                        -- Change episode ID based on season and episode number
                        if (seasonNumber < 10) then
                            if (episodeNumber < 10) then
                                set episode ID to ("S0" & seasonNumber as text) & "E0" & episodeNumber as text
                            else
                                set episode ID to ("S0" & seasonNumber as text) & "E" & episodeNumber as text
                            end if
                        else
                            if (episodeNumber < 10) then
                                set episode ID to ("S" & seasonNumber as text) & "E0" & episodeNumber as text
                            else
                                set episode ID to ("S" & seasonNumber as text) & "E" & episodeNumber as text
                            end if
                        end if

                    end tell -- End newAddition
                end tell -- End iTunes
            end repeat -- End Episode Repeat
        end repeat -- End Season Repeat
    end repeat -- End Show Repeat
end tell -- End Finder Repeat
4

2 に答える 2

0

これが私がそれを解決した方法です:

スクリプトではなくアプリとして保存します。

ここから解決策を得ました: http://forums.ilounge.com/applescripts-itunes-mac/245120-need-help-add-tracks-files-via-applescript.html

なぜそれをしているのかわかりません.try-catch、timeoutを使ってみました...それでもうまくいきませんでした. アプリとしては動くのに!?

于 2012-10-08T22:58:11.023 に答える
0

オフセットとファイル名のさまざまなコンポーネントを計算するときにエラーがないと仮定すると、コード自体は適切に見えます。ただし、問題を解決できる可能性のあるエラーの原因が 2 つあります。

まず、Finder の Tell ブロッ​​ク内に iTunes Tell のコード ブロックを配置します。基本的に、iTunes に何かをするように Finder に指示することになります。これは、起こりうるエラーの原因です。Tell ブロッ​​クを互いに分離する必要があります。たとえば、あなたはこれを持っています...

tell application "Finder"
    -- do something
    tell application "iTunes"
        -- do something
    end tell
end tell

こんな時はいつだって…

tell application "Finder"
    -- do something
end tell

tell application "iTunes"
    -- do something
end tell

2 つ目は、「エピソード ID」コードの括弧に間違いがあります。たとえばこれ...

("S0" & seasonNumber as text)

これのはず…

"S0" & (seasonNumber as text)

そのため、iTunes のものをサブルーチンに分離し、括弧を修正しました。このコードはテストしていないことに注意してください。適切な変数をすべてサブルーチンに渡したと思いますが、確信が持てません。これが役立つことを願っています。

set mainFolder to choose folder

tell application "Finder"
    -- Loop through all shows
    set shows to every folder of mainFolder
    repeat with show from 1 to count of shows

        -- Set Show Name
        set showName to name of item show of shows

        -- Set Artist
        display dialog "Who is the artist for " & showName & "?" default answer showName
        set showArtist to the text returned of the result

        -- Set Genre
        display dialog "What is the genre for " & showName & "?" default answer ""
        set showGenre to the text returned of the result

        -- Loop through all season
        set seasons to every folder in item show of shows
        repeat with season from 1 to count of seasons

            set seasonName to name of item season of seasons

            -- Set Season Number
            set seasonNumber to text 1 thru ((offset of "-" in seasonName) - 2) of seasonName as integer

            -- Set Year
            display dialog "What year was Season " & seasonNumber & " of " & showName & " in?" default answer "2012"
            set showYear to the text returned of the result

            -- Set Season Name      
            set seasonName to text ((offset of "-" in seasonName) + 2) thru ((offset of "." in seasonName) - 1) of seasonName as text

            -- Set Total Episodes in Season
            set totalEpisodes to count of every file in item season of seasons

            -- Loop through all episodes
            set episodes to every file in item season of seasons
            repeat with episode from 1 to count of episodes

                set episodeName to name of item episode of episodes

                -- Set Episode Number
                set episodeNumber to text 1 thru ((offset of "-" in episodeName) - 2) of episodeName as integer

                -- Set Episode Name
                set episodeName to text ((offset of "-" in episodeName) + 2) thru ((offset of "." in episodeName) - 1) of episodeName as text

                my addEpisodeToItunes((item episode of episodes) as alias, seasonName, seasonNumber, episodeName, episodeNumber, totalEpisodes, showName, showArtist, showGenre, showYear)
            end repeat -- End Episode Repeat
        end repeat -- End Season Repeat
    end repeat -- End Show Repeat
end tell -- End Finder Repeat

on addEpisodeToItunes(theEpisode, seasonName, seasonNumber, episodeName, episodeNumber, totalEpisodes, showName, showArtist, showGenre, showYear)
    tell application "iTunes"
        set newAddition to add theEpisode
        tell newAddition
            set video kind to TV show
            set name to episodeName
            set album to seasonName
            set track number to episodeNumber
            set track count to totalEpisodes
            set disc number to "1"
            set disc count to "1"
            set show to showName
            set season number to seasonNumber
            set episode number to episodeNumber

            -- Manual Entries
            set artist to showArtist
            set genre to showGenre
            set year to showYear


            -- Change episode ID based on season and episode number
            if (seasonNumber < 10) then
                if (episodeNumber < 10) then
                    set episode ID to "S0" & (seasonNumber as text) & "E0" & (episodeNumber as text)
                else
                    set episode ID to "S0" & (seasonNumber as text) & "E" & (episodeNumber as text)
                end if
            else
                if (episodeNumber < 10) then
                    set episode ID to "S" & (seasonNumber as text) & "E0" & (episodeNumber as text)
                else
                    set episode ID to "S" & (seasonNumber as text) & "E" & (episodeNumber as text)
                end if
            end if

        end tell -- End newAddition
    end tell -- End iTunes
end addEpisodeToItunes
于 2012-10-06T07:12:49.393 に答える