37

I have a list of URLs in a text file, for example,

http://url1
http://url2
http://url3

I wonder how to open them each in one tab in Firefox (or SeaMonkey), without the hassle of creating a new tab, copying into address bar and hitting return for each URL?

My OS is Ubuntu 10.10. Both command line and GUI solutions are welcome.

slhck
  • 235,242
Tim
  • 17,743

7 Answers7

38

You can save the following to a HTML file:

<!doctype html>
<html>
<head>
<title>Open Windows</title>
<script>
function openWindow(){
    var x = document.getElementById('a').value.split('\n');
    for (var i = 0; i < x.length; i++)
        if (x[i].indexOf('.') > 0)
            if (x[i].indexOf('://') < 0)
                window.open('http://'+x[i]);
            else
                window.open(x[i]);
}
</script>
<style>
html, body
{
    height : 99%;
    width  : 99%;
}

textarea
{
    height : 80%;
    width  : 90%;
}
</style>
</head>
<body>
<textarea id="a"></textarea>
<br>
<input type="button" value="Open Windows" onClick="openWindow()">
<input type="button" value="Clear" onClick="document.getElementById('a').value=''">
</body>
</html>

Now load the file in Firefox, copy the list of URLs in the textarea and click Open Windows.

Dennis
  • 50,701
37

A simple

firefox $(cat file.txt)

should suffice. It will pass each link as an argument to the firefox command, as long as every link is separated by whitespace.

slhck
  • 235,242
jhenninger
  • 1,731
11

On windows you can create a batch file (named say, multiurl.bat):

@echo off    
for /F "eol=c tokens=1" %%i in (%1) do "C:\Program Files (x86)\Mozilla Firefox\firefox.exe" %%i

and then run multiurl.bat urls.txt from the command line and it will load the URLS in new tabs if FireFox is already open, or it will run it and then load the URLS.

8

On Mac OS X, save the following script as openurls.sh, run chmod +x openurls.sh in Terminal, and then type ./openurls.sh from the same directory.

#!/usr/bin/env bash

while read line ; do
    open -a Firefox "$line"
done < "/path/to/file-with-urls.txt"
Daniel Beck
  • 111,893
2

Open your text file in firefox as

file:///C:/URLTextFile.txt
  1. Select the whole link
  2. Right click on it
  3. Click on "Open Link in new tab"
Siva Charan
  • 4,959
1

To expand on an existing Linux answer, personally I strongly prefer opening all pages in the same (existing, open) browser window. Unfortunately Firefox (command-line flags) appears not to accept all the input at once and I had to implement delay (sleep) between actions with xargs (source):

<example-domains.txt xargs -I "%" sh -c '{ firefox --new-tab "%"; sleep 0.25; }'

You may be able to use a significantly shorter delay than 0.25 seconds. You can try out the method with a file containing (about the reserved domains):

https://example.com/
https://example.net/
https://example.org/
https://example.edu/
user198350
  • 4,269
0

Speaking about windows env I used this from cmd:

start http://...
start http://...
start http://...
start http://...
Tobia
  • 2,403