Как предотвратить неправильное чтение специальных символов в Applescript - PullRequest
0 голосов
/ 03 июля 2018

Я использую следующий скрипт для создания плейлиста в iTunes из текстового файла с названиями песен, но, похоже, в моем списке нет названий со специальными символами:

--selects file to read from and variables, deletes exisiting tracks
set TheFile to read file "Macintosh HD:Applications:Automator stuff:01b iTunes Scripts:SongListxxx.txt"
tell application "iTunes"
    set thePlaylist to playlist "SongListxxx"
    try
        delete every track of thePlaylist
    end try
    set MySongs to paragraphs of (TheFile) -- read artist names (separated by newlines) from the file
end tell
--refills playlist
tell application "iTunes"
    set theTrack to ""
    repeat with AnItem in MySongs -- get all tracks from each artist
        set AnItem to (contents of AnItem)
        if AnItem is not "" then try -- don't bother with empty names
            set MyTracks to (location of file tracks of playlist "Music" whose name is AnItem) --and artist does not contain "Jamie Farrow" and genre is not "Spoken Word")
            --can also modify the above from "is" to "contains" or "_begins with_"
            add MyTracks to thePlaylist

    on error errmess -- oopsie (not found, etc)
        --added bit
        set theTrack to theTrack & AnItem & return
        --display dialog theTrack
        --back to script
        log errmess -- just log it
    end try
end repeat
end tell

Заголовки, которые в свойстве 'name' в Applescript читают:

Caprice (Le Bal masqué)
Desafinado (Jobim, Mendonça, Hendricks)
Sous le dôme épais (Flower Duet from Lakmé, Delibes)

Мой текстовый файл также имеет точные совпадения для них, поэтому это не ошибка исходного файла.

Во всяком случае, они, похоже, читаются Applescript как:

Caprice (Le Bal masqueÃÅ)
Desafinado (Jobim, Mendonça, Hendricks)
Sous le dôme épais (Flower Duet from Lakmé, Delibes)

И поэтому они не появляются в скомпилированном плейлисте. Могу ли я использовать твик, чтобы избежать этого?

Спасибо.

1 Ответ

0 голосов
/ 03 июля 2018

Текстовый файл в кодировке UTF8, необходимо указать кодировку текста в строке read, по умолчанию MacRoman

set TheFile to read file "Macintosh HD:Applications:Automator stuff:01b iTunes Scripts:SongListxxx.txt" as «class utf8»
...