AppleScript 显示“无法打开文档。您没有权限。”但是文件可以打开吗?

AppleScript 显示“无法打开文档。您没有权限。”但是文件可以打开吗?

当我尝试访问 AppleScript 中的多个文件时,我收到“无法打开文档 [文件名]。您没有权限”的提示。但是,我可以手动打开这些文件,没有任何问题。

我尝试了以下操作:

  • 通过手动修改权限File->Get Info
  • 使用磁盘实用程序“验证”和“修复权限”
  • 在恢复模式下重新启动以重置主目录权限和 acl

我仍然面临这个问题。

更令人沮丧的是,文件并不总是报告错误。有时我在运行脚本时会收到文件错误,但下次不会!

为什么我可能会收到此权限错误?我还能怎样解决它?

下面是 AppleScript,如果它有帮助:

-- prompt for source directory
set srcDirectory to (choose folder)

-- get list of all files in source directory
set allFiles to (list folder srcDirectory without invisibles)

tell application "OmniGraffle"
    -- create a new document
    set newDocument to (make new document with properties {template:"Single Pixel Grid"})

    -- added for debug purposes
    delay 5

    -- get a reference to the first layer
    set destinationLayer to first layer in first canvas of newDocument

    -- step through each of the file
    repeat with currentFile in allFiles
        -- get a reference to the next file
        set srcFileString to (srcDirectory as string) & currentFile
        set srcFileRef to (open srcFileString)

        -- get a reference to the icon
        set srcGraphic to first graphic in first layer in first canvas of srcFileRef

        -- flip the icon (they're all upside down)
        flip srcGraphic over vertically

        -- copy the updated source to destination canvas
        duplicate srcGraphic to destinationLayer

        -- close the source file
        close srcFileRef saving no

        -- added for debug purposes
        delay 5
    end repeat

end tell

相关内容