Apple Music批量导出播放列表脚本报错:变量all_ps未定义
问题原因与修复方案
错误的核心是变量类型不匹配:你把all_ps初始定义成了字符串"{}",但后续代码用set the end of all_ps是给列表添加元素的语法,字符串不支持这种操作,导致变量操作失败,系统判定all_ps未正确定义。
修复步骤
把set all_ps to "{}"这一行改成:
set all_ps to {}
这会把all_ps初始化为一个空列表,后续的set the end of all_ps操作就能正常给列表添加元素了。
修正后的完整代码片段
try set all_specialps to (get name of every user playlist whose special kind is not none) set all_userps to (get name of every user playlist whose smart is false and special kind is none) set all_smartps to (get name of every user playlist whose smart is true and special kind is none) set delim to "--------------------------------------------------" set delim_specialpl to "---------------- Special Playlists: ----------------" set delim_userpl to "------------------ User Playlists: -----------------" set delim_smartpl to "---------------- Smart Playlists: -----------------" set all_ps to {} -- 这里改成空列表,不是字符串 if ((length of all_specialps) > 0) then set the end of all_ps to delim set the end of all_ps to delim_specialpl repeat with ps in all_specialps set the end of all_ps to ps end repeat end if if ((length of all_userps) > 0) then set the end of all_ps to delim set the end of all_ps to delim_userpl repeat with ps in all_userps set the end of all_ps to ps end repeat end if if ((length of all_smartps) > 0) then set the end of all_ps to delim set the end of all_ps to delim_smartpl repeat with ps in all_smartps set the end of all_ps to ps end repeat end if end try
额外说明
- AppleScript里,
{}表示空列表,"{}"是包含这两个字符的字符串,两者完全不同 - 后续的
set the end of ...只能对列表类型的变量使用,字符串没有“末尾添加元素”的概念
内容的提问来源于stack exchange,提问作者KirklandStackOF
相关产品推荐
相关产品推荐

