Jump to content
tam131

Mapping arguments in Workflows

Recommended Posts

Hey all, 

 

I'm brand new to Alfred and would like to set up some easy-to-update workflows for my support team coworkers. I believe a Script Filter is best suited for my requirements but I am hoping I'm overlooking another workflow which doesn't require any coding skills. While I'm a developer and can easily write the code required for this for my requirements, I want it to be easy to update for the non-developer members of my team.

 

My first workflow idea is very basic. I would like a keyword argument pair to map that argument to a URL and then open that URL in the browser. There will be over 50 argument and URL combos so I would prefer not to create a keyword for each but to have a single keyword control this and open the correct URL based on the argument passed. 

So I was hoping to have a keyword set up some with mapping like:

 

arg     url

arg1  http://url1.com

arg2  http://url2.com

arg3  http://url2.com

...        ...

 

so when the use types "keyword arg2" in Alfred, the default browser opens http://url2.com.

 

I tried using the List Filter but that doesn't seem to let me set a "value" for the argument. Is there any input object or utility I can use in Alfred to set this up without any code?

 

I have lots of other ideas for workflows to help our team and I'm hoping once I figure this out I will be better acquainted with the app in order to put those together with minimal code. 

 

Thanks for your help.

Share this post


Link to post

Thanks for your reply! 

 

I understand how to open a URL so far. I’d like to type a command in Alfred and have it open a URL based on the argument. 

 

So my keyword right now is set to be “wcp”. When I type out “wcp coa” (coa is just an abbreviation of one of our products), i’d like Alfred to open the product’s documentation in a browser.

 

I understand I can manually set up all 50+ documentation links as separate keywords but I want to see if it’s possible to have one keyword which opens the links based on an argument => URL mapping. 

 

One more example, if I type “wcp prp”, I’d like Alfred to open the PRP product’s documentation. 

 

Basically my question is: “is there a way to manipulate the query argument, change it to something else, before it’s passed to the URL action?”  

 

I could do this with code but it would be less maintainable for the rest of my team.  

 

I’m not sure if that’s made my requirements a bit easier to understand. I initially thought the List Filter would do this for me as it allows you to set up a list of arguments so I thought I could also map the arguments to their intended values. 

 

Thanks so much! 

Share this post


Link to post

If this isn’t possible, that’s not a big issue as I can have an array in the code which maps to the correct value and arrays are easy enough to update for most people. I’m more interested in learning what can be done with the app so I can wrap my head around all of the functions. 

Share this post


Link to post
3 hours ago, tam131 said:

I tried using the List Filter but that doesn't seem to let me set a "value" for the argument.

 

That's exactly how you do it. The URL goes in the Arg field.

 

list-filter-config.png

Share this post


Link to post

Hi deanishe,

 

Thanks, I must be confused then. I thought I would need to have the argument I type out into Alfred in the Arg field. If that's not the case, then where would I set up that argument?

 

Maybe I'm still having trouble expressing what it is I'm looking to do. 

 

I have over 50 key-value pairs. For the developers here, think of an associative array. They look like so:

 

array(

'product1' => 'http://docs.domain.com/products-full-name-1',

'product2' => 'http://docs.domain.com/products-full-name-2',

'product3' => 'http://docs.domain.com/products-full-name-3',

'product4' => 'http://docs.domain.com/products-full-name-4',

...

'product55' => 'http://docs.domain.com/products-full-name-55',
);

 

I'm wondering if there is a way to set up a keyword ("wcp") workflow without any code (or minimal code) to map the argument (key in the array) to the URL (value in the array) so that when I type the following into Alfred, http://docs.domain.com/products-full-name-3 (the URL from the value) is opened in my browser:

 

wcp product3

 

How could i use the List Filter to do that? This would be the optimal workflow as it allows for CSV importing, making it easier for our team to upkeep.

 

This particular problem I'm trying to solve can be easily done with code and would be rather maintainable even by the team members who haven't touched a line of code in their life. That's because I could just do an array like above and look up the query. However, I'm using this as an example project so I can get more familiar with how Alfred works and what is possible with workflows out of the box.

 

Thanks!

 

 

 

Share this post


Link to post

Have you tried setting Title to "product3" and Arg to the URL? (Subtitle is optional.) When I do that and type "wcp product3" in Alfred, the result shows up.

 

Note that if you drop a CSV file onto the list, it will not update the existing items, it will just add the items as duplicates. So you need to delete all the existing items first.

 

Have you considered using a Script Filter which reads the items from an external file, be it CSV, JSON, or whatever? That way your team doesn't have to muck about with Alfred's UI or your script to update the items. This file could even be retrieved from a webserver, so that any changes are immediately visible to your entire team.

Edited by Tsunami

Share this post


Link to post

I went ahead and created the workflow for you using dummy data.

You can download it here.

 

As per your description, it's triggered using the keyword `wcp`, which accepts a single argument, currently `product1`, `product2`, ... , `product55`.  Upon selection, the URL referenced by argument entered gets passed to the next action.  There's an Open URL action waiting on the workflow's workspace, not yet connected to the trigger.  Instead, a Large Type output receives the URL, allowing you to preview the URL fully for testing purposes.

 

Mapping Arguments in Workflows (screen shot)

Share this post


Link to post
2 minutes ago, CJK said:

I went ahead and created the workflow for you using dummy data.

You can download it here.

 

As per your description, it's triggered using the keyword `wcp`, which accepts a single argument, currently `product1`, `product2`, ... , `product55`.  Upon selection, the URL referenced by argument entered gets passed to the next action.  There's an Open URL action waiting on the workflow's workspace, not yet connected to the trigger.  Instead, a Large Type output receives the URL, allowing you to preview the URL fully for testing purposes.

 

Mapping Arguments in Workflows (screen shot)

 

Wow thank you so much for this! Clearly my testing of the List Filter was very flawed as I didn't realize it works this way. This is perfect and exactly what I was looking for!

Share this post


Link to post

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