zenangst / KeyboardCowboy

:keyboard: The missing keyboard shortcut utility for macOS
Other
805 stars 14 forks source link

Add support for contextual/environment arguments for script commands #45

Open zenangst opened 4 years ago

zenangst commented 4 years ago

I think it would increase usability if arguments could be passed to shell scripts using environmental or contextual variables.

Example:

If the user selects file(s) in Finder, the file(s) paths can be passed as arguments to an inline or path based script.

If we add support for passing of arguments, you could take it one step further and have one command produce output for the succeeding command(s). That could open up for command chains and ability to produce unique command type(s) that can take output.

Example:

Output from a script command is sent to an AnnounceCommand which has different types, either by using say command or notification center to render the result of the script execution result.

fushugaku commented 4 weeks ago

it would also be great to get stuff like variables, for example $clipboardText, $activeDisplay and etc. Maybe it would be great to have in-built text buffers, for example temp files where you could input-output data from and use their contents as variables. Stuff like this can already be done with some scripting and shortcuts, but it's a bit tedious

fushugaku commented 3 weeks ago

Also got an idea, if you can add a blank key/any key in shortut and then use it as a variable example - keybinding: fn+w+blank_key action: take the name of blank key, create a txt file with the name, like a.txt, paste clipboard to it, save file keybinding: fn+r+blank_key action: paste from this blank_key txt file

I have a lot of text snippets mapped to keys - it would greatly improve the process of creating new one's

zenangst commented 3 weeks ago

@fushugaku, so you're saying 'blank key' means 'Any Key'? That means the last part of the sequence can be anything you want, right?

fushugaku commented 3 weeks ago

yep, just any key at the end of sequence

zenangst commented 3 weeks ago

I like this idea, added it to my R&D list 🤓

zenangst commented 2 weeks ago

Hey @fushugaku, I started tinkering with this feature and have a working prototype now.

image

In this example, just like you described, ending the sequence with any key will trigger the workflow. The 'LAST_KEY' will be filled with the key you pressed. And if you have a rebinding, like 'shift+(' being a workflow that reassigns that key to another key press, then your rebinding will override the regular system event.

(I have a bunch of rebindings when it comes to coding, which are specific to Xcode, Terminal, and other editors, so for me, that's really helpful).

Based on the example you provided, you can use the same variable as shown in the screenshot to create a folder or file.

fushugaku commented 2 weeks ago

Wow, that looks really cool, thank you!

zenangst commented 2 weeks ago

@fushugaku here is a pre-release if you want to take it for a spin 😎

Keyboard Cowboy 3.25.5.dmg.zip

fushugaku commented 2 weeks ago

tried it, how do i type in ANY in the shorcut?) $LAST_KEY works, but only for key that was pressed in the combination.

image

also a small bug - for example when i use this shortut it should be "a", but now it pastes "w"

zenangst commented 2 weeks ago

@fushugaku I thought about that myself, that is why I added a button to the left of the recorder button.

image

I should probably make that more visible to the user 😁

fushugaku commented 2 weeks ago

oh, I installed the wrong version %) yep, can see it now, will replace my buffer read-write and return with results

zenangst commented 2 weeks ago

Nice, let me know how it goes!

fushugaku commented 2 weeks ago

tried it like this, didn't work for me, looks like the file is not created for some reason Pasting last letter is okay, but I guess it doesn't work yet in terminal scripts

image
zenangst commented 1 week ago

I didn’t try this with pass through, perhaps that and the Any key is in conflict. Will need to investigate a bit.

zenangst commented 1 week ago

@fushugaku Found the issue, here is a new version.

Keyboard Cowboy 3.25.5.dmg.zip

Basically, I forgot to add these to the terminal environment. As you can see in my screenshot, I tested this with string interpolations with the type command. Totally forgot that there where to different codepaths.

fushugaku commented 1 week ago

works as intended, thank you!

fushugaku commented 1 week ago

found a bug :) this scenario doesn't work:

image

this does:

image

the only difference is that i have an extra key after first sequence

zenangst commented 1 week ago

@fushugaku Are you running the workflow as concurrent or sequential? To ensure order, it should use sequential.

zenangst commented 1 week ago

But I am gonna look into why the number of keys in sequence might affect the outcome.

fushugaku commented 1 week ago

Tried it with sequential - same result

zenangst commented 1 week ago

@fushugaku Yeah then there is something wonky with the keybinding and when to trigger the command. I'll investigate and get back to you. Thanks again for reporting and beta testing ❤️

zenangst commented 1 week ago

Hey @fushugaku, I've tried to replicate this and it works for me. Do you have any conflicting shortcuts?

image

I've also attached a new version of the code. I made some additional changes to the source code, which might have fixed the issue. Let me know if it works for you!

Keyboard Cowboy 3.25.5.dmg.zip

fushugaku commented 1 week ago

Hi! Thank you, tried it, it worked one time with concurrent, but now I can't make it work (doesn't work with serial either), cmd+c shortcut for some reason is not triggered it but works in a shortcut without any key %)

image

When i remove any_key - works just fine, like here

image
zenangst commented 6 days ago

@fushugaku I'll take another look when life allows :)