1

所以我有一个脚本问题(并且找不到与 iTunes 结合使用的特定应用程序)。

我可以对 Python 中的任何脚本执行类似的操作,假设我有歌曲标题:

我的心跳 - 原创混音

我想把它改成我的心跳(原始混音)

在 Python 中,我会:

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

简单吧?但我想在我标记为这样的轨道上的 iTunes 中(在 Mac 上)批量处理

有什么建议么?

谢谢

4

4 回答 4

1

我看到你有一个答案,但是我想指出你可以用与你的 python 代码几乎相同的方式来解析 applescript 中的字符串。只需使用“偏移”即可找到文本位置。简单吧?

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 语句。

于 2013-09-04T04:48:54.067 回答
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
于 2013-09-03T22:46:06.573 回答
0

使用 Applescript,您可以使用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
于 2013-09-03T21:33:09.277 回答
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
于 2013-09-03T22:35:07.463 回答