title: How to open an EMACS file in OS X by double-clicking on it, using the `emacsclient` command?
body: <p>I want to open an org-mode file selected in the <em>Finder</em>, by double clicking on it. But since I use Emacs in <em>daemon-mode</em>, I want to use the <code>emacsclient</code> command for that.</p>
  
  <p>Thus the primary idea was to wrap the command <code>emacsclient -c posixPathToFile</code> in an AppleScript <em>App</em> to open it. </p>
  
  <pre><code>tell application "Finder"
      set fileAlias to the selection as alias
      set fileName to name of fileAlias
      set posixPath to POSIX path of fileAlias
  end tell
  
  -- tell application "Emacs" to activate
  
  try
      do shell script "/usr/local/bin/emacsclient -c " &amp; quoted form of posixPath
  end try
  </code></pre>
  
  <p>I know some <code>set</code> commands are not needed. Let's assume this script is saved as <code>Xemacs.app</code> and that I associate this app to always open <code>.org</code> file. </p>
  
  <p>Using this App does not work by double-clicking on the file, but rather if I select the file in the Finder and then call the <em>Xemacs.app</em> independently. Why ? I'm not confident enough with AppleScript to figure out what happens. </p>
  
  <p>So the workaround was to use the Automator service</p>
  
  <pre><code>  on run {input, parameters}
  
      set posixPath to POSIX path of input
  
  
      tell application "iTerm" to do shell script "/usr/local/bin/emacsclient -c " &amp; quoted form of posixPath
  
      return input
  
  end run
  </code></pre>
  
  <p>The service is saved as <strong>'Open in Emacs'</strong> </p>
  
  <p>Now selecting a file and right-clicking and callig Service > "Open in Emacs" works and opens the file. </p>
  
  <p>What is wrong with the first approach ?  </p>