Created
July 18, 2022 11:42
-
-
Save vojtaholik/ef7ce2ae4a9ecb10426639630376bf91 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