Created
January 25, 2022 06:43
-
-
Save vojtaholik/9c2e6473396d90513f9942352f9e5359 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import "@johnlindquist/kit" | |
// Menu: App Launcher | |
// Description: Search for an app then launch it | |
// Author: John Lindquist | |
// Twitter: @johnlindquist | |
let createChoices = async () => { | |
let apps = await fileSearch("", { | |
onlyin: "/", | |
kind: "application", | |
}) | |
let prefs = await fileSearch("", { | |
onlyin: "/", | |
kind: "preferences", | |
}) | |
let group = path => apps => | |
apps | |
.filter(app => app.match(path)) | |
.sort((a, b) => { | |
let aName = a.replace(/.*\//, "") | |
let bName = b.replace(/.*\//, "") | |
return aName > bName ? 1 : aName < bName ? -1 : 0 | |
}) | |
return [ | |
...group(/^\/Applications\/(?!Utilities)/)(apps), | |
...group(/\.prefPane$/)(prefs), | |
...group(/^\/Applications\/Utilities/)(apps), | |
...group(/System/)(apps), | |
...group(/Users/)(apps), | |
].map(value => { | |
return { | |
name: value.split("/").pop().replace(".app", ""), | |
value, | |
description: value, | |
} | |
}) | |
} | |
let appsDb = await db("apps", async () => ({ | |
choices: await createChoices(), | |
})) | |
let app = await arg("Select app:", appsDb.choices) | |
let command = `open -a "${app}"` | |
if (app.endsWith(".prefPane")) { | |
command = `open ${app}` | |
} | |
exec(command) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment