2012-10-06 5 views
1

iTunes에 파일을 자동으로 추가하고 메타 데이터를 채우기 위해 간단한 AppleScript를 작성했습니다. 에디터에서 직접 실행하면 작동하지만 iTunes에서 실행하면 "AppleEvent Timed Out"이 표시됩니다. 자체가 오프셋 및 파일 이름의 다른 구성 요소를 계산할 때 오류가없는 가정 사운드를 보인다AppleScript로 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 

       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 

답변

0

코드 :

여기에 코드입니다. 그러나 귀하의 문제를 해결할 수있는 2 가지 오류 소스를 볼 수 있습니다.

먼저 Finder에서 코드 블록에 코드 블록을 알려주십시오. 근본적으로 Finder에게 iTunes가 뭔가를하도록 말하고 있습니다. 이것이 가능한 오류의 원인입니다. 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 

두 번째를해야 할 때, 당신은 괄호와 함께 "에피소드 ID가"코드에서 실수 있습니다. 예를 들어이 ...

("S0" & seasonNumber as text) 

"S0" & (seasonNumber as text) 

같은 나는 서브 루틴에 아이튠즈 물건을 분리하고 괄호를 해결했습니다 ...이 작아야합니다. 이 코드는 테스트하지 않았습니다. 나는 서브 루틴에 모든 적절한 변수를 전달했다고 생각하지만 확신 할 수는 없다. 이게 도움이 되길 바란다. 대신 스크립트의 응용 프로그램으로

저장 : 여기

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 
+0

시간을내어 질문에 답변 해 주셔서 감사합니다. 난 당신의 코드를 시도하고 좋은 오류를 지적했다. 불행히도 스크립트는 내 문제와 동일한 문제를 겪고 있습니다. 편집기에서 직접 실행하면 잘 동작합니다. iTunes에서 실행하면 "AppleEvent Timed It"이라고 표시됩니다. –

관련 문제