kit icon indicating copy to clipboard operation
kit copied to clipboard

I ran into some confusion / odd-to-me behavior while trying out `path()` with an argument

Open johnlindquist opened this issue 3 years ago • 9 comments

  I ran into some confusion / odd-to-me behavior while trying out `path()` with an argument. It is possible that I'm not specifying the option correctly. I wanted to specify a path relative to my home directory (`~/code/til`). That didn't seem to work, so I ended up using the absolute path. Here is a video demonstrating the behavior. The format might be a little weird as I was half in the mindset of demonstrating the behavior and half in the mindset of recording a screencast.

https://user-images.githubusercontent.com/694063/202872232-bb84fa39-172f-46a9-ae10-9506d85ccc7d.mp4

Originally posted by @jbranchaud in https://github.com/johnlindquist/kit/discussions/809#discussioncomment-4185882

johnlindquist avatar Nov 21 '22 17:11 johnlindquist

@jbranchaud does await path() without an argument have the same behavior for you? I should default to the home directory...

johnlindquist avatar Nov 21 '22 17:11 johnlindquist

@jbranchaud does await path() without an argument have the same behavior for you? I should default to the home directory...

@johnlindquist I just tried await path() without an arg and it exhibits the same behavior.

jbranchaud avatar Nov 21 '22 17:11 jbranchaud

@jbranchaud Thanks, can't reproduce on my main machine, hoping I can on my mac mini and my old laptop 😅

johnlindquist avatar Nov 21 '22 18:11 johnlindquist

Some repro details:

  • ScriptKit v1.36.0
  • OSX Catalina v10.15.7 (Intel chip)

jbranchaud avatar Nov 21 '22 18:11 jbranchaud

I wanted to come up with a minimal repro script and found a potential clue.

This script works as expected:

// Name: View a TIL
import "@johnlindquist/kit";
await path();

When I add in the Shortcut comment and trigger it with the shortcut is when the path() bug shows up:

// Name: View a TIL
// Shortcut: cmd shift j
import "@johnlindquist/kit";
await path();

When I trigger the above script from the scriptkit UI, the path bug doesn't show up. So, it seems the shortcut trigger and path are mixing poorly.

jbranchaud avatar Nov 21 '22 18:11 jbranchaud

@jbranchaud THANKS! I couldn't reproduce anywhere, but I can definitely reproduce when invoking from a shortcut! Yay

johnlindquist avatar Nov 21 '22 19:11 johnlindquist

Ok, figured it out.

  1. Prompts have Filter/Generate choices modes
  2. The mode is set when the prompt is opened
  3. When using a shortcut, await path() sets the choices before the prompt is opened and the mode is set

Note: await path() manually calls setChoices() instead of using arg/div/etc which create "prompt data". It's extremely rare to setChoices before a prompt is open, so this shouldn't impact anything and probably only shows up in this specific scenario.

The fix is a one-liner in the app:

// If the promptData isn't set, default to Mode.FILTER
const mode = g(promptData)?.mode || Mode.FILTER;

I'll get out a bugfix build later this week. Thanks for the help.

johnlindquist avatar Nov 21 '22 21:11 johnlindquist

@jbranchaud Can you test this build? Just download, quit Kit.app, then drag this over to replace it.

https://github.com/johnlindquist/kitapp/releases/download/v1.36.1/Kit-1.36.1.dmg

johnlindquist avatar Nov 21 '22 23:11 johnlindquist

@johnlindquist I just tried the build, that fixed it!

jbranchaud avatar Nov 22 '22 21:11 jbranchaud