Search code examples
bashzenity

Bash&Zenity to launch multiple sites


I want to launch multiple sites (selected by zenity checkmarks). I have been successful but a little trouble.

#!/bin/bash
browser=$(zenity --list  --text "Which browser?" --radiolist  --column "Pick" --column "Browser" TRUE firefox FALSE opera)
sites=$(zenity --height=280 --width=300 --list  --text "How linux.byexamples can be improved?" --checklist  --column "Pick" --column "Sites" TRUE http://cr4.globalspec.com/ TRUE http://www.cheresources.com/ TRUE http://www.eng-tips.com/ FALSE http://www.engineersedge.com/ FALSE http://hvac-talk.com/vbb/ FALSE http://www.refrigeration-engineer.com/ FALSE http://engineering.stackexchange.com/ FALSE http://chemistry.stackexchange.com/ --separator=" ")
$browser $sites

If my firefox is already running & I check more than one site to open in firefox, the checked websites will open in a new firefox window, instead of existing window & new tabs. This doesn't happen if I check single site. The problem can be circumvented if I use something like

$browser site1
$browser site2 ...

So how can I slice the output (collection of websites separated by space character) produced by zenity & then chain through each of them as indicated?


Solution

  • You can iterate (and thus open one by one) over the $sites in this way:

    #!/bin/bash
    
    browser=$(zenity --list  --text "Which browser?" --radiolist  --column "Pick" --column "Browser" TRUE firefox FALSE opera)
    
    sites=$(zenity --height=280 --width=300 --list  --text "How linux.byexamples can be improved?" --checklist  --column "Pick" --column "Sites" TRUE http://cr4.globalspec.com/ TRUE http://www.cheresources.com/ TRUE http://www.eng-tips.com/ FALSE http://www.engineersedge.com/ FALSE http://hvac-talk.com/vbb/ FALSE http://www.refrigeration-engineer.com/ FALSE http://engineering.stackexchange.com/ FALSE http://chemistry.stackexchange.com/ --separator=" ")
    
    for site in $sites; do
      $browser $site
    done