You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Photos容器类型判断异常:脚本与应用运行结果差异及解决方法

Photos容器类型判断的正确方法及运行差异原因

正确的容器类型判断方法

不要通过将类转为文本的方式判断,直接使用AppleScript的类比较语法,两种写法都可行:

  • 判断文件夹:
    if class of nextContainer is folder then
        -- 文件夹处理逻辑
    end if
    
  • 判断相册:
    if class of nextContainer is album then
        -- 相册处理逻辑
    end if
    

或者更简洁的写法:

if nextContainer is a folder then
    -- 文件夹逻辑
else if nextContainer is an album then
    -- 相册逻辑
end if

这种方式不管是在脚本编辑器直接运行,还是打包成应用,都能准确识别容器类型。

两种运行方式结果不同的原因

  • 脚本编辑器直接运行时:AppleScript会自动将Photos框架的内部类,映射为面向用户的友好名称(folder/album),所以转成文本时显示的是这些易读名称。
  • 打包为应用运行时:应用处于沙箱环境中,AppleScript的编译/运行机制发生变化,直接将类转为文本时,返回的是Photos底层的内部类标识(lPfd对应文件夹,iPal对应相册),这是系统内部使用的类代码,而非用户可见的显示名称。

内容的提问来源于stack exchange,提问作者pawi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.06 13:04:50