Jump to content

Fallback action when script filter has no results


Recommended Posts

I'm trying to figure out how to trigger an action from a script filter in the event that there's no match. 

 

I've hacked together a workflow (hotkey: cmd+shift+2 --> script filter) that allows me to manage text keywords/tags, and I'm trying to refine it further. Currently, the script filter I've cobbled together selects existing keywords/tags from a json file and pastes them wherever the cursor is placed or, if an action modifier is invoked at point of selection, deletes the selected keyword from the json file.

 

I've already figured out a separate workflow that can allows me to add a keyword to the json file, but I'd like to everything to be triggered by the same hotkey.

 

Any pointers? Thanks in advance for any help!

Link to comment
5 hours ago, jslr said:

I'm trying to figure out how to trigger an action from a script filter in the event that there's no match. 

 

Alfred doesn't offer that feature. You have to do that yourself in code, i.e. test if you have no results and then run some other process.

5 hours ago, jslr said:

if an action modifier is invoked at point of selection, deletes the selected keyword from the json file.

 

I have no idea what that means.

 

5 hours ago, jslr said:

I've already figured out a separate workflow that can allows me to add a keyword to the json file, but I'd like to everything to be triggered by the same hotkey.

 

I also don't really understand what it is you're trying to achieve here. At any rate, Alfred does not allow you to set the same hotkey for different workflows. You'll have to implement your own logic behind a single hotkey to decide what to do.

Link to comment
1 hour ago, deanishe said:

Alfred doesn't offer that feature. You have to do that yourself in code, i.e. test if you have no results and then run some other process.

 

Ah. Thanks for setting me straight there. I was thrown because the script filter seems to stop dead when the input is beyond the scope of the filter's results...

 

1 hour ago, deanishe said:

I have no idea what that means.

 

My script filter is currently connected to two actions. On enter, the result is passed to a "copy to clipboard action". On enter+cmd, the result is passed on to a "run script" action that deletes the selected item from the json file that powers the filter. 

 

1 hour ago, deanishe said:

I also don't really understand what it is you're trying to achieve here.

 

Apologies for any lack of clarity— first time trying to author my own workflow. The intended workflow: 

 

hotkey(cmd+shift+2): call Alfred and display list of text items from json file for selection

- press enter: paste selected text item to frontmost app

-- if input doesn't match anything in the filter, add input to json that powers the script filter AND paste to frontmost app [this is what I'm trying to work out]

- press cmd+enter: delete selected item from the json that powers the script filter

 

Edited by jslr
Link to comment
30 minutes ago, jslr said:

-- if input doesn't match anything in the filter, add input to json that powers the script filter AND paste to frontmost app [this is what I'm trying to work out]

 

Connect a second action to your Script Filter that adds the input to the JSON. In that script, you can test if it's already in there and do nothing. If you want to get fancy about it, set a workflow variable in that result (i.e. when the input isn't in the JSON), e.g. "addnew=true", and use a Filter element before your add-to-JSON action to only pass when "addnew" is set to "true".

Link to comment

Thanks! This makes a lot of sense, and I've got a piece of script ready to go with the appropriate conditional switch, but my problem is that if the input doesn't match anything in the filter list, Alfred won't do anything. Pressing enter has no effect, so I don't know how to manipulate call upon that input with the script. Feels like I'm close... Is there a setting in the first script filter itself that I could be overlooking?

Link to comment

No. You have to show a result that you can action to tell Alfred to perform the next action.

 

In principle, you need to check if you have any results from your JSON to show, and if not, create another result saying, "Add tag XYZ and save tag".

 

I can't give you any concrete help because you haven't posted your workflow for me to look at.

Link to comment

This is great. 

 

I know— my hack of Shawn's workflow was still unfinished. I had an add action that ran off a separate hotkey, and another one that wasn't wired in yet. Your demo gives me a lot to learn from. Thank you!

 

Now, must get my head around Python... ;)

Link to comment

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