Skip to content

Commit

Permalink
feat: sync-trampolines allin1
Browse files Browse the repository at this point in the history
  • Loading branch information
hraban committed Nov 3, 2023
1 parent 7990e31 commit 03aeb4b
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 10 deletions.
13 changes: 13 additions & 0 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

- =mktrampoline= :: Create a “trampoline” launcher app
- =sync-dock= :: Update persistent apps in the Dock
- =sync-trampolines= :: Create a directory with trampolines to all your apps

Made with Nix in mind.

Expand Down Expand Up @@ -31,6 +32,18 @@ It will find an old persistent item by the name of "Foo" and update it to the ne

N.B.: This is currently limited only to Nix apps, but actually it could work for anything. I’ve just kept it conservative to be on the safe side.

** sync-trampolines

Combines =mktrampoline= and =sync-dock= to create a fresh directory with a fresh trampoline for every source app. E.g.:

#+begin_src shell
$ nix run github:hraban/mac-app-util -- sync-trampolines ~/special/apps/ ~/Applications/Special/
#+end_src

Will create a fresh directory (=~/Applications/Special=), deleting if it already existed. In that directory it will create a trampoline app for every single =*.app= file it finds in =~/special/apps/=.

This helps register apps from outside of your =~/Applications= directory with Spotlight and the Launchpad.

* License

mac-app-util - Manage Mac App launchers
Expand Down
49 changes: 39 additions & 10 deletions main.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
(asdf:load-system "trivia")

(defpackage #:script
(:use #:cl)
(:use #:cl #:arrow-macros)
(:local-nicknames (#:alex #:alexandria)
(#:sh #:inferior-shell)))

Expand Down Expand Up @@ -119,14 +119,19 @@
(find ,to-cnts -name "*.icns" -delete)
(rsync :include "*.icns" :exclude "*" :recursive ,from-cnts ,to-cnts)))))

(defun create-trampoline (app trampoline)
(let* ((aapp (merge-pathnames app (uiop:getcwd)))
(atrampoline (merge-pathnames trampoline (uiop:getcwd)))
(cmd (format NIL "do shell script \"open '~A'\"" aapp)))
(rm-rf atrampoline)
(sh `("/usr/bin/osacompile" #\o ,atrampoline #\e ,cmd))
(sync-icons aapp atrampoline)
(copy-paths (infoplist aapp) (infoplist atrampoline) *copyable-app-props*)))
(defgeneric mktrampoline (from to))

(defmethod mktrampoline ((app string) (trampoline string))
(mktrampoline (to-abs-dir app) (to-abs-dir trampoline)))

(defmethod mktrampoline ((app pathname) (trampoline pathname))
(uiop:ensure-pathname app :ensure-absolute t)
(uiop:ensure-pathname trampoline :ensure-absolute t)
(let ((cmd (format NIL "do shell script \"open '~A'\"" app)))
(rm-rf trampoline)
(sh `("/usr/bin/osacompile" #\o ,trampoline #\e ,cmd))
(sync-icons app trampoline)
(copy-paths (infoplist app) (infoplist trampoline) *copyable-app-props*)))


;;; sync-dock
Expand Down Expand Up @@ -171,6 +176,28 @@ Also resolves symlinks, if relevant.
;; only restart exactly once.
(sh `(dockutil :add ,(realpath app) :replacing ,existing))))))


;;; sync-trampolines

(defun to-abs-dir (d)
"Transform d into an absolute directory pathname."
(uiop:ensure-pathname d
:ensure-absolute t
:defaults (uiop:getcwd)
:ensure-directory t))

(defun directory-name (d)
;; Weird lispism
(first (last (pathname-directory d))))

(defun sync-trampolines (&rest args)
(destructuring-bind (from to) (mapcar #'to-abs-dir args)
(rm-rf to)
(ensure-directories-exist to)
(dolist (app (directory (merge-pathnames #p"*.app" from)))
(mktrampoline app (merge-pathnames (directory-name app) to)))
(sync-dock from)))


;;; CLI

Expand All @@ -197,9 +224,11 @@ directory, without having to check which one is pinned etc.
(uiop:quit 0))
(trivia:match args
((list "mktrampoline" from to)
(create-trampoline from to))
(mktrampoline from to))
((list* "sync-dock" apps)
(sync-dock apps))
((list "sync-trampolines" from to)
(sync-trampolines from to))
(_
(print-usage)
(uiop:quit 1))))))
Expand Down

0 comments on commit 03aeb4b

Please sign in to comment.