I wrote a Python script to parse an org file that I keep my tasks in, reformat those tasks, and save them to a taskpaper file so that I can easily view and
process the tasks on my phone. The script works the way I want it to, but I have to
rememeber to run it every time I want my tasks to 'sync'. I
have been trying to use after-save-hook
to run the script whenever I save changes
to my org file, but I haven't been able to get it to work. I am new to Emacs, and
don't know much about lisp. This is what I have come up with based mostly on the
answer to this question.
(defun sync-to-taskpaper ()
"Sync org file to taskpaper file for mobile access"
(when (eq buffer-file-name "~/path/to/org/file.org")
(shell-command "python3 ~/path/to/python/script.py")))
(add-hook 'after-save-hook #'sync-to-taskpaper)
I am not getting any error messages when I save the file, it just is not running my custom function. Is it possible to do it this way, and if so, what am I missing? Thank you for your help!
(shell-command "python3 ~/path/to/python/script.py")
and does it do what you want? You can typeM-x eval-expression RET (shell-command "python3 ~/path/to/python/script.py") RET
eval-buffer
, and it did exactly what I want. The problem must be with my function then...(when (eq buffer-file-name "~/path/to/org/file.org")
seemed to be the best thing I could come up with for "do this when the file in the buffer that I am saving is the file I want to run the script on", but I am not that confident that this is right.