2

I want to open an org-mode file selected in the Finder, by double clicking on it. But since I use Emacs in daemon-mode, I want to use the emacsclient command for that.

Thus the primary idea was to wrap the command emacsclient -c posixPathToFile in an AppleScript App to open it.

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 " & quoted form of posixPath
end try

I know some set commands are not needed. Let's assume this script is saved as Xemacs.app and that I associate this app to always open .org file.

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 Xemacs.app independently. Why ? I'm not confident enough with AppleScript to figure out what happens.

So the workaround was to use the Automator service

  on run {input, parameters}

    set posixPath to POSIX path of input


    tell application "iTerm" to do shell script "/usr/local/bin/emacsclient -c " & quoted form of posixPath

    return input

end run

The service is saved as 'Open in Emacs'

Now selecting a file and right-clicking and callig Service > "Open in Emacs" works and opens the file.

What is wrong with the first approach ?

m0ll3art
  • 63
  • 5
  • How about making an application with platypus and running your script from there, and make your favorite file types associated with that platypus application? – lawlist Aug 07 '17 at 18:55
  • 1
    idea was not to use a third party tool – m0ll3art Aug 08 '17 at 06:53
  • Here is a related thread entitled "*Emacsdaemon and Emacsclient on Mac*" that has a few examples: https://emacs.stackexchange.com/questions/141/emacsdaemon-and-emacsclient-on-mac and here is another related thread on reddit: https://www.reddit.com/r/emacs/comments/1wu2ja/a_tip_for_os_x_users_using_emacs_daemon/?st=j639vmk6&sh=8bb51e73 Google keywords: "**emacsclient automator app emacs finder**" – lawlist Aug 08 '17 at 07:36
  • thanks, I already found those links but none are really answering my question and the Ascrpit are the same as mine. My problem is how to wire the component so that double-clicking opens the file. The automator approach is only a temp. workaround. – m0ll3art Aug 08 '17 at 09:12

1 Answers1

1

ok, I solved my issue. The problem comes from my misunderstanding of the difference between ScriptEditor and the Automator. If I use the Automator to create an App and use the former script instead of creating an App using the ScriptEditor, then it works as expected.

One can simplify the process by creating an App in Automator and running a shell script instead of wrapping the command in Ascript.

shell script Automator

m0ll3art
  • 63
  • 5