4

Is it possible to to register a folder extension on Mac to be opened with a specific application (something like .app folders behave in a special way)? If it's possible, then how? I'm looking for a solution similar to this: related question, only for folders, not files.

I had a look at the reference of the UTIs UTIs, but I did not find any identifier that seems suitable (e.g. something like public.folder-extension).

Is it possible to do this at all? On the GUI I did not see any way to do it either (for a folder with a specific extension, there is no "Open With..." option). [Important: I do not want to do this on the GUI, this was only a remark to say why I think it might be impossible.]

Community
  • 1
  • 1
Andras
  • 71
  • 5

2 Answers2

3

I found out a way that works for me (in case somebody else also encounters this problem):

  1. Add the following snippet in the Info.plist file of the application bundle:

    <key>CFBundleDocumentTypes</key>
    <array>
        <dict>
           <key>CFBundleTypeExtensions</key>
           <array>
               <string>ext1</string>
               <string>ext2</string>
           </array>
           <key>CFBundleTypeIconFile</key>
           <string>documentlogo.icns</string>
           <key>CFBundleTypeName</key>
           <string>My Bundle Type Name</string>
           <key>CFBundleTypeRole</key>
           <string>Viewer</string>
           <key>LSTypeIsPackage</key>
           <true />
        </dict>
    </array>
    
  2. Replace ext1, ext2 with the extensions you would like to support, documentlogo.icns with the name of the icon of the document (which must be located in Application Bundle.app/Contents/Resources/documentlogo.icns), and My Bundle Type Name with a sensible name for your bundle)

  3. In this example, any folder, to be recognized as a bundle of our application, must have the extension ext1 or ext2, and must contain a Contents/PkgInfo file, with 8 "?"s. All the other contents are up to you.

I base my solution on these sources, Document Packages, Information Property List Key Reference, Document Packages Examples.

Please, correct me if there is a better/more efficient way to do it, because I still have some doubts (e.g.: as I see, this should work also for normal files, not just Packages. Then why do we need the LaunchServices way as well? Is the application bundle the default, and the LaunchServices the way each user customizes it?)

Andras
  • 71
  • 5
1

I found how to do this manually, which I will list here for others to find, and to do this programmatically you can combine this info with the answer at: https://superuser.com/questions/273756/how-to-change-default-app-for-all-files-of-particular-file-type-through-terminal

You must have XCode installed. Open Terminal or iTerm and:

cd ~/Library/Preferences
open com.apple.LaunchServices.plist

Add or overwrite the following entry (use Cmd+F to search for "folder"):

LSHandlerContentType String public.folder
LSHandlerRoleAll String com.somecompany.someproduct

Replace the com.somecompany.someproduct with an existing name - you can see these in the same directory (~/Library/Preferences) - they end with .plist - e.g. com.macromates.textmate or com.sublimetext.2.

Alternative if you use Quicksilver: add a custom keyboard trigger for "Current Selection (Proxy Object) -> Open With -> Your App Here". I found that this also creates (and vigorously re-creates) the above association whenever you use the newly created keyboard shortcut on a folder in Finder.

Community
  • 1
  • 1
youurayy
  • 1,635
  • 1
  • 18
  • 11