(Nix) Utilities for Mac App launchers
How to use in Nix
Use the home-manager module to “fix” your .app launchers:
- Pinning in Dock works across updates
- Launch from Spotlight
Now you can launch Nix-installed apps using only your keyboard, using ⌘ space.
Flakes
How to use this in nix-darwin or home-manager, assuming you use flakes:
{
inputs = {
#...
mac-app-util.url = "github:hraban/mac-app-util";
#...
};
outputs = {
nix-darwin
, home-manager
, mac-app-util
, ...
}: {
darwinConfigurations = {
MyHost = nix-darwin.lib.darwinSystem {
# ...
modules = [
mac-app-util.darwinModules.default
# And if you also use home manager:
home-manager.darwinModules.home-manager
(
{ pkgs, config, inputs, ... }:
{
home-manager.users.foobar.imports = [
#...
mac-app-util.homeManagerModules.default
];
}
)
];
};
};
};
}
Non-flakes
Since I use flakes for home manager and nix-darwin I’m not 100% on how to do this, but I suspect that it’s similar to the above, at its core.
What will be different is the “plumbing”, i.e. how to get a reference to this app’s derivation. Here’s how:
let
mac-app-util-src = pkgs.fetchFromGitHub {
repo = "mac-app-util";
owner = "hraban";
rev = "master";
# Replace this by the output of:
# nix run --experimental-features 'nix-command flakes' nixpkgs#nix-prefetch-github -- hraban mac-app-util | grep sha
hash = "";
};
mac-app-util = (pkgs.callPackage mac-app-util-src {});
in
# Now you have either the program as a derivation itself:
mac-app-util.default
# Or the home manager module:
mac-app-util.homeManagerModules.default
# Or darwin:
mac-app-util.darwinModules.default
The rest is up to you. Good luck!
Commands
At the core of this project is a (Nix-agnostic) program that can:
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
mktrampoline
This creates a “trampoline” launcher app which is a simple wrapper application that just launches your actual application.
$ nix run github:hraban/mac-app-util -- mktrampoline /path/to/MyApp.app /Applications/MyApp.app
Intuitively, you would either fully copy & paste the original .app, or create a symlink or “alias”; all of those solutions have different problems and they don’t get indexed by Spotlight properly.
This trampoline script is indexed by Spotlight and by Launchpad, so you can keep launching your apps using ⌘ SPC <appname> ⏎
See nix-community/home-manager#1341
sync-dock
When you have an app in your Dock which doesn’t live in /Applications/..
, it can get stale: e.g. your app at /foo/v1/Foo.app
gets replaced by /foo/v2/Foo.app
. To automatically update the Dock to the new location of Foo, execute:
$ nix run github:hraban/mac-app-util -- sync-dock Foo.app
It will find an old persistent item by the name of “Foo” and update it to the new location.
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.:
$ nix run github:hraban/mac-app-util -- sync-trampolines ~/special/apps/ ~/Applications/Special/
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 Copyright © 2023 Hraban Luyat
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, version 3 of the License.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License along with this program. If not, see https://www.gnu.org/licenses/.