Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
String 使用applescript按文本文件中的值对字符串排序_String_Sorting_Applescript_Text Files_Itunes - Fatal编程技术网

String 使用applescript按文本文件中的值对字符串排序

String 使用applescript按文本文件中的值对字符串排序,string,sorting,applescript,text-files,itunes,String,Sorting,Applescript,Text Files,Itunes,我正在尝试构建一个applescript来对iTunes中音乐文件的流派字段中的标签进行排序 我使用分号分隔的列表作为类型字段,如下所示:摇滚;艺术摇滚;女歌手 我要排序的字符串在我的脚本中名为genreList: {"Art Rock", "Female Vocalists", "Rock"} 我的首选标签顺序列为排序列表: {"Rock", "Dance", "Art Rock", "New Wave", "Female Vocalists", "Male Vocalists"} 我希望

我正在尝试构建一个applescript来对iTunes中音乐文件的流派字段中的标签进行排序

我使用分号分隔的列表作为类型字段,如下所示:摇滚;艺术摇滚;女歌手

我要排序的字符串在我的脚本中名为genreList:

{"Art Rock", "Female Vocalists", "Rock"}
我的首选标签顺序列为排序列表:

{"Rock", "Dance", "Art Rock", "New Wave", "Female Vocalists", "Male Vocalists"}
我希望genreList中的项目按照sortList排序,如下所示:

{"Rock", "Art Rock", "Female Vocalists"}

如何使用第二个列表对第一个列表进行排序?我在这里和谷歌上搜索过,但作为一名脚本编写新手,我甚至不确定我在搜索正确的术语。

试试这个,在iTunes中选择一个或多个曲目并运行脚本

如果分隔符应为分号+空格,请更改第二个属性行

如果流派属性不包含分隔符,则不会更改任何内容

如果某个流派与排序列表中的项目不匹配,它将被追加到末尾

property sortedGenreList : {"Rock", "Dance", "Art Rock", "New Wave", "Female Vocalists", "Male Vocalists"}
property separator : ";"

tell application "iTunes" to set selectedItems to (get selection)
if selectedItems is {} then
    display dialog "Nothing selected" buttons {"Cancel"} default button 1
end if

set {TID, text item delimiters} to {text item delimiters, separator}
repeat with aTrack in selectedItems
    set orderedGenreList to {}
    set nonOrderableGenres to {}
    tell application "iTunes" to set trackGenreList to text items of (get genre of aTrack)
    if (count trackGenreList) > 1 then
        repeat with aGenre in trackGenreList
            if sortedGenreList does not contain aGenre then set end of nonOrderableGenres to contents of aGenre
        end repeat
        repeat with aGenre in sortedGenreList
            if trackGenreList contains aGenre then
                set end of orderedGenreList to contents of aGenre
            end if
        end repeat
        set orderedGenres to (orderedGenreList & nonOrderableGenres) as text
        tell application "iTunes" to set genre of aTrack to orderedGenres
    end if
end repeat
set text item delimiters to TID
如果要使用每行具有类型的文本文件,请将第一个属性行替换为

set sortedGenreList to paragraphs of (read (choose file))