2

I am using https://github.com/sprig/org-capture-extension which is a cool Chrome extension to capture links while browsing. The setup on OS X requires defining an Applescript application which is called by the extension. Here is the code I use:

on emacsclient(input)
    display dialog input
    try
        do shell script "/usr/local/Cellar/emacs-plus/25.2/bin/emacsclient -n '" & input & "'"
    on error e number n
        my logit("OOPs: " & e & " " & n, "Emacsclient")
    end try
end emacsclient

to logit(log_string, log_file)
    do shell script ¬
        "echo `date '+%Y-%m-%d %T: '`\"" & log_string & "\" >> $HOME/Library/Logs/" & log_file & ".log"
end logit

on open location input
    emacsclient(input)
end open location

on open inputs
    repeat with raw_input in inputs
        set input to POSIX path of raw_input
        emacsclient(input)
    end repeat
end open

on run
    do shell script emacsclient("")
end run

There is an Emacs running in daemon mode which is started upon initial login in the system. The problem I have is the emacsclient run in the script cannot find the server's socket: This socket is located inside my $TMPDIR which is set by OS X and is not available to scripts run through applescripts shell script action.

How can I solve this conundrum? I need either to run the daemon with a fixed socket file so that I can pass that to the client, or retrieve $TMPDIR from within applescript.

3
  • Run do shell script "echo $TMPDIR" in Script Editor gives the same output as in Terminal from here. Not sure why it didn't work for you.
    – xuchunyang
    Commented Aug 27, 2017 at 19:24
  • FWIW, Emacs Mac Port supports org-protocol out of the box.
    – xuchunyang
    Commented Aug 27, 2017 at 19:28
  • Thanks @xuchunyang. Actually I did not even try echo $TMPDIR... I found another solution
    – insitu
    Commented Aug 28, 2017 at 7:46

1 Answer 1

1

I solved my problem by looking for the actual socket file used:

on emacsclient(input)
    set socket to do shell script "lsof -c Emacs | grep server | grep -E -o '[^[:blank:]]*$' | head -1"
    try
        do shell script "/usr/local/Cellar/emacs-plus/25.2/bin/emacsclient -n '" & input & "' -s " & socket
    on error e number n
        my logit("OOPs: " & e & " " & n, "Emacsclient")
    end try
end emacsclient

@xuchunyang's solution would definitely be simpler though: set socket to do shell script "echo $TMPDIR"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.