Jump to content

Keyword Arg mandatory but can be ignored with modifier key


Recommended Posts

Hi Alfred community, I'm trying to write a workflow where I want to trigger the workflow by a keyword, let's say `ss`. I want it to have `Argument Required` args, unless I use a modifier key (opt/cmd/shift) and then I can skip this mandate and do something. How can I accomplish this?

 

Right now, I entering a <space> as an arg and the conditional utility to perform a different action. I'm hoping I can change it to a modifier key

Link to comment

For such specific custom behaviour, you’ll need a Script Filter instead. Set the language to /usr/bin/osascript (JavaScript) and use this code:


function run(argv) {
  return JSON.stringify({ items: [{
    title: "YOUR TITLE HERE",
    subtitle: "YOUR SUBTITLE HERE",
    valid: argv.length > 0,
    arg: argv[0],
    mods: {
      cmd: { valid: true },
      alt: { valid: true },
      ctrl: { valid: true },
      shift: { valid: true }
    }
  }]})
}


Replace YOUR SUBTITLE HERE and YOUR SUBTITLE HERE with whatever you want.

Link to comment

@vitor I tried this and it works well. The only thing is now when I press `ss`, the resultant item `Search Splunk for...` always shows up at the end of the Alfred results despite my using it many times. Is there anything wrong I'm doing here? Alfred's most frequently used item feature works well for everything else for me.

 

Second, I enable the `Alfred filters results` for this script filter and when I would type something as an arg, Alfred would move away from this script filter and go back to my fallback results. Is that because what I'm typing cannot be found in the script results list? e.g., when I typed `ABC` this string is not in the results returns by the filter (since we only have `Search Splunk....`. Trying to understand if it's working that way.

 

Third, I searched a bit but could not find that we can change this setting via this code. Are these fields/options documented anywhere on Alfred's website?

 

 

image.thumb.png.b2bafa628856fc0a4d69db306e0c7c7b.png

 

 

 

Edited by andy4222
Link to comment
1 hour ago, andy4222 said:

always shows up at the end of the Alfred results despite my using it many times.

 

Add a uid: "search_splunk", line above the title one. The value of uid can be anything, it just needs to be static.

 

1 hour ago, andy4222 said:

I enable the `Alfred filters results` for this script filter

 

You can’t do that because you’ll no longer be able to set the custom argument.

 

1 hour ago, andy4222 said:

Are these fields/options documented anywhere on Alfred's website?

 

Script Filter JSON Format.

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