Skip to content

Instantly share code, notes, and snippets.

@yanyaoer
Created September 20, 2024 08:03
Show Gist options
  • Save yanyaoer/63b40dc2ca9737286b34e89689fc5fa7 to your computer and use it in GitHub Desktop.
Save yanyaoer/63b40dc2ca9737286b34e89689fc5fa7 to your computer and use it in GitHub Desktop.
simple app/shortcuts/cli luncher on macos
#!/usr/bin/env bash
# brew install choose-gui
# https://github.com/chipsenkbeil/choose?tab=readme-ov-file#open-apps-from-the-applications-directories
# bindkey with .skhdrc
# ctrl + alt + shift + cmd - r : app-choose.sh
shopt -s nullglob globstar
candidate() {
APPS=(
/Applications/
/Applications/Utilities/
/System/Applications/
/System/Applications/Utilities/
)
arr=$(ls "${APPS[@]}" | grep '\.app$');
arr+=$(/usr/bin/shortcuts list | xargs -I{} echo short-{});
printf '%s\n' "${arr[@]}"
}
runner() {
echo "$@"
if [[ $@ == short-* ]]; then
/usr/bin/shortcuts run ${@#short-}
elif [[ $@ == *.app ]]; then
open -a "$@"
else
eval "$@"
fi
}
export -f runner
candidate | \
choose -m | \
xargs -I {} bash -c 'runner "$@"' _ {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment