osx - AppleScript shows "Document could not be opened. You don’t have permission." but file can be opened?

08
2014-07
  • Evil Closet Monkey

    I am getting a "The document [filename] could not be opened. You don't have permission" when attempting to access several files in an AppleScript. However, I can open these files manually without issue.

    I have attempted the following:

    • Manually modified permission via File->Get Info
    • Used Disk Utility to "Verify" and "Repair Permissions"
    • Rebooted in recovery mode to reset home directory permissions and acls

    I continue to have the problem.

    To add further frustration, the files do not consistently report the error. Sometimes I will get the error on a file when the run the script, but not the next time!

    Why might I be receiving this permissions error, and how else might I address it?

    AppleScript below, if it helps:

    -- 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
    
  • Answers
    Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

    Related Question

    osx - How to get QuickTime Player 7 to save its export settings?
  • orj

    I'm trying to get QuickTime Player 7 on Mac OS X 10.6.4 to save its export settings so I can batch convert some MKV movies to M4V (MPEG-4).

    I've already exported a movie using the settings I want. The settings I want to save are for an export of a "Movie to MPEG-4".

    When I run this AppleScript to save the settings:

    tell application "QuickTime Player 7"
        activate
        tell document 1
            save export settings for QuickTime movie to file "Macintosh HD:Test.set"
        end tell
    end tell
    

    I get this error: "QuickTime Player 7 got an error: An error of type -2107 has occurred."

    I can not find any reference to this error type on the net.

    From what I can tell, using AppleScript is the only way to instruct QuickTime 7 to save its export settings.

    Is there an easier way of doing this? Is there something wrong with my AppleScript?


  • Related Answers
  • Chealion

    From my answer on Stack Overflow

    Yes, you do have to use AppleScript in order to export the settings file.

    I don't personally get the error -2107 running your script, but it doesn't save the file for me.

    Try:

    set file2save to (choose file name default location (path to desktop) default name "setting.qtes")
    
    tell application "QuickTime Player 7"
        tell first document
            save export settings for QuickTime movie to file2save
        end tell
    end tell
    

    While you can export the document using that settings file:

    tell application "QuickTime Player 7"
        #Change this path to wherever the .qtes file is
        set settings_file to "Macintosh HD:setting.qtes"
        set movie2save to (choose file name default location (path to desktop) default name "QuickTime.mov")
        export document 1 to movie2save as QuickTime movie using settings alias settings_file
    end tell