Skip to content

Commit

Permalink
refactor: remove raycast and use workaround to add apps to spotlight
Browse files Browse the repository at this point in the history
  • Loading branch information
squirmy committed Nov 2, 2023
1 parent e948520 commit da602f5
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 9 deletions.
1 change: 1 addition & 0 deletions home/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

# Programs and packages to manage with home manager.
imports = [
./trampoline.nix
./terminal.nix
./secrets.nix
./ssh.nix
Expand Down
38 changes: 38 additions & 0 deletions home/trampoline.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Why: Applications installed by home-manager don't show up in spotlight. This
# module works around the issue. Can be removed if this is ever included
# in home-manager.
# Issue: https://github.com/nix-community/home-manager/issues/1341
{
config,
pkgs,
lib,
...
}: {
home.activation = {
trampolineApps = let
apps = pkgs.buildEnv {
name = "home-manager-applications";
paths = config.home.packages;
pathsToLink = "/Applications";
};
in
lib.hm.dag.entryAfter ["writeBoundary"] ''
toDir="$HOME/Applications/HMApps"
fromDir="${apps}/Applications"
rm -rf "$toDir"
mkdir "$toDir"
(
cd "$fromDir"
for app in *.app; do
/usr/bin/osacompile -o "$toDir/$app" -e "do shell script \"open '$fromDir/$app'\""
icon="$(/usr/bin/plutil -extract CFBundleIconFile raw "$fromDir/$app/Contents/Info.plist")"
if [[ $icon != *".icns" ]]; then
icon="$icon.icns"
fi
mkdir -p "$toDir/$app/Contents/Resources"
cp -f "$fromDir/$app/Contents/Resources/$icon" "$toDir/$app/Contents/Resources/applet.icns"
done
)
'';
};
}
10 changes: 1 addition & 9 deletions nix-darwin/homebrew.nix
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,6 @@
# If an app isn't available in the Mac App Store, or the version in the App Store has
# limitiations, e.g., Transmit, install the Homebrew Cask.
homebrew.casks = [
# Raycast
# Raycast is a blazingly fast, totally extendable launcher. It lets you
# complete tasks, calculate, share common links, and much more.
# https://www.raycast.com/
# Why: Applications installed by home-manager don't show up in spotlight.
# Issue: https://github.com/nix-community/home-manager/issues/1341
"raycast"

# 1password
# A password manager, digital vault, form filler and secure digital wallet.
# https://1password.com
Expand All @@ -32,7 +24,7 @@
"1password"
];

# For cli packages that aren't currently available for macOS in `nixpkgs`.Packages should be
# For cli packages that aren't currently available for macOS in `nixpkgs`. Packages should be
# installed in `../home/default.nix` whenever possible.
homebrew.brews = [
];
Expand Down
58 changes: 58 additions & 0 deletions trampoline.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/usr/bin/env bash

# dest="/Users/${username}/Applications/Home Manager Trampolines/"
# src="${apps}/Applications/"
# rm -rf "$dest" && mkdir -p "$dest"
# export dest

# for file do
# # escape the filename because space separated filenames suck
# filename="''${file@Q}"
# appname="$(basename "$file")"
# out="$dest/$appname"

# # This is basically going to be the script body
# open_cmd=(
# "open"
# \"$file\"
# )
# open_cmd="''${open_cmd[@]}"

# # generate a wrapper app visible to spotlight
# wrapper=(
# "do"
# "shell"
# "script"
# "$open_cmd"
# )
# wrapper="''${wrapper[@]}"
# /usr/bin/osacompile -o "$out" -e "$wrapper" 2>/dev/null

# # time to make stuff visible in spotlight
# plutil=/usr/bin/plutil
# contents=/Contents
# resources="$contents/Resources"
# plist="$contents/Info.plist"

# # splice in the icon
# icon="$("$plutil" -extract CFBundleIconFile raw "$file/$plist")"
# icon="''${icon%.icns}.icns"
# icon_src="$file/$resources/$icon"
# mkdir -p "$out/$resources" && cp "$icon_src" "$_/applet.icns"
# done

function thing() {
files=("$@")

for file in "${files[@]}"; do

/usr/bin/osacompile -o "$toDir/$app" -e 'do shell script "open \"$fromDir/$app\""'
icon="$(/usr/bin/plutil -extract CFBundleIconFile raw "$fromDir/$app/Contents/Info.plist")"
mkdir -p "$toDir/$app/Contents/Resources"
cp -f "$fromDir/$app/Contents/Resources/$icon" "$toDir/$app/Contents/Resources/applet.icns"

done
}

export -f thing
find . -exec sh -c 'thing "$@"' sh {} +

0 comments on commit da602f5

Please sign in to comment.