February 2021 (version 1.6.9) - Built-in Editor, New Main Menu Features, `await path()`, Event handlers, Beta pro features, Terminate Process

Been a busy month of major Script Kit features!

Built-in Editor

Script Kit's number one goal is to make writing time-saving scripts easier. So now Script KIt comes with a pre-configured editor, complete with autocompletion and error checking:

If you're already using vs code, you can switch to the "Kit" editor in the Kit tab -> Change Editor.

Main Menu Shortcuts and /, ~, and >

The Script Kit main menu will continue to grow in features.

Shortcuts

  • cmd+f - Does a grep search through all of your scripts
  • cmd+p - Launches a Processes menu for currently running scripts

Path Mode

Type the following characters to change the mode of the main menu:

  • ~ Switches to a path selector mode in your home directory
  • / Switches to a path selector mode in your root directory

Navigate with right/left or tab/shift+tab then select with return. Here's an example of typing ~

Command Mode

  • > Switches to a command mode to execute a command

Future Work

In the March release, planning on these:

  • , List system preferences
  • . App launcher
  • ; MEGA MENU WITH EVERYTHING 🤭

await path()

You can now prompt to select a path. This UI works exactly like "path mode" above.

let selectedPath = await path()
cd(selectedPath)
await exec(`git pull`) // this will now operate based on the selectedPath

Event Handlers

When building the path prompt, I realized it just wasn't possible to do in a script. So I put in the effort to expose the event handlers from the app into the prompt. So even though path behaves very differently, it's still an arg with customized handlers. You can override many of the handlers yourself for customized prompts:

For example, you can override the default behavior of Escape terminating your current script:

// Submit the current input when you hit escape
await arg({
onEscape: (input)=> {
submit(input)
}
})

Overriding handlers is definitely considered "advanced", so I'm happy to answer any questions!

Here's a list of all the new arg config properties:

export interface ChannelHandler {
(input: string, state: AppState): void | Promise<void>
}
export interface PromptConfig
onNoChoices?: ChannelHandler
onChoices?: ChannelHandler
onEscape?: ChannelHandler
onAbandon?: ChannelHandler
onBack?: ChannelHandler
onForward?: ChannelHandler
onUp?: ChannelHandler
onDown?: ChannelHandler
onLeft?: ChannelHandler
onRight?: ChannelHandler
onTab?: ChannelHandler
onInput?: ChannelHandler
onBlur?: ChannelHandler
onChoiceFocus?: ChannelHandler
debounceInput?: number
debounceChoiceFocus?: number
onInputSubmit?: {
[key: string]: any
}
onShortcutSubmit?: {
[key: string]: any
}
}

onInputSubmit, onShortcutSubmit

If you want to create "shortcuts" to submit specific values, can use the new onInputSubmit and onShortcutSubmit. These allow you to bind text or shortcuts to submit values. This is exactly how the main menu works:

CleanShot 2022-02-03 at 09 47 42

Beta Pro Features: Menubar

You can now customize the text of the Script Kit menubar icon to say anything with the pro.beta.menubar method. In the future, you'll be able to build out an entire menu, but I thought I'd sneak this feature in for fun in this build:

Open menubar-demo in Script Kit

// Name: Menubar Demo
import "@johnlindquist/kit"
let value = await arg("Set the menubar to:")
pro.beta.menubar(value)

Terminate Processes

If you need to end a script that's running in the background, stuck on an exec command, or whatever reason, open the main menu with the cmd+; shortcut, then press this button (or hit cmd+p. This will open a "terminate processes" window where you can end your scripts:

CleanShot 2022-02-03 at 10 20 45@2x

Discuss Post