在自制AppleScript应用中运行外部AppleScript脚本报错的技术求助
解决AppleScript中运行资源脚本的报错问题
看起来你遇到的问题是因为对path to resource返回的对象处理不当导致的。让我帮你拆解一下错误原因和修复方案:
错误原因分析
你的代码中,path to resource "file creator.scpt" in directory "Scripts"返回的是一个alias对象(指向资源文件的引用),而不是字符串路径。当你尝试用path of filescript去获取它的路径时,AppleScript找不到这个属性,就会抛出类似"It can't get a class PPTH of alias"的错误——这里的PPTH应该是解析错误导致的path属性误写。
修复后的代码方案
你有几种简单的方式来修正这个问题:
方案1:直接运行alias对象
run script命令可以直接接受alias对象作为参数,不需要额外转换:
set filescript to (path to resource "file creator.scpt" in directory "Scripts") run script filescript
方案2:转换为字符串路径运行
如果你需要显式使用路径字符串,可以把alias转换为HFS路径字符串(AppleScript原生支持的路径格式):
set filescript to (path to resource "file creator.scpt" in directory "Scripts") run script (filescript as string)
或者转换为POSIX路径(更通用的Unix风格路径)再运行:
set posixScriptPath to POSIX path of (path to resource "file creator.scpt" in directory "Scripts") run script POSIX file posixScriptPath
额外注意事项
- 确保你的
file creator.scpt确实存在于应用包的Contents/Resources/Scripts/目录下(in directory "Scripts"对应的就是这个路径) - 如果是用Xcode打包的AppleScript应用,记得在项目中把脚本文件和Scripts目录添加到Copy Bundle Resources的Build Phase中,否则打包后资源会缺失
内容的提问来源于stack exchange,提问作者michael319
相关产品推荐
相关产品推荐

