{"id":91,"date":"2010-05-25T21:25:30","date_gmt":"2010-05-26T02:25:30","guid":{"rendered":"http:\/\/jamesroberts.name\/blog\/?p=91"},"modified":"2010-05-26T11:26:15","modified_gmt":"2010-05-26T16:26:15","slug":"osx-finder-new-file-contextual-menu-item-using-automator","status":"publish","type":"post","link":"https:\/\/jamesroberts.name\/blog\/2010\/05\/25\/osx-finder-new-file-contextual-menu-item-using-automator\/","title":{"rendered":"OSX Finder New File Contextual Menu Item Using Automator"},"content":{"rendered":"<p>I have always been annoyed that there is no &#8220;New File&#8221; contextual menu item in OS X&#8217;s Finder.  I mean, common Apple, why no new file?  Anyway, after looking around I found some packages that don&#8217;t work with Snow Leopard.  So I decided to see what I could do with Automator.  Low and behold, there are many options for writing &#8220;services&#8221; which appear in a the &#8220;Services&#8221; sub menu of the contextual menu for a folder.  I found this simple shell script which creates an empty text document when saved in Automator as a &#8220;Service&#8221;. (<b>NOTE: there is a <a title=\"automator new file applescript workflow solution\" href=\"#applescript-solution\">better solution<\/a> below&#8230;<\/b>)<\/p>\n<pre lang=\"shell\">\r\ntouch \"$@\/NewTextFile.txt\"\r\n<\/pre>\n<p>I tried messing around with apple script to get a dialog input from the user for the new file&#8217;s extension (<b>UPDATE: figured this out, see below<\/b>), but got incredibly frustrated trying to turn the input folder into a string that could be run as a shell script with the a fore mentioned script.  So I gave up and just made a few of the most common blank files I wanted.<\/p>\n<p><a href=\"\/project-src\/automator-workflow-library\/blank_file_workflows.zip\">Click Here to download<\/a> a zip of the Automator Workflow files I created.  Hopefully this helps someone who is as frustrated as I am with the lack of a &#8220;New File&#8221; button or contextual menu in OS X.<\/p>\n<p><a id=\"applescript-solution\"><\/a><\/p>\n<p><b>Please Note:<\/b> that you must click on the actual folder (with the icon) to get the &#8220;Services&#8221; menu to appear in Finder&#8217;s contextual menu.  The &#8220;Services&#8221; menu does not show when you click on the &#8220;background&#8221; of the folder in Finder.  Annoying.<\/p>\n<h3>A Better Solution<\/h3>\n<p><b>UPDATE:<\/b> Actually got this working the next day when a co-worker mentioned that the folder string i was looking for was called a POSIX (aka Unix) style folder path string.  Anyway, I now have a script which is called from the contextual menu, which prompts you for a filename, then creates it in the folder you have clicked on!  Yay!<\/p>\n<p>To create this work flow, you can <a title=\"download automator new file contextual menu item workflow\" href=\"\/project-src\/automator-workflow-library\/new_file_applescript_workflow.zip\">download the service workflow<\/a> , then put it in the ~\/Library\/Services\/ folder for your user.  Alternatively, you can create your own new &#8220;Service&#8221; with Automator.  Open a new workflow as a &#8220;Service&#8221;, then search for &#8220;applescript&#8221; in the actions library.  Drag the &#8220;Run AppleScript&#8221; action into your workflow, select &#8220;files and folders&#8221; in the &#8220;service recieves&#8221; drop down, then paste this code into the action:<\/p>\n<pre lang=\"applescript\">\r\non run {input}\r\n\tdisplay dialog \"File Name?\" default answer \"blank.txt\"\r\n\tset filename to the text returned of result\r\n\tset filepath to POSIX path of input\r\n\tdo shell script \"touch \" & quoted form of filepath & filename\r\n\treturn input\r\nend run\r\n<\/pre>\n<p>Save the service workflow, and blamo, there it is in your contextual menu when clicking on a folder.  <\/p>\n","protected":false},"excerpt":{"rendered":"<p>I have always been annoyed that there is no &#8220;New File&#8221; contextual menu item in OS X&#8217;s Finder. I mean, common Apple, why no new file? Anyway, after looking around I found some packages that don&#8217;t work with Snow Leopard. So I decided to see what I could do with Automator. Low and behold, there [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21],"tags":[25,24,22,12,63,23],"_links":{"self":[{"href":"https:\/\/jamesroberts.name\/blog\/wp-json\/wp\/v2\/posts\/91"}],"collection":[{"href":"https:\/\/jamesroberts.name\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jamesroberts.name\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jamesroberts.name\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jamesroberts.name\/blog\/wp-json\/wp\/v2\/comments?post=91"}],"version-history":[{"count":11,"href":"https:\/\/jamesroberts.name\/blog\/wp-json\/wp\/v2\/posts\/91\/revisions"}],"predecessor-version":[{"id":102,"href":"https:\/\/jamesroberts.name\/blog\/wp-json\/wp\/v2\/posts\/91\/revisions\/102"}],"wp:attachment":[{"href":"https:\/\/jamesroberts.name\/blog\/wp-json\/wp\/v2\/media?parent=91"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jamesroberts.name\/blog\/wp-json\/wp\/v2\/categories?post=91"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jamesroberts.name\/blog\/wp-json\/wp\/v2\/tags?post=91"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}