Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
zenangst opened this issue Sep 13, 2020 · 24 comments
Open
Labels
discussion Further information is requested

Comments

@zenangst
Copy link
Owner

zenangst commented Sep 13, 2020

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
Copy link

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
Copy link

fushugaku commented Nov 7, 2024

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
Copy link
Owner Author

zenangst commented Nov 7, 2024

@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
Copy link

yep, just any key at the end of sequence

@zenangst
Copy link
Owner Author

zenangst commented Nov 7, 2024

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

@zenangst
Copy link
Owner Author

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
Copy link

Wow, that looks really cool, thank you!

@zenangst
Copy link
Owner Author

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

Keyboard Cowboy 3.25.5.dmg.zip

@fushugaku
Copy link

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
Copy link
Owner Author

@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
Copy link

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

@zenangst
Copy link
Owner Author

Nice, let me know how it goes!

@fushugaku
Copy link

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
Copy link
Owner Author

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

@zenangst
Copy link
Owner Author

@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
Copy link

works as intended, thank you!

@fushugaku
Copy link

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
Copy link
Owner Author

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

@zenangst
Copy link
Owner Author

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

@fushugaku
Copy link

Tried it with sequential - same result

@zenangst
Copy link
Owner Author

@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
Copy link
Owner Author

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
Copy link

fushugaku commented Nov 27, 2024

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
Copy link
Owner Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants