12

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?

migrated from programmers.stackexchange.com Dec 4 '14 at 10:22

This question came from our site for professionals, academics, and students working within the systems development life cycle.

  • 4
    You can use after-save-hook to run the script – Iqbal Ansari Dec 4 '14 at 11:16
  • Is this our first immigrant? :-) – Malabarba Dec 4 '14 at 13:24
  • @Malabarba This is the second I have seen :) – Kaushal Modi Dec 4 '14 at 13:29
9

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, privacy policy and cookie policy

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