Jump to content
Heydomdom

Multiple arguments to multiple tabs in one query

Recommended Posts

I can make a simple simple query to open a browser and load a page, but how can I enter multiple arguments separated by a space or a comma to open multiple tabs with those arguments?

 

For instance I can easily make a single workflow as follows:

"Stock" -> aapl -> http://www.google.com/finance?q={query} and that inserts "aapl" in the {query} area and returns the correct page.

 

What I want to do is:

"Stock" -> aapl, amzn, fb, sfix -> and that send the URL command 4 times, each with a a different query so that I have four open tabs, each showing the different stock price.

 

Is there a simple way to do this? I can't figure out how to parse the query and had it open four tabs.

 

Thanks.

 

 

Share this post


Link to post

@Heydomdom Welcome to the forum! 

 

Could you please fill in your Powerpack email address in your forum profile? This is only visible to admins (Andrew and myself) and allows us to confirm your Powerpack status first. :) We'll then be happy to help you out with your question.

 

Cheers,
Vero

Share this post


Link to post

I've added the email.. You bring up a good point there as well. Is it possible for me to one day change my powerpack email as I'm phasing out my use of that email address with all my services?

Share this post


Link to post

@Heydomdom Thanks for filling in your details :) Pop an email to info@ for license-related questions and we'll be happy to help you out.

 

With regards to your original question, take a look at these few examples depending on the outcome you want:

 

If your queries are always the same (e.g. always the same four stock symbols)

 

Connect one keyword to four "Open URL" objects, with each one pre-filled with one of the stock symbols. You can then type the keyword and press Enter, and all four pages will open.

 

Entering multiple queries separately:

Take a look at the built-in workflow in Alfred, under the + button in the bottom left > Examples > Simple To-Do List.
 
In that workflow, I'm using two variables; The first is typed (the task I want to do) and the second is picked from a List Filter (the list to which I want to add it), each of which is saved in an Arg & Vars utility, then called later in the "Append to file" object to form the name of the list to which I want to add the task.

 

@Andrew's going to share his own example for splitting a query into four as well, as another way to do it.

 

If you then start creating your own workflow and need further help, add it to this thread and fellow users can help you get it completed :)

 

Cheers,
Vero

Edited by Vero
Updated to give a better couple of examples :)

Share this post


Link to post

@Andrew @Vero

 

Thank you guys so much. This is exactly what I wanted. You make it looks so simple but trust me, if you're not a programmer, that little bit of code could take me days to try and work out.

 

Thanks again.

 

Dominic

Edited by Heydomdom

Share this post


Link to post

I have a similar question.

 

I have created an workflow that uses a "list filter" to ask me what sites I want to open. It lists 4 sites and one "all" option. The result is sent to "open URL action". Each item in the "list filter" is an url and the individual ones work. But the all part dosen't. I have just listed all the urls separated by comma in that item.

Share this post


Link to post
2 hours ago, runard said:

But the all part dosen't. I have just listed all the urls separated by comma in that item.

 

It is called "Open URL", not "Open several URLs separated by commas"… As far as Alfred is concerned, whatever you pass to Open URL is a single URL and will be treated as such.


Fundamentally, apart from File Actions, Alfred's workflow elements aren't designed to work with multiple inputs. If you want to open multiple URLs at once, you need to write your own script that splits your single input into its component parts, and passes each one to the open command.

 

Share this post


Link to post

A shorter version would be:

List filter:

  • All (open all of the below)
  • BGA (boardgamearena.com)
  • Boit (boitajeux.com)
  • Core (boardgamecore.com)

Selected option gets sendt to "open URL".

 

That is it. I can program all the singel sites, but the open all part is difficult. 

 

Share this post


Link to post

I found a less elegant solution.

 

Have the List filter -> vars/args -> filter(if var not = all) -> Open URL

                                                        ->filter(if var = all) -> branch to several Open URL commands

 

So it works, but it is not elegant and has to be hard coded.

Share this post


Link to post

@runard Are you looking to type one keyword and have multiple URLs open (either static URLs or adding your search term to it)?

 

If so, look in Alfred's built-in examples for "Should I watch this movie?" This example is set up for you to use one keyword to launch IMDB, Rotten Tomatoes and YouTube with the keyword you want to search for. 

 

Cheers,
Vero

Share this post


Link to post
1 hour ago, runard said:

That is it.

 

I meant an example of the combined URL you need splitting and opening. What you need is a short script to split a single input into individual URLs. We need an example of that input to write a script to split it.

Share this post


Link to post

Hello,

 

Based on Andrew's workflow I modified it to work with Google Trends website and other services. For some reason it does not seem to work as expected with Google Trends.

 

Could some of you elaborate on what's wrong?

 

For now when I type Paris, Rome into the alfred search bar it should open the following tabs

https://trends.google.pl/trends/explore?geo=IT&q=Paris

https://trends.google.pl/trends/explore?geo=IT&q=Rome

 

Instead I got

https://trends.google.pl/trends/explore?geo=IT

https://trends.google.pl/trends/explore?geo=IT

 

Workflow - https://www.dropbox.com/s/rnh3dlfazvpl4k7/Google Stock (1).alfredworkflow?dl=0

 

Additionally is there any way of pasting keywords from a list format instead of comma separated?

 

keyword1

keyword2

keyword 3

 

instead of keyword 1, keyword 2, keyword 3

 

Thanks,

Michael

Share this post


Link to post
Posted (edited)
30 minutes ago, meeffe said:

 

That appears to be Andrew's original workflow, not the one you've edited.

 

You probably need to change this line:

$url = 'http://www.google.com/finance?q=' . urlencode(trim($arg));

to this:

$url = 'http://www.google.pl/trends/explore?geo=IT&q=' . urlencode(trim($arg));

 

30 minutes ago, meeffe said:

Additionally is there any way of pasting keywords from a list format instead of comma separated?

 

Change this line: $args = explode(',', $argv[1]); to this: $args = explode("\n", $argv[1]);

Edited by deanishe

Share this post


Link to post

Right. I see the problem. The URL isn't being properly escaped, so the shell is interpreting the &.

 

Change this line:

shell_exec('open ' . $url);

to:

shell_exec('open ' . escapeshellarg($url));

 

Share this post


Link to post

If any of you would be kind to help me with one small thing

I tried to use this workflow with another tool called ahrefs.com and it works fine with single words but when I use 2,3 or 4 words in one query I get + in between in search field

 

e.g. I used

double decked ship

 

and received

double+decked+ship in a search field

 

Ahrefs uses %20 as a space

https://ahrefs.com/v3-keywords-explorer/google/us/overview?keyword=double%20decker%20ship

 

So how to encode spaces as %20 in the following code?

 

<?php

$args = explode("\n", $argv[1]);

// loop through args
foreach ($args as $arg) {
	
	// create the url
	$url = 'https://ahrefs.com/v3-keywords-explorer/google/it/overview?keyword=' . urlencode(trim($arg));

	// open the url in the default browser
	shell_exec('open ' . escapeshellarg($url));
}

?>

 

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