如何防止Applescript误读特殊字符
How to prevent Applescript from misreading special characters
我使用以下脚本从歌曲标题的文本文件在 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
Applescript 'name' 属性 中的标题为:
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)
因此它们不会出现在编译的播放列表中。有没有我可以用来避免这种情况发生的调整?
谢谢。
文本文件是UTF8编码,你必须在read
行指定文本编码,默认是MacRoman
set TheFile to read file "Macintosh HD:Applications:Automator stuff:01b iTunes Scripts:SongListxxx.txt" as «class utf8»
我使用以下脚本从歌曲标题的文本文件在 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
Applescript 'name' 属性 中的标题为:
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)
因此它们不会出现在编译的播放列表中。有没有我可以用来避免这种情况发生的调整?
谢谢。
文本文件是UTF8编码,你必须在read
行指定文本编码,默认是MacRoman
set TheFile to read file "Macintosh HD:Applications:Automator stuff:01b iTunes Scripts:SongListxxx.txt" as «class utf8»