Jump to content

Add ability to specify a script to be triggered in the script filter JSON format


Recommended Posts

Currently, if I output the following:

{"items": [
	{
		"title": "Foo",
		"arg": "unicorn"
	}
]}

I have to handle the `unicorn` arg in a connected output action in the workflow.

 

It would be useful to be able to dynamically handle it without needing to create an output action. This can be useful for very dynamic results and creating reusable modules that create output with different actions.

 

I propose adding a `script` property to the JSON format that when specified makes it not pass the output to any connected output action (like `valid: false`) and instead executes the `script` and passes `arg` to it.

{"items": [
	{
		"title": "Foo",
		"arg": "unicorn",
		"script": "run-foo.sh"
	}
]}

This would make script filters a lot more powerful.

Edited by sindresorhus
Link to comment
Share on other sites

This can already be achieved in various ways by using workflow variables and/or setting arg to a shell command.
 
There's no reason you can't create a Run Script Action with Language = /bin/bash and Script = {query} and then set arg in your JSON output to run-foo.sh myinput. You just need to take care of any necessary escaping yourself.
 
Or you could set a bunch of variables and use a JSON Config Utility to dynamically configure the following Action.
 
What I generally do is write my workflows as command-line programs with various arguments/modes, like --search or --open, that correspond to the workflow's Script Filters and/or Run Scripts. If you also connect the options to environment variables, e.g. MYPROG_SEARCH=wallop is equivalent to ./myprog --search wallop, then you can use workflow variables to connect as many Script Filters as you like to a single Run Script Action that just says ./myprog.

Edited by deanishe
Link to comment
Share on other sites

  • 4 weeks later...

@deanishe I'm aware of this, but I was looking for a way to do it completely programmatically without having to resort to any more workflow nodes or variables. In Alfy, I would have liked to create some reusable dynamic menus that users could make use of without having to add anything extra in the workflow view.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...