2013-09-03 1 views
1

그래서 스크립팅 문제가 있으며 (iTunes와 함께 특정 앱을 찾을 수 없습니다).Regex (또는 simmilar)를 사용하여 스크립트를 통해 iTunes의 노래 이름 (또는 다른 태그)을 변경하십시오.

내가 노래 제목으로 말해봐, 파이썬에서 모든 스크립트에이 같은 작업을 수행 할 수 있습니다 내 마음의

비트 - 원래 혼합

나는 내 마음의 이길을 변경하려면 (원래 혼합) 파이썬에서

나는 것 :

string = 'Beat of my heart - original mix' 
location = string.index(' - ') 
fixed_string = string[,location] + '(' + string[location+3,] + ')' 

간단한 권리? 하지만 나는 아이튠즈 (MAC에서) 같은 레이블로 표시된 트랙에 일괄 처리 싶어요

어떤 제안?

들으 AppleScript를 가진

답변

0

, 당신은 Text Item Delimiters 사용할 수 있습니다

set ASTID to AppleScript's text item delimiters 
tell application "iTunes" 
    repeat with song in (selection of browser window 1) 
     set the_name to name of song 
     if the_name contains " - " then 
      set AppleScript's text item delimiters to ("- ") 
      set the_name to text items of the_name 
      set AppleScript's text item delimiters to ("(") 
      set the_name to (the_name as string) & ")" 
      set name of song to the_name 
     end if 
    end repeat 
    set AppleScript's text item delimiters to ASTID 
end tell 
+0

고마워요! 이게 효과가있는 것 같지만 스크립트 수정을 도와 줄 수 있습니까? 하나의 세그먼트를 모든 선택 트랙으로 변경했지만 작동하지 않습니다. 나는 그것이 플레이리스트를 내려가는 것을 원하지 않지만 (내가 할 수는 있겠지만)하지만 나는 나의 선택을 얻는 것을 선호한다 (나는 트랙을 아이튠즈에서 강조했다). 그게 가능하니? – StudentOfScience

+0

사실 내 의견에 대한 답을 찾았습니다. 아래에서 볼 수 있지만 원래 스크립트를 작성한 이후로 수정 된 스크립트 대신 사용자의 대답을 수락하도록 선택했습니다. – StudentOfScience

+0

이 조쉬 (내 잘못이 아니라)에 대한 나의 유일한 문제는 오히려 sllllooooowwwwww입니다. 약 2-3 분이 걸리는 300 트랙이 걸릴 것입니다 ... 당신이 그것에 대해 생각할 때 ... 매우 빠르다는 것은 텍스트 조작이지만 ... : ( – StudentOfScience

0
set ASTID to AppleScript's text item delimiters 
tell application "iTunes" 
    set sel to selection 
    if sel is not {} then 
     repeat with aTrack in sel 
      set the_name to name of aTrack 
      if the_name contains " - " then 
       set AppleScript's text item delimiters to (" - ") 
       set the_name to text items of the_name 
       set AppleScript's text item delimiters to (" (") 
       set the_name to (the_name as string) & ")" 
       set name of aTrack to the_name 
      end if 
     end repeat 
    end if 
    set AppleScript's text item delimiters to ASTID 
end tell 
+0

위 코드는 @Josh 코드와 동일합니다. 단, en을 실행하는 대신 선택 항목을 가져 오도록 수정했습니다. 타이어 재생 목록. Thx Josh – StudentOfScience

1

시도 : 나는 당신이 대답을 참조

tell application "iTunes" 
    set myTracks to get selection 
    repeat with aTrack in myTracks 
     set trackName to aTrack's name 
     set newTrackName to do shell script "sed 's/ - \\(.*\\)/ (\\1)/' <<< " & quoted form of trackName 
     if newTrackName ≠ trackName then set aTrack's name to newTrackName 
    end repeat 
end tell 
1

그러나 내가 지적하고 싶었 당신은 파이썬 코드와 거의 같은 방식으로 문자열을 파싱 할 수 있습니다. 그냥 "오프셋"을 사용하여 텍스트 위치를 찾으십시오. 간단한 권리?

set theString to "Beat of my heart - original mix" 
set theLocation to offset of " - " in theString 
set fixed_string to text 1 thru theLocation of theString & "(" & text (theLocation + 3) thru end of theString & ")" 

참고 : 오프셋 텍스트가 발견되지 않는 경우 다음 theLocation가 마지막 행하기 전에 필요한 경우 0이 그렇게 추가 if 문 경우 수있을 것입니다.