{"id":63,"date":"2005-12-04T11:08:58","date_gmt":"2005-12-04T18:08:58","guid":{"rendered":"http:\/\/www.red-sweater.com\/blog\/?p=63"},"modified":"2005-12-20T16:48:05","modified_gmt":"2005-12-20T23:48:05","slug":"add-a-favorites-section-to-xcode-file-templates","status":"publish","type":"post","link":"https:\/\/redsweater.com\/blog\/63\/add-a-favorites-section-to-xcode-file-templates","title":{"rendered":"Add a Favorites Section to Xcode File Templates"},"content":{"rendered":"<h4>Scenario<\/h4>\n<p>If you&#8217;re developing software with Xcode, you&#8217;re familiar with the typical process of adding a new source file to your project. You hit Cmd-N, and then either navigate or typeselect to the desired file type. Usually, if you&#8217;re a Cocoa programmer, this means getting past all the AppleScript, BSD, and Carbon templates you don&#8217;t give a rat&#8217;s ass about. Even if you use the disclosure triangle to &#8220;close&#8221; those sections, they&#8217;ll reopen the next time you open the dialog.<\/p>\n<p>\nWouldn&#8217;t it be great if all the file types *YOU* care about were at the top of the list, beckoning you to instantly select them and get on with your job, hobby, or ascetic pursuit of nirvana?\n<\/p>\n<p>\nHere&#8217;s a trick I discovered that allows just that: place a custom category of templates at the top of the list, with symbolic links pointing to all the desired items in their proper home folders. The best news? Xcode chooses the name of the template for the dialog by the name of the <em>file<\/em>, so you also rename the <em>link<\/em> to accurately describe the template in question. For instance, there are templates called &#8220;C File&#8221; in both BSD and Carbon sections. By linking to the items but renaming the link, I end up with a clear and useful Favorites section that works best for my current workflow:\n<\/p>\n<p>\nNote that because the templates in the &#8220;Design&#8221; section are not true templates, there is no way that I know of to include them in the Favorites section. These items must by dynamically injected by Xcode, because they are not represented by &#8220;.pbfiletemplate&#8221; files, and include a custom UI in the New File assistant dialog.\n<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/www.red-sweater.com\/blog\/images\/FavoriteFiles.jpg\"\/><\/p>\n<h4>Step by Step&#8230;<\/h4>\n<p>Just so it&#8217;s exceedingly clear how this is done, I&#8217;ll describe the process as a series of simple steps:\n<\/p>\n<ol>\n<li><strong>Create a Custom Favorites Folder<\/strong><br \/>To get your folder to show up above all the other categories, you&#8217;ll want to name it so that it sorts alphanumerically early. A trick I&#8217;ve used is to insert a space before the word, to make sure it sorts early. The following example shows how you might create the required folder from the Terminal:\n<div style=\"margin-left:1cm\">\n<pre>\r\n% cd ~\r\n% mkdir -p \"Library\/Application Support\/Apple\/Developer Tools\/File Templates\/ Favorites\"<\/pre>\n<\/div>\n<\/li>\n<li><strong>Find Existing Templates to Link To<\/strong><br \/>\nUnless you have existing custom templates in your home directory, you&#8217;ll find that all the templates worth linking to are located in Xcode&#8217;s File Templates folder. Navigate in the Finder to this directory (Cmd-Shift-G): &#8220;\/Library\/Application Support\/Apple\/Developer Tools\/File Templates\/&#8221;. You should be looking at a a list of folders in the Finder, each containing a number template items. Items ending in &#8220;.pbfiletemplate&#8221; are templates folders. These folders are what you want to link directly to.<\/p>\n<\/li>\n<li><strong>Add Links to Favorites<\/strong><br \/>\nThe easiest way to add links to the Favorite folder is to open up a Terminal window, change to the Favorites directory, and use Drag-and-Drop to easily drop in the full paths of templates you want to include. Type &#8220;ln -s &#8220;, then drag in the pbfiletemplate folder you wish to add, hitting backspace a few times to remove the trailing slash. After your link has been created, you can rename the link to avoid naming collisions with other templates, or to increase the clarity as you see fit. For example, here are the commands I used to add the &#8220;BSD C File&#8221; template to my list of favorites:<\/p>\n<div style=\"margin-left:1cm\">\n<pre>\r\n% cd ~\/Library\/Application\\ Support\/Apple\/Developer\\ Tools\/File\\ Templates\/\\ Favorites\r\n% ln -s \/Library\/Application\\ Support\/Apple\/Developer\\ Tools\/File\\ Templates\/BSD\/C\\ File.pbfiletemplate\r\n% mv C\\ File.pbfiletemplate BSD\\ C\\ File.pbfiletemplate\r\n<\/pre>\n<\/div>\n<p>Note: Unfortunately, Mac OS Aliases do not work. You must use a link. I recommend symbolic links because a hard link would not allow you to rename the link as described above (without also renaming the original). (<strong>Update: 12\/20\/2005:<\/strong> Kyle Dean points out in the comments that this is not true. See the comments for discussion.<strong>End update.<\/strong>)<\/li>\n<\/ol>\n<h4>Summary<\/h4>\n<p>Adding a list of favorites to the Xcode file templates will only save you a few seconds here and there, but the clarity of focus and satisfaction that your tools are working <em>for you<\/em> and not against you can improve your productivity and increase your desire to work. Enjoy!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Scenario If you&#8217;re developing software with Xcode, you&#8217;re familiar with the typical process of adding a new source file to your project. You hit Cmd-N, and then either navigate or typeselect to the desired file type. Usually, if you&#8217;re a Cocoa programmer, this means getting past all the AppleScript, BSD, and Carbon templates you don&#8217;t [&hellip;]<\/p>\n","protected":false},"author":10,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,5],"tags":[],"class_list":["post-63","post","type-post","status-publish","format-standard","hentry","category-usability","category-xcode"],"_links":{"self":[{"href":"https:\/\/redsweater.com\/blog\/wp-json\/wp\/v2\/posts\/63","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/redsweater.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/redsweater.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/redsweater.com\/blog\/wp-json\/wp\/v2\/users\/10"}],"replies":[{"embeddable":true,"href":"https:\/\/redsweater.com\/blog\/wp-json\/wp\/v2\/comments?post=63"}],"version-history":[{"count":0,"href":"https:\/\/redsweater.com\/blog\/wp-json\/wp\/v2\/posts\/63\/revisions"}],"wp:attachment":[{"href":"https:\/\/redsweater.com\/blog\/wp-json\/wp\/v2\/media?parent=63"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/redsweater.com\/blog\/wp-json\/wp\/v2\/categories?post=63"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/redsweater.com\/blog\/wp-json\/wp\/v2\/tags?post=63"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}