Shortcodes

Shortcodes require Kit-1.3.0-beta.6.dmg

Shortcodes are like writing acronyms to quickly get to specific choices of a script.

To run the following script and select "Banana" and "Cookie" type "a", space, "b", space, "c":

// Shortcode: a
let fruit = await arg("Type 'b' then spacebar", [
{
name: "Apple",
value: "apple",
},
{
name: "Banana",
value: "banana",
shortcode: "b",
},
])
let treat = await arg("Type 'c' then spacebar", [
{
name: "Donut",
value: "donut",
},
{
name: "Cookie",
value: "cookie",
shortcode: "c",
},
])
await arg(`${fruit}, ${treat}`)

Shortcodes also enable "English" shortcuts. From the main menu, type "go fish " or "go eat " to quickly drill down to one of these choices:

//Shortcode: go
let message = await arg("Where?", [
{
name: "Lunch",
shortcode: "eat",
value: "Gone out to lunch",
},
{
name: "Fishing",
shortcode: "fish",
value: "Gone fishin'",
},
])
await arg(message)
Discuss Post

Global API

Here are the global api methods and their types. I'll add more explanation/organization soooooon :D

Note: These are all proxied/lazy loaded. They won't be "required" until you actually invoke the method.

cd: typeof shelljs.cd
cp: typeof shelljs.cp
chmod: typeof shelljs.chmod
echo: typeof shelljs.echo
exec: typeof shelljs.exec
exit: typeof shelljs.exit
grep: typeof shelljs.grep
ln: typeof shelljs.ln
ls: typeof shelljs.ls
mkdir: typeof shelljs.mkdir
mv: typeof shelljs.mv
sed: typeof shelljs.sed
tempdir: typeof shelljs.tempdir
test: typeof shelljs.test
which: typeof shelljs.which
rm: typeof trashType //use `trash` instead
spawn: typeof child_process.spawn
spawnSync: typeof child_process.spawnSync
fork: typeof child_process.fork
get: AxiosInstance["get"]
put: AxiosInstance["put"]
post: AxiosInstance["post"]
patch: AxiosInstance["patch"]
readFile: typeof fsPromises.readFile
writeFile: typeof fsPromises.writeFile
appendFile: typeof fsPromises.appendFile
createWriteStream: typeof fs.createWriteStream
readdir: typeof fsPromises.readdir
compile: typeof handlebars.compile_
cwd: typeof process.cwd
pid: typeof process.pid
stderr: typeof process.stderr
stdin: typeof process.stdin
stdout: typeof process.stdout
uptime: typeof process.uptime
path: typeof import("path")
_: LoDashStatic
uuid: typeof uuidType.v4
chalk: ChalkFunction
paste: typeof clipboardy.read
copy: typeof clipboardy.write
db: DB
trash: typeof trashType
wait: Wait
home: Path
isFile: IsCheck
isDir: IsCheck
isBin: IsCheck
tmp: Path
inspect: Inspect
compileTemplate: CompileTemplate
md: Markdown
applescript: AppleScript
setPlaceholder: SetAppProp
setPanel: SetAppProp
setHint: SetAppProp
setInput: SetAppProp
setIgnoreBlur: SetAppProp
setChoices: (choices: Choices<any>) => void
sendResponse: (value: any) => void
show: ShowAppWindow
showImage: ShowAppWindow
edit: Edit
terminal: (script: string) => Promise<string>
iterm: (iterm: string) => Promise<string>
notify: typeof notifyType
Discuss Post

User Input

await arg()

let input = await arg()

Launches the prompt, waits for user input.

await env("SOME_TOKEN")

let SOME_TOKEN = await env("SOME_TOKEN")

Launches the prompt if var isn't found in .env. Waits for user input. Automatically stores var in .env.

await drop()

let dropData = await drop()

Launches the prompt as a drop target.

await hotkey()

let keyInfo = await hotkey()

Launches the prompt and waits for a key combination.

Discuss Post

Metadata

// Shortcut

// Shortcut: cmd opt shift ctrl a

Automatically assigns a keyboard shortcut to the script. Will update each time you save the file. You can also change shortcuts in Main Menu -> Help -> Change script shortcut

// Menu

// Menu: My Awesome Script

Customizes the name of the script in the main menu

// Description

// Description: This script does something awesome

Describes the script in the main menu

// Author and // Twitter

Credits you when the script runs with a prompt

✨ New ✨ in Kit-1.3.0-beta.4

// Exclude

// Exclude: true

Hides the script from the Main Menu (can still be run from shortcuts, schedule, system, etc).

// Schedule

// Schedule: */10 * * * * *

Runs the script on a cron schedule.

// System

// System: unlock-screen

Runs the script on a system event.

Available events:

  • suspend
  • resume
  • on-ac
  • on-battery
  • shutdown
  • lock-screen
  • unlock-screen
  • user-did-become-active
  • user-did-resign-active

Read about the available events here

Discuss Post