{"id":27,"date":"2011-08-23T13:00:25","date_gmt":"2011-08-23T17:00:25","guid":{"rendered":"http:\/\/www.defectivestudios.com\/devblog\/?p=27"},"modified":"2012-08-10T22:15:22","modified_gmt":"2012-08-11T02:15:22","slug":"adding-preview-to-c-source-files-in-os-x","status":"publish","type":"post","link":"https:\/\/www.defectivestudios.com\/devblog\/adding-preview-to-c-source-files-in-os-x\/","title":{"rendered":"Adding preview to (C#) source files in OS X"},"content":{"rendered":"<p>So I&#8217;ve been forced to use OS X a lot these days, what with an iOS project and teaching programming to kids (see Jono&#8217;s post). I&#8217;ve tried on a few occasions to get comfortable in OS X, and even own an old early G4-based macbook. Well, that is to say, I bought it from my sister for $50 and used it for a few months freshman year before lending it to a friend&#8230; long story short it was a nice little reliable laptop which I could carry around with me, check e-mail, browse the web, etc. Basically I used it as a netbook before netbooks were cool.<\/p>\n<p><!--more--><\/p>\n<p>Obviously judging the OS X experience from my short time with a then-obsolete laptop is unfair, but I would say that that&#8217;s the type of use these computers are geared towards. I certainly consider myself a Windows power user&#8211;I&#8217;ve been using a Microsoft OS since DOS 5&#8211;but I&#8217;m still pretty clueless when it comes to OS X. I&#8217;m taking it slow, trying to learn about features as the need arises. I&#8217;m a fan of menu-bar activity monitors, though I haven&#8217;t settled on which is my favorite. One feature I&#8217;m very pleased with is the OS-wide quick-look preview, but I was disappointed to find that it didn&#8217;t know how to understand my .cs source files (or a few other types for that matter). \u00a0Not only that, but when it comes across a type that it can&#8217;t understand, the &#8220;default&#8221; is very minimal. \u00a0If the content is just text, why not show a text preview? \u00a0A quick Google search came up with a solution, but configuring it was a little hairy. Here&#8217;s what I did:<\/p>\n<ul>\n<li>Google &#8220;OS X preview C#&#8221;<\/li>\n<li>Discover preview feature is called &#8220;Quick Look&#8221;<\/li>\n<li>Google &#8220;Quick Look Syntax Highlight&#8221;<\/li>\n<li>Try just installing <a title=\"qlcolorcode\" href=\"http:\/\/code.google.com\/p\/qlcolorcode\/\">qlcolorcode<\/a><\/li>\n<\/ul>\n<div>Alas, while there is default support for some filetypes (generally ones already recognized by OS X like .h, .m, .cpp) my .cs and .js files were still woefully un-preivew-able! As a note for those lazy users who dont&#8217; want to read the qlcolorcode readme, the way to install a QuickLook plugin is simply to copy the binary to \/Library\/QuickLook or ~\/Library\/QucikLook<\/div>\n<div>After some more digging through qlcolorcode&#8217;s FAQ and t3h internetz I found that I had to modify the system-wide UTI (always an unfortunate acronym) definition for cs and js files. \u00a0Basically, QuickLook hooks into a system-wide file-type identification system called Uniform Type Identifiers. \u00a0These identifiers are specified by some metadata included in the various applications which edit these files. \u00a0I headed over to \u00a0QLColorcode package to modify its Info.plist, which is a file that (presumably) can be found in the root of any app package. \u00a0For those total OS X noobs out there, a .app (or just an application) is actually a folder which the OS tricks you into thinking is a file. \u00a0If you control-click (or right-click) on the package and say &#8220;Show Package Contents&#8221; you can view the files inside this folder. \u00a0In this case, the QL library is just the same.<\/div>\n<div>I meant to be a bit more organized about this article, citing more of the sources I found, but I did this so long ago that I don&#8217;t have all that info. Suffice to say, I &#8220;somehow&#8221; figured out that the cs entry of this info file should look something like this:<\/div>\n<div>\n<pre class=\"syntax {XML}\">\/\/ -*- mode: XML; -*-\r\n<!--?xml version=\"1.0\" encoding=\"UTF-8\"?-->\r\n...\r\n\r\n\tUTImportedTypeDeclarations\r\n\r\n\t\t...\r\n\r\n\t\t\tUTTypeConformsTo\r\n\r\n\t\t\t\tpublic.source-code\r\n\r\n\t\t\tUTTypeDescription\r\n\t\t\tC# Source File\r\n\t\t\tUTTypeIdentifier\r\n\t\t\tcom.microsoft.csharp-source\r\n\t\t\tUTTypeReferenceURL\r\n\t\t\thttp:\/\/www.microsoft.com\/\r\n\t\t\tUTTypeTagSpecification\r\n\r\n\t\t\t\tpublic.filename-extension\r\n\r\n\t\t\t\t\tcs\r\n\r\n\t...<\/pre>\n<\/div>\n<div>So, with that done, everything works! Now when I hit space bar with a .cs script selected, I get a nice syntax-highlighted preview \ud83d\ude42 My one complaint is that I can&#8217;t select text from within a preview, but oh well.<\/div>\n","protected":false},"excerpt":{"rendered":"<p>So I&#8217;ve been forced to use OS X a lot these days, what with an iOS project and teaching programming to kids (see Jono&#8217;s post). I&#8217;ve tried on a few occasions to get comfortable in OS X, and even own an old early G4-based macbook. Well, that is to say, I bought it from my [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"_links":{"self":[{"href":"https:\/\/www.defectivestudios.com\/devblog\/wp-json\/wp\/v2\/posts\/27"}],"collection":[{"href":"https:\/\/www.defectivestudios.com\/devblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.defectivestudios.com\/devblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.defectivestudios.com\/devblog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.defectivestudios.com\/devblog\/wp-json\/wp\/v2\/comments?post=27"}],"version-history":[{"count":2,"href":"https:\/\/www.defectivestudios.com\/devblog\/wp-json\/wp\/v2\/posts\/27\/revisions"}],"predecessor-version":[{"id":106,"href":"https:\/\/www.defectivestudios.com\/devblog\/wp-json\/wp\/v2\/posts\/27\/revisions\/106"}],"wp:attachment":[{"href":"https:\/\/www.defectivestudios.com\/devblog\/wp-json\/wp\/v2\/media?parent=27"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.defectivestudios.com\/devblog\/wp-json\/wp\/v2\/categories?post=27"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.defectivestudios.com\/devblog\/wp-json\/wp\/v2\/tags?post=27"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}