Jump to content
sindresorhus

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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

@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.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...