Jump to content

Fill an input's title and subtitle with result from script?


Recommended Posts

Hi,

 

I have a workflow where a script returns a path to open. This works just fine. But ideally instead of naming my workflow something like "Open current destination" I'd rather name it something like "Open <resolved filename>". So basically I want the script to execute _before_ I hit return and then put the result in the name of my input trigger.

 

Is this possible somehow?

 

—Michael

Link to comment
1 hour ago, vitor said:

It is possible with a Script Filter.

 

With a script filter this becomes a two step thing though I believe. If I add a script filter that always returns just a single entry, during autocomplete when I start typing the command (say I have foobar as the name and I type foo) it completes with the placeholder text and only if I hit return it then switches over to the list entry.

 

I only have a single entry all the time so the initial step is one I don't really want / need.

Link to comment

No, with a Script Filter you can have your entry say anything you want. There’s no difference between returning one result or multiple; technically you don’t need your Script Filter to filter anything. It’s the only way to execute code as you type and have it programmatically show up in the results.

 

The exact implementation will depend on your Workflow. Right now we only have a vague description, without seeing it it’s not possible to be more precise.

Link to comment

So what I am seeing is, I set up a Script Filter that reacts to a keyword, say "foobar", and I give it a placeholder title of "Open current foobar", and then in the script filter just return a list with a single item that has a title of "Open foobar from <path>".

 

Now when I type "foo", Alfred shows the list as the top and most likely target, but its title says "Open current foobar". I first have to hit return for it to start showing the result and with that "Open foobar from <path>". I then have to hit return again to actually trigger that action. What I'd want is the original entry just showing "Open foobar from <path>" right away and just having to hit return once to trigger that action.

 

Am I setting the wrong options here for that script filter?

Link to comment
5 hours ago, virpio said:

I first have to hit return for it to start showing the result


You don’t hit return to show the result, you do it to complete the keyword. Showing the result happens after that. It’s an important distinction.

 

5 hours ago, virpio said:

What I'd want is the original entry just showing "Open foobar from <path>" right away


You can’t, and that’s by design. Imagine if every Script Filter auto-ran with partial keywords: you’d have tons of Workflows running all the time by mistake, cluttering and slowing down your results.


You’re asking for things to run before they are called, which is impossible. If you need the Script Filter to trigger sooner, consider shortening its keyword.

Link to comment
On 2/22/2022 at 10:52 PM, virpio said:

I first have to hit return for it to start showing the result and with that "Open foobar from <path>".

 

Sounds like you've set it up wrong. If the keyword is "foo", Alfred should run the Script Filter (and show its results) as soon as you type "foo" (or "foo " if you've checked "with space"). Have you set it to "Argument Required"? That would explain why it's not running immediately.

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