7

A week ago, quicklook stopped working with .m and .h files. Instead, it's showing me a .m or .h thumbnail. I think that day a message box popped up and I didn't read it — I answered the question hastily — but I wasn't doing anything with the system. Anyway, now I've lost the quicklook for these file types.

It still works for all other default files. I tried to copy the ".qlgenerator" files from another mac, which has the same OS version... and it still didn't work.

I tried to disk verify/repair permissions, it indicated something concerning .qlgenerator files, but I thought "It's probably because of my copy-paste-replace by intruder files that probably changed some permissions". Anyway, it didn't solve the problem.

I also tried running qlmanage -r, and restarting my mac. The problem persists.

The other mac is still showing the default way (aka, with quicklook previews) for these file types.

Any idea on what went wrong? Do you think that that message box that I answered hastily is responsible for that? I feel that it is, but I'm not sure, because I wasn't configuring the system or anything, nor even anything that is related neither to quicklook (I didn't know that this feature had a name back then) nor xcode... I'm lost.

EDIT As @Bootle suggested, i ran

qlmanage -p FILE

and surprisingly, the Quicklook opened the file correctly, i.e. you can see the content of the file and the default XCode coloring for it. Additionally, the following output was printed in the terminal. enter image description here

So any more hints?

EDIT New hints emerged after checking the log from the console after @StvnW 's edit.

i'm attaching the logs image after ordering quicklook on a file

UPDATE The solution was because i was keeping older versions of XCodes since 3.6.2 ^_^ and other versions, i put all of them together in a folder where i disallowed myself the permission to access it. Thus they became inaccessible to the system too. And problem was solved, the system (or QL) fixed itself to the latest official XCode application.

But this is thanks to the below answer that gave me that hint from the debugging. I guess other people who have this same problem should follow his answer. I'm marking this response as the correct answer

1
  • 2
    Can you open Terminal and run this command: qlmanage -p FILE Where FILE is the path to a .h or .m file on your computer. And then copy and paste the terminal output here, or in a pastebin or something. Thanks.
    – Bootle
    Apr 24, 2014 at 13:32

2 Answers 2

6
+25

You might consider simply using QLStephen which will add proper QuickLook support for all text files regardless of their extensions. It will also properly handle files without extensions (e.g. README, Makefile). What I like about it is that you don't have to maintain a list of extensions; QLStephen detects text files automatically. QLStephen is independent of XCode and is a QL plugin that you drop into /Library/QuickLook/ or ~/Library/QuickLook/.

The fact that I am also named Steven is purely coincidental.

Edit: Debugging QuickLook based on more info from OP:

Turn on QuickLook logging:

defaults write -g QLEnableLogging YES

Here is some reference logging output (written to Console):

Stock Xcode installed:

2014-04-29 2:46:08.172 PM quicklookd[19315]: 
    [QL] Thumbnailing file://localhost/Users/user/src/hello/main.m. 
    Content type UTI: public.objective-c-source
    Generator used: <QLGenerator Text.qlgenerator>

2014-04-29 2:46:08.173 PM com.apple.quicklook.satellite[19330]:
    [QL] <QLThumbnailRequest main.m
            token: d45af7955eb9401bc7a49fd6652d1c3aa5cc4a8b;00000000;000000000000001a;
            com.apple.app-sandbox.read;00000001;01000003;0000000003e32849;
            /users/user/src/hello/main.m>.
    Content type UTI: public.objective-c-source.
    Generator used: <QLGenerator /System/Library/QuickLook/Text.qlgenerator>

Third-party generator (QLColorCode) installed:

2014-04-29 2:51:40.458 PM quicklookd[19359]:
    [QL] Thumbnailing file://localhost/Users/user/src/hello/main.m.
    Content type UTI: public.objective-c-source.
    Generator used: <QLGenerator /Users/user/Library/QuickLook/QLColorCode.qlgenerator>

2014-04-29 2:51:40.459 PM com.apple.quicklook.satellite[19367]:
    [QL] <QLThumbnailRequest main.m
            token: d45af7955eb9401bc7a49fd6652d1c3aa5cc4a8b;00000000;000000000000001a;
            com.apple.app-sandbox.read;00000001;01000003;0000000003e32849;
            /users/user/src/hello/main.m>.
    Content type UTI: public.objective-c-source.
    Generator used: <QLGenerator /Users/user/Library/QuickLook/QLColorCode.qlgenerator>

Since things work for you when calling qlmanage from the command line, you might be able to compare the logs written to Console with the output from manually invoking on the command line and spot the issue. With only Xcode installed:

[user@macbook]/Users/user/src/hello$ qlmanage -p -d 1 main.m 
Testing Quick Look preview with files:
    main.m
[DEBUG] Registering <QLGenerator Built-in 0x7fa08241eaa0> for public.image
[DEBUG] Preview test for main.m -- file://localhost/Users/user/src/hello/.
        Content type UTI: public.objective-c-source
[DEBUG] Previewing file://localhost/Users/user/src/hello/main.m.
        Content type UTI: public.objective-c-source.
        Generator used: <QLGenerator Text.qlgenerator>
[DEBUG] Loading <QLGenerator Text.qlgenerator>
[DEBUG] Previewing file://localhost/Users/user/src/hello/main.m finished
4
  • but that didn't work either, probably because the extension of files is overriding its functionality?
    – LolaRun
    Apr 29, 2014 at 7:38
  • Perhaps. I also can confirm that my Xcode's Info.plist is identical to what was suggested by Bootle, and I am also on stock Xcode 5.0.2.
    – StvnW
    Apr 29, 2014 at 12:15
  • I didn't quite understand all of your second reply :) You should have told me to go to console and look at the logs. Anyway i have found out new evidences i think the problem will be fixed soon
    – LolaRun
    May 6, 2014 at 7:07
  • Sorry if that wasn't clear. I've added mention of where to find the logs.
    – StvnW
    May 6, 2014 at 11:38
5

QuickLook for these types of files works because the file type is specified in Xcode's Info.plist.

In order for QuickLook to use Xcode to quick view these files again in Finder, you'll need to edit Xcode's Info.plist file. This is found by right clicking the Xcode.app file in your Applications and clicking "Show Package Contents". You'll find Info.plist in the Contents folder that opens up.

In the Info.plist file, all of the file types associated with Xcode are listed as "CFBundleTypeExtensions" dictionaries.

Once opening the plist, do a search for <string>h</string> (or the same with 'm'). If it can't be found, you'll need to add it.

Note: At this point, you may want to create a backup of the whole Xcode.app file in case something goes wrong.

Make a copy of Info.plist by alt-dragging it to your Desktop. Open the copy and search for <key>CFBundleExecutable</key>. You'll see </array> on the line above it. Before the </array>, paste in the block of text allowing for a file type to be associated with Xcode (shown below). This block should start and end with <dict> and </dict>, respectively.

For the .h file:

<dict>
        <key>CFBundleTypeExtensions</key>
        <array>
            <string>h</string>
        </array>
        <key>CFBundleTypeIconFile</key>
        <string>c-header_Icon</string>
        <key>CFBundleTypeName</key>
        <string>C Header Source</string>
        <key>CFBundleTypeRole</key>
        <string>Editor</string>
        <key>LSIsAppleDefaultForType</key>
        <true/>
        <key>LSItemContentTypes</key>
        <array>
            <string>public.c-header</string>
        </array>
</dict>

For the .m file:

<dict>
    <key>CFBundleTypeExtensions</key>
    <array>
        <string>m</string>
    </array>
    <key>CFBundleTypeIconFile</key>
    <string>objective-c-source_Icon</string>
    <key>CFBundleTypeName</key>
    <string>Objective-C Source</string>
    <key>CFBundleTypeRole</key>
    <string>Editor</string>
    <key>LSIsAppleDefaultForType</key>
    <true/>
    <key>LSItemContentTypes</key>
    <array>
        <string>public.objective-c-source</string>
    </array>
</dict>

Once this is done, you should be able to copy the edited Info.plist back into the Xcode.app Contents folder. Sometimes, apps don't like you editing their plists and decide not to work afterwards. If this is the case, just restore from the copy you (should have) made earlier.

This can be replicated with any application and any filetype. If there's a better way to do this perhaps by changing/setting some preferences in Xcode, it'd be good to know.

3
  • wow, very important information. Thanks a lot. But when i opened the plist, as a text, it contained a lot of garabage along with recognized characters, meaning it's not xml formatted. And if you open it as a plist you don't find the "CFBundleTypeExtensions", instead you can find the "CFBundleDocumentTypes", among the list i was able to find "item16(C header source)" including the CFBundleTypeExtensions "h", and another "item 22 (Objective-c source)" including the "m" value. This is XCode 5.0.2. So i think it's still not corrupt. Thanks a lot though, i hope this helps.
    – LolaRun
    Apr 16, 2014 at 10:32
  • 1
    I forgot that TextEdit won't open plist files. By default they're opened by Xcode itself but not in an XML looking format. I use TextWrangler for all text files, plists and other formats alike. You will be able to open the plist in the format I mentioned in my answer by using TextWrangler or another text editor like it, such as an editor designed to edit code. TextWrangler, however, is free to use and I'd recommend it. You can find it here: barebones.com/products/textwrangler
    – Bootle
    Apr 16, 2014 at 15:41
  • yeah i can see it in xml format now, thanks a lot. I already had textwrangler btw :) . Anyway, like i stated earlier, and as i now was able to see literally what's written in xml format, i can confirm that i already have what you're suggesting to insert. So the problem must be elsewhere. Thanks a lot though for your big effort, i'm grateful.
    – LolaRun
    Apr 17, 2014 at 8:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .