15

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?

Dan
  • 32,584
  • 6
  • 98
  • 168
qacwnfq q
  • 253
  • 3
  • 6

1 Answers1

19

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)
Dan
  • 32,584
  • 6
  • 98
  • 168