2 Replies
      Latest reply on Feb 11, 2020 8:48 AM by red_menace
      bseemann Level 1 Level 1 (0 points)

        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?

        • Re: AppleScript App (Xcode) "cannot open files of this type"
          bseemann Level 1 Level 1 (0 points)

          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.