I've been using Ubuntu for a few weeks, and I want to know more about automating tasks.
How can I write a bash script to open a web browser with a specific URL after startup?
I've been using Ubuntu for a few weeks, and I want to know more about automating tasks.
How can I write a bash script to open a web browser with a specific URL after startup?
For this case I am going to imagine a scenery. First of all let's say I need a script to open a web browser in certain Youtube Video(s) and each time it opens on boot I need the videos to be played with a random different duration.
First of all let's create the file, I am calling this "youtuviewer.sh", inside of which I am going to set this portions of code:
I explain it quickly:
chromium-browser
will run (it can be replaced by firefox or any other web browser). The browser will open the youtube links in the list in separated tabs, the list should be separated by a space. The ampersand (&) will instruct that after executing that line, the rest of the script should be executed and the chromium-browser instance should be left running meanwhile.A more complex example can be made with this 7 lines, indeed. You can make it in just one line, everything depends on what you wish to achieve.
We are going to set execution permissions to the file via your favorite file browser (nautilus comes to my mind) or via terminal. See this: How do I run .sh files?
Now we need to setup the file to be run on boot, we can achieve this via cron (see this: How do I set up a Cron job?) or by using the "Startup applications" dialog (see this: How to add application to startup application menu?).
This is the simplest way I find to do what the edits by @ImaginaryRobots let's see.
If you need further assistance don't hesitate to let us know.
Good luck!
To open an URL you should use xdg-open, which will use your preferred browser to visit the URL.
In order to Open It after startup, you should do what Geppettvs D'Constanzo suggests: