Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

In Mac OS X, when you doubleclick on a file name, that file will open with the application which created the file. So there must be stored, somewhere in the file description on a Mac OS X file, information on which application created this file. Note that this is not the file extension, the file can have any extension, or no extension at all.

Two questions regarding this information:

(1) How can I search for all files which will open a specific application?

(2) How can I see, and change, the application which a certain file will open?

share|improve this question
    
This is no longer the case. OS X changes its behavior in recent versions to ignore e.g. creator codes. –  Daniel Beck Jun 23 '12 at 18:22

2 Answers 2

The application a file will open with is identified by the Item Kind. For example, a "Plain text document" will open with TextMate, while a "TextWrangler text document" will open with TextWrangler. The applications themselves are responsible for supplying these item kinds, and they are assigned to the files, which will then allow OS X to select the application to open them with.

You can check this info on single files with mdls:

mdls -name kMDItemKind -raw some-file.txt

So, to search for all files that will open with TextMate, search for them with that specific Item Kind:

mdfind 'kMDItemKind == "Plain text document"'

You can also restrict this search to a certain folder:

mdfind -onlyin /some/folder 'kMDItemKind == "Plain text document"'

Now, how do you find out these "Item Kind" strings that applications provide?

Go to the application file you're interested in, and right-click it. Select Show Package Contents… and navigate to Contents/Resources. Open Info.plist.

Here, you'll find the document types the application can handle, including their Document Type Name, which is exactly the one you can search for with mdfind.


How can I see, and change, the application which a certain file will open?

Select the file, right-click it and click Get Info. Change the application listed under Open with:

Another useful app for maintaining default applications and associations is RCDefaultApp.

share|improve this answer

If you change the program association for a single file, it's stored in an extended attribute named com.apple.ResourceFork (AFAICT, always at offset 0x108) and can be accessed from the command line using xattr.

Extended attributes of files can be listed using ls -l@ on the command line:

$ ls -la@ test.png 
-rw-r--r--@ 1 danielbeck  staff  23580 23 Jun 20:26 test.png
    com.apple.FinderInfo       32 
    com.apple.ResourceFork   1338 
    com.apple.metadata:kMDItemIsScreenCapture      42 
    com.apple.metadata:kMDItemScreenCaptureType    51 

For the example, I explicitly selected Preview as the application to open the file in its Get Info window.

$ xattr -p -l com.apple.ResourceFork test.png 
com.apple.ResourceFork:
00000000  00 00 01 00 00 00 05 08 00 00 04 08 00 00 00 32  |...............2|
00000010  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  |................|
00000020  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  |................|
00000030  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  |................|
00000040  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  |................|
00000050  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  |................|
00000060  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  |................|
00000070  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  |................|
00000080  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  |................|
00000090  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  |................|
000000A0  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  |................|
000000B0  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  |................|
000000C0  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  |................|
000000D0  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  |................|
000000E0  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  |................|
000000F0  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  |................|
00000100  00 00 04 04 00 00 00 1A 2F 41 70 70 6C 69 63 61  |......../Applica|
00000110  74 69 6F 6E 73 2F 50 72 65 76 69 65 77 2E 61 70  |tions/Preview.ap|
00000120  70 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  |p...............|
[snip]

Older OS X versions supported use of the creator code to determine the application to open a specific file. Some applications still write them, and they can be accessed by examining a file's Spotlight metadata using mdls. In the example, I'm inspect a .pxm file created by Pixelmator.

$ mdls test.pxm 
kMDItemAlternateNames          = (
    "test.pxm"
)
kMDItemContentCreationDate     = 2012-06-23 18:23:04 +0000
kMDItemContentModificationDate = 2012-06-23 18:24:12 +0000
kMDItemContentType             = "com.pixelmator.pxm"
kMDItemContentTypeTree         = (
    "com.pixelmator.pxm",
    "public.image",
    "public.data",
    "public.item",
    "public.content"
)
kMDItemDateAdded               = 2012-06-23 18:23:04 +0000
kMDItemDisplayName             = "test"
kMDItemFSContentChangeDate     = 2012-06-23 18:24:12 +0000
kMDItemFSCreationDate          = 2012-06-23 18:23:04 +0000
kMDItemFSCreatorCode           = "PXMT"
[...]

The last line of the sample output shows the creator code set by Pixelmator: PXMT.

share|improve this answer
    
How can i search for all files which have a particular application as creator. Preferable search in a Time Machine data base, but such data bases look like ordinary sets of directories and files within them. –  Jacob Palme Jun 24 '12 at 18:06
    
@JacobPalme Have Time Machine index the drive and (for the Pixelmator example) run mdfind -onlyin /path/to/directory/to/limit/search/to 'kMDItemFSCreatorCode=="PXMT"' –  Daniel Beck Jun 24 '12 at 18:10
    
Note that creator codes are only used in older versions of OS X, and there not even exclusively, so that e.g. .png files downloaded from the web without this metadata are opened in the preferred image viewer. I'm afraid your goal would be quite difficult to accomplish completely. –  Daniel Beck Jun 24 '12 at 18:14

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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