AppleScript App (Xcode) "cannot open files of this type"

This is a newbie question:

I've created an AppleScript App in Xcode which is a simple wrapper that takes command line arguments and calls another application. The part I'm struggling with is that I also want users to be able to double-click a file on their Desktop (or select Open with) and have the selected file be input to my AppleScript App. But when invoking the application this way, the file does not come into my AppleScript App as one of the command line arguments and I also get the error message saying:

The document "ut33p23.hod" could not be opened. <MyApplicationName> cannot open files of this type."

ut33p23.hod is the file I try to open with my app.


I have entered the UTI and Document Type in the Info.plist so that my application shows up in the list of available applications which can open files of type hod.

Questions:

1. Is there some other Info.plist setting I'm missing to fix this error message?

2. Is there something I need to define in the AppleScript itself to accept files of this type?

3. If the file doesn't come in as a command-line argument, how can the AppleScript get access to it?

Looks like I get to answer my own questions...


Answer to question 1:

The missing entry in the Info.plist to solve the "cannot open files of this type" error message is the CFBundleTypeOSTypes entry. I had the others, but not this one. Here's a modified version of my Info.plist with context:


<key>CFBundleDocumentTypes</key>

<array>

<dict>

<key>CFBundleTypeExtensions</key>

<array>

<string>*</string>

</array>

<key>CFBundleTypeMIMETypes</key>

<array/>

<key>CFBundleTypeName</key>

<string>your_specific_name_here</string>

<key>CFBundleTypeOSTypes</key>

<array>

<string>****</string>

</array>

<key>CFBundleTypeRole</key>

<string>Editor</string>

<key>LSHandlerRank</key>

<string>Owner</string>

<key>LSItemContentTypes</key>

<array>

<string>your.pkg.name.here</string>

</array>

</dict>

</array>


Answer to questions 2 & 3:

Adding the following handler allowed me to get the file that was being sent via "Open with".

on application_openFiles_(sender, droppedItem)

--- droppedItem contains the path to the file

end application_openFiles_


I stumbled across a really old reference to it and decided to give it a try. It worked! It would have been nice if Apple's documentation had something for application_openFiles_. I would have expected to possibly see it here along with other methods the AppleScript App template inserts by default:

https://developer.apple.com/documentation/appkit/nsapplicationdelegate?language=objc


If there's a more recent handler I should be using instead, please provide.

Your link is the current documentation, and includes that method. The template just has the basics; you are expected to add other delegate methods and configure the Info.plist as desired. Note that you can set up your own project and file templates, although information about that is difficult to find.

AppleScript App (Xcode) "cannot open files of this type"
 
 
Q