A package is just a directory, apparently, but somehow Finder and Path Finder know it's a package.

How is this indicated in the file system? I've tried a few changes to a directory to make it a package but to no avail.

  • call it something.app or something.photoslibrary etc. There are many versions – Tetsujin Apr 10 '17 at 17:23
  • @Tetsujin you're correct that it's in the filename. which I did not know. But yet DayOne app has managed to register .dayone as a package type. So... how can that be done for new pathnames? Thanks! – Dan Rosenstark Apr 10 '17 at 17:27
  • 1
    Sorry, that will need someone smarter than me, I'm afraid ;) – Tetsujin Apr 10 '17 at 17:31
  • Thanks... well if you want to add an answer to this question even given just what you've given so far, that would be great. Thanks. – Dan Rosenstark Apr 10 '17 at 17:33
  • I'd wait for one of the smarter cookies - there's bound to be one along shortly :) – Tetsujin Apr 10 '17 at 17:35
up vote 5 down vote accepted

Short answer

To register a document as a package, the developer of DayOne would have had to modify the document type information in the DayOne app's information property list (Info.plist) file.

Long Answer

A package is a file system directory used by macOS and iOS. It's basically a directory that will appear as a single file, but which may in fact contain a preserved state of files and folders. So, a folder could have a number of subfolders and many files, but as a package it will be displayed to users like a single file. For example, in macOS the Finder will see a package as a single file to avoid users mucking around with the actual contents. However, users can view the contents through various methods such as right-clicking on the package and selecting Show Package Contents from the context menu.

Apple's Bundle Programming Guide, available on their Developer site, has a whole section on Document Packages. Below are some relevant quotes:

To register a document as a package, you must modify the document type information in your application’s information property list (Info.plist) file. The CFBundleDocumentTypes key stores information about the document types your application supports. For each document package type, include the LSTypeIsPackage key with an appropriate value. The presence of this key tells the Finder and Launch Services to treat directories with the given file extension as a package. For more information about Info.plist keys, see Information Property List Key Reference.

Document packages should always have an extension to identify them—even though that extension may be hidden by the user. The extension allows the Finder to identify your document directory and treat it as a package. You should never associate a document package with a MIME type or 4-byte OS type.

Source: Bundle Programming Guide

On the off-chance you can't access the document, let me know and I'll include some additional quotes from the page.

  • You code Mac Apps? – Pacerier Dec 10 '17 at 22:04
  • No, not yet. Actually, I am slowly working on one, but it'd be my first. I've only developed iOS apps so far, or done other lower-level programming tasks (e.g. AppleScript, VBA, HTML, etc). – Monomeeth Dec 12 '17 at 21:46

As I have made a document-based application for macOS, I may help you understand a bit. Although @Monomeeth's answer is right, but dealing with GUI is a lot better than Info.plist. People usually use another path. They subclass NSDocment, which provides the basis for file/bundle saving and loading. Then, people go to Xcode and under the "General" tab, define a document type, then go to "Exported UTIs" and export an UTI that conforms to com.apple.package. They read in with the NSFileWrapper class. This way, people won't have to do some tedious work with stuff like NSData.

If you want to create a bundle, check this answer. Simply create an empty macOS app and edit the "Exported UTIs" sections to taste.

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.