I have an Automator workflow script, which uses emacsclient to edit any text, in my `~/Library/Services`. The service receives selected text in any application and output replaces the selected text. It consists of two parts: Run AppleScript, and Run Shell Script.
The AppleScript part is:
on run {input, parameters}
tell application "EmacsMac" to activate
tell application "System Events"
repeat until visible of process "Emacs" is true
delay 0.5
end repeat
end tell
return input
end run
and the Shell Script part (pass input to stdin) is: tmp=$(mktemp "$HOME/tmp/EditTextinEmacsXXXXXXXX")
ec=/Applications/MacPorts/EmacsMac.app/Contents/MacOS/bin/emacsclient
cat > "$tmp"
until [ $($ec -q -e '(server-running-p)' 2>/dev/null) == t ]; do
sleep 1
done
$ec -q -c "$tmp"
rv="$?"
cat "$tmp"
if [ $rv -ne 0 ]; then
echo "Something went wrong. Please find your text in"
echo "$tmp"
else
rm "$tmp"
fi
Getting it to work with any editor should be straightforward.