2020-08-20 02:10:25 -04:00
|
|
|
;;; os/macos/autoload.el -*- lexical-binding: t; -*-
|
2019-09-23 13:39:53 -04:00
|
|
|
|
2022-06-21 18:08:02 +02:00
|
|
|
(defun +macos-defaults (action &rest args)
|
|
|
|
(apply #'doom-call-process "defaults" action args))
|
|
|
|
|
2017-02-19 18:54:42 -05:00
|
|
|
(defun +macos-open-with (&optional app-name path)
|
|
|
|
"Send PATH to APP-NAME on OSX."
|
|
|
|
(interactive)
|
2017-02-25 02:11:24 -05:00
|
|
|
(let* ((path (expand-file-name
|
|
|
|
(replace-regexp-in-string
|
|
|
|
"'" "\\'"
|
2018-10-04 11:11:08 -07:00
|
|
|
(or path (if (derived-mode-p 'dired-mode)
|
2017-02-25 02:11:24 -05:00
|
|
|
(dired-get-file-for-visit)
|
|
|
|
(buffer-file-name)))
|
|
|
|
nil t)))
|
2017-02-19 18:54:42 -05:00
|
|
|
(command (format "open %s"
|
|
|
|
(if app-name
|
|
|
|
(format "-a %s '%s'" (shell-quote-argument app-name) path)
|
|
|
|
(format "'%s'" path)))))
|
|
|
|
(message "Running: %s" command)
|
|
|
|
(shell-command command)))
|
|
|
|
|
2019-07-22 23:54:43 +02:00
|
|
|
(defmacro +macos--open-with (id &optional app dir)
|
2017-02-19 18:54:42 -05:00
|
|
|
`(defun ,(intern (format "+macos/%s" id)) ()
|
|
|
|
(interactive)
|
|
|
|
(+macos-open-with ,app ,dir)))
|
|
|
|
|
2022-06-21 18:08:02 +02:00
|
|
|
(defmacro +macos--open-with-iterm (id &optional dir newwindow?)
|
|
|
|
`(defun ,(intern (format "+macos/%s" id)) ()
|
|
|
|
(interactive)
|
|
|
|
(letf! ((defun read-newwindows ()
|
|
|
|
(cdr (+macos-defaults
|
|
|
|
"read" "com.googlecode.iterm2" "OpenFileInNewWindows")))
|
|
|
|
(defun write-newwindows (bool)
|
|
|
|
(+macos-defaults
|
|
|
|
"write" "com.googlecode.iterm2" "OpenFileInNewWindows"
|
|
|
|
"-bool" (if bool "true" "false"))))
|
|
|
|
(let ((newwindow?
|
2022-06-29 18:12:43 +02:00
|
|
|
(if ,newwindow? (not (equal (read-newwindows) "1")))))
|
2022-06-21 18:08:02 +02:00
|
|
|
(when newwindow?
|
|
|
|
(write-newwindows t))
|
|
|
|
(unwind-protect (+macos-open-with "iTerm" ,dir)
|
|
|
|
(when newwindow?
|
|
|
|
(write-newwindows nil)))))))
|
|
|
|
|
2020-08-20 02:10:25 -04:00
|
|
|
;;;###autoload (autoload '+macos/open-in-default-program "os/macos/autoload" nil t)
|
2019-07-22 23:54:43 +02:00
|
|
|
(+macos--open-with open-in-default-program)
|
2017-02-19 18:54:42 -05:00
|
|
|
|
2020-08-20 02:10:25 -04:00
|
|
|
;;;###autoload (autoload '+macos/reveal-in-finder "os/macos/autoload" nil t)
|
2019-07-22 23:54:43 +02:00
|
|
|
(+macos--open-with reveal-in-finder "Finder" default-directory)
|
2017-02-19 18:54:42 -05:00
|
|
|
|
2020-08-20 02:10:25 -04:00
|
|
|
;;;###autoload (autoload '+macos/reveal-project-in-finder "os/macos/autoload" nil t)
|
2019-07-22 23:54:43 +02:00
|
|
|
(+macos--open-with reveal-project-in-finder "Finder"
|
|
|
|
(or (doom-project-root) default-directory))
|
2017-02-19 18:54:42 -05:00
|
|
|
|
2020-08-20 02:10:25 -04:00
|
|
|
;;;###autoload (autoload '+macos/send-to-transmit "os/macos/autoload" nil t)
|
2019-07-22 23:54:43 +02:00
|
|
|
(+macos--open-with send-to-transmit "Transmit")
|
2017-02-19 18:54:42 -05:00
|
|
|
|
2020-08-20 02:10:25 -04:00
|
|
|
;;;###autoload (autoload '+macos/send-cwd-to-transmit "os/macos/autoload" nil t)
|
2019-07-22 23:54:43 +02:00
|
|
|
(+macos--open-with send-cwd-to-transmit "Transmit" default-directory)
|
2017-02-19 18:54:42 -05:00
|
|
|
|
2020-08-20 02:10:25 -04:00
|
|
|
;;;###autoload (autoload '+macos/send-to-launchbar "os/macos/autoload" nil t)
|
2019-07-22 23:54:43 +02:00
|
|
|
(+macos--open-with send-to-launchbar "LaunchBar")
|
2017-02-19 18:54:42 -05:00
|
|
|
|
2020-08-20 02:10:25 -04:00
|
|
|
;;;###autoload (autoload '+macos/send-project-to-launchbar "os/macos/autoload" nil t)
|
2019-07-22 23:54:43 +02:00
|
|
|
(+macos--open-with send-project-to-launchbar "LaunchBar"
|
|
|
|
(or (doom-project-root) default-directory))
|
2020-02-25 07:11:56 -08:00
|
|
|
|
2020-08-20 02:10:25 -04:00
|
|
|
;;;###autoload (autoload '+macos/open-in-iterm "os/macos/autoload" nil t)
|
2022-06-21 18:08:02 +02:00
|
|
|
(+macos--open-with-iterm open-in-iterm default-directory)
|
|
|
|
|
|
|
|
;;;###autoload (autoload '+macos/open-in-iterm-new-window "os/macos/autoload" nil t)
|
|
|
|
(+macos--open-with-iterm open-in-iterm-new-window default-directory t)
|