17

When I'm in org-mode, I want Emacs to execute a bash script I wrote whenever I hit C-x s to save. The script automatically syncs the file I am saving to my Raspberry Pi. It expects the file name as argument.

How do I tell Emacs to run the external script on org files when I save?

3
  • 7
    You can use after-save-hook to run the script Commented Dec 4, 2014 at 11:16
  • Is this our first immigrant? :-)
    – Malabarba
    Commented Dec 4, 2014 at 13:24
  • @Malabarba This is the second I have seen :) Commented Dec 4, 2014 at 13:29

1 Answer 1

20

Here's a simple setup that you can modify that allows you to sync org files to your Raspberry Pi, based on your bash script (untested, of course, because I have neither a Pi nor your script). Modify the function with your script name. It uses shell-command-to-string to put the command line output somewhere; you could also just use shell-command if that's not a concern.

You can then add it to after-save-hook, as @IqbalAnsari's comment suggested.

(defun sync-to-pi ()
  "Sync org file to Raspberry Pi with external script."
  (when (eq major-mode 'org-mode)
    (shell-command-to-string (format "your-script-name %s" buffer-file-name))))

(add-hook 'after-save-hook #'sync-to-pi)

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.