Skip to content

Instantly share code, notes, and snippets.

@tshu-w
Last active January 12, 2021 13:34
Show Gist options
  • Save tshu-w/869a3b2f1e0823c32d85532a43b22793 to your computer and use it in GitHub Desktop.
Save tshu-w/869a3b2f1e0823c32d85532a43b22793 to your computer and use it in GitHub Desktop.
Emacs Org Capture or Agenda in a new Frame and quit after finishing.
;;; System interaction function
(defun supress-frame-splitting (&rest r)
(let ((frame-name (frame-parameter nil 'name)))
(when (or (equal "capture" frame-name)
(equal "agenda" frame-name))
(delete-other-windows))))
(defun org-capture-finalize@after (&rest r)
(when (equal "l" (plist-get org-capture-plist :key))
(run-at-time 0 nil #'osx-switch-back-to-previous-application))
(when (equal "capture" (frame-parameter nil 'name))
(delete-frame)))
(defun org-agenda-finalize@after (&rest r)
(when (equal "agenda" (frame-parameter nil 'name))
(delete-frame)))
(defun org-capture-select-template@around (org-capture-select-template &optional keys)
(let ((res (ignore-errors (funcall org-capture-select-template keys))))
(unless res (setq res "q"))
(when (and (equal "capture" (frame-parameter nil 'name))
(equal "q" res))
(delete-frame))
res))
(defun org-agenda-get-restriction-and-command@around (org-agenda-get-restriction-and-command prefix-descriptions)
(let ((res (ignore-errors (funcall org-agenda-get-restriction-and-command prefix-descriptions))))
(when (and (not res)
(equal "agenda" (frame-parameter nil 'name)))
(delete-frame))
res))
(advice-add 'org-agenda-quit :after #'org-agenda-finalize@after)
(advice-add 'org-agenda-exit :after #'org-agenda-finalize@after)
(advice-add 'org-agenda-get-restriction-and-command :around #'org-agenda-get-restriction-and-command@around)
(advice-add 'org-capture-finalize :after #'org-capture-finalize@after)
(advice-add 'org-capture-select-template :around #'org-capture-select-template@around)
(advice-add 'org-switch-to-buffer-other-window :after #'supress-frame-splitting)
@tshu-w
Copy link
Author

tshu-w commented Jan 12, 2021

#!/bin/sh
#
# LaunchBar Action Script
#

APP_NAME=$( osascript \
                -e 'tell application "System Events"' \
                -e 'set frontAppName to name of first application process whose frontmost is true' \
                -e 'end tell' \
                -e 'return frontAppName' )

/usr/local/bin/emacsclient -c -F "((name . \"agenda\") (height . 50) (width . 120))" -e "(select-frame-by-name \"agenda\")" -e "(org-agenda $*)"

osascript -e "tell application \"$APP_NAME\" to activate"
#!/bin/sh
#
# LaunchBar Action Script
#

APP_NAME=$( osascript \
                -e 'tell application "System Events"' \
                -e 'set frontAppName to name of first application process whose frontmost is true' \
                -e 'end tell' \
                -e 'return frontAppName' )

/usr/local/bin/emacsclient -c -F "((name . \"capture\") (height . 20) (width . 120))" -e "(select-frame-by-name \"capture\")" -e "(org-capture $*)"

osascript -e "tell application \"$APP_NAME\" to activate"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment