Jump to content

Presenting list of options, enter leads to more


Recommended Posts

I'm interested in making a custom workflow that behaves like the following scenario:

  1. the user types the keyword "disk" into Alfred
  2. the results shows a list of all of the volumes associated with the computer
  3. the user selects one of the volumes (ex: "Macintosh HD") and presses "enter"
  4. the search field updates to read "disk Macintosh HD"
  5. the results update to show a list of options that can be performed on the disk, like "Open in Finder", "Open in Terminal", "Get Info", etc
  6. the user selects one of these options and presses "enter" to perform the action

I've been poking around in Alfred, and I know how to do steps 1-3 and 5-6. What I don't know is how to tie them together. How can I make it so that selecting one alternative updates the UI to present more alternatives?

Link to comment

There are a bunch of ways to do this. One way that was developed a while ago can be read about in this thread. But it seems like that method would be overkill.

 

To take advantage of the "autocomplete" that Florian mentioned, you'd do something like this:

$query = "{query}";
$options = [ 'Macintosh HD', 'External HD' ];

print "<?xml version='1.0' encoding='UTF-8'?>\n";
print "<items>\n";
if ( ! in_array( $query, $options ) ) {
    foreach( $options as $option ) :
        print "<item autocomplete='{$option}' valid='no'>";
        print "<title>{$option}</title>";
        print "</item>";
    endforeach;
} else {
    $actions = [ "Open in Finder", "Open in Terminal", "Get Info" ];
    foreach( $actions as $action ) :
        print "<item arg='{$action}--{$query}' valid='yes'>";
        print "<title>{$query}: {$action}</title>";
        print "</item>";
    endforeach;
}
print "</items>\n";

So that's just a simple script filter.

 

When you pass it to the action, you'll want to make sure that you split the query passed, because the query will be in the form of:

{$action}--{$query}
Link to comment

Alternatively, you can use External Triggers to link two Script Filters together. Filter 1 connects to an AppleScript node that calls the External Trigger and passes the arg. Filter 2 is triggered by the external trigger and receives the arg as the query. My Pandoctor workflow (see sig) uses this method a lot.

Link to comment

It's a personal thing, but I think the External Trigger method is a bit sucky. It's totally one-way. After a trigger is called, there's no way back to the previous "screen" without closing and re-opening Alfred and entering the previous query again.

 

Having a massive query isn't ideal, either, but you can navigate back up again much more easily.

Link to comment

It's a personal thing, but I think the External Trigger method is a bit sucky. It's totally one-way. After a trigger is called, there's no way back to the previous "screen" without closing and re-opening Alfred and entering the previous query again.

 

Having a massive query isn't ideal, either, but you can navigate back up again much more easily.

True enough, but sometimes one way is all that's needed. Of course, Andrew could upgrade this facet of workflows in the future (here's to hoping).

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