![AppleScript 显示“无法打开文档。您没有权限。”但是文件可以打开吗?](https://linux22.com/image/1400108/AppleScript%20%E6%98%BE%E7%A4%BA%E2%80%9C%E6%97%A0%E6%B3%95%E6%89%93%E5%BC%80%E6%96%87%E6%A1%A3%E3%80%82%E6%82%A8%E6%B2%A1%E6%9C%89%E6%9D%83%E9%99%90%E3%80%82%E2%80%9D%E4%BD%86%E6%98%AF%E6%96%87%E4%BB%B6%E5%8F%AF%E4%BB%A5%E6%89%93%E5%BC%80%E5%90%97%EF%BC%9F.png)
当我尝试访问 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