Home > Blockchain >  Quicktime Error opening random files using simple apple script
Quicktime Error opening random files using simple apple script

Time:08-31

I'm getting the following error: "The file isn’t compatible with QuickTime Player."

When using this script:

tell application "Finder"
    
    set random_file to some file of entire contents of folder "Movies" of home
    open result
    
end tell

However, I am able to open the file from the finder manually and once I do the script works on just that file. The problem is I have thousands of files and don't want to open each one manually for the script to work again. Have not had this problem with the script in the past.

CodePudding user response:

There are two ways I can think of to approach modifying your script:

  1. Stick with Finder's open command but invoke it fully with its using parameter, which accepts an application file that informs Finder of the application that will be used to open the file. It may sound superfluous given it already tries to open it in QuickTime, and we're not trying to change that, but it's not unwise to see if it does confer a difference in behaviour:

    tell application id "com.apple.finder"
            tell the folder (path to movies folder) to tell (the ¬
                    a reference to entire contents) to tell (the ¬
                    some document file as alias) to set f to it
    
            open f using application file id "com.apple.QuickTimePlayerX"
    end tell
    
  2. Grab the file as you like (really, you ought to be using System Events for this, not Finder, but I'll go with what you had), but then use the open handler of the specific application to open the file:

    tell application id "com.apple.finder" to tell the folder (path to movies folder) ¬
            to tell (a reference to the entire contents) to tell (some document file) ¬
            as alias to set f to it
    
    tell application id "com.apple.QuickTimePlayerX"
            activate
            open f
    end tell
    

NB. I'm using Monterey, in which both of these two above propositions work appropriately. This doesn't necessarily infer that it will do so in Big Sur, but if they do not, it's worth checking the various app permissions under the different Security & Privacy headings of System Preferences.

  • Related