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

相關內容