Discover more from YesXorNo
Automating Common Action with Free Software
Using and embracing customization/extensibility
Updated 2023-06-07: A few textual errors have been corrected, and an annoyance of the rendering of “$HOME” which blows the internal circuitry of Substack’s rendering engine was overcome. Most importantly, images of the terminal session have been added to assist. Lastly, a Postfix was added.
Updated 2023-05-15: Another purpose for the tool is presented.
Reading the News
If one is not using RSS to gather interesting news sources and one wishes to launch the Firefox browser to load a bunch of URLs, in this case targeted at news, how does one do that?
This little article is a "how to", concluding with some additional customization towards using an anonymity preserving browser.
Below, I use the term "directory". This is the original term for the modern synonym "Folder". To my mind, a folder is a physical thing. A directory is digital.
Your knowledge of the GNU/Linux command-line or the Terminal (same for MacOS) is basic. You should know how to open a terminal and how to copy/paste to and from it (though some advice is offered there too).
You'll need bash, the default GNU/Linux shell which is normally used in the "Terminal". You'll get this by default on recent Apple (MacOS) operating systems. For windows a good solution is to install Git, not for its version control system, but because it comes with a limited bash which is good enough for most purposes, including this one. If you don't have "bash" available, or know how to launch a terminal, stop reading now.
The Firefox browser, and thus the anonymity preserving Tor equivalent, support a feature to load multiple URLs on start. This is the feature we will use. Actually, any Internet browser which you can launch from the command-line will almost certainly support this feature.Tthe URLs take the place of “files”, a common argument list to many command-line utilities.
To make our tool easy to use and easily maintained we are going to edit one file ($HOME/.bashrc) and create two others ($HOME/bin/news.sh and $HOME/.Firefox.start.urls.rc). You may need to create the $HOME/bin directory along the way, but that is also covered below.
About your $HOME directory
$HOME just means your home directory.
If you're using a GNU/Linux operating system (or MacOS) learning about one's home directory and how files within it customize various pieces of software, and how its structure can be adjusted to customize how one interacts with the operating system can pay large dividends on time invested. Take this as a hint from an old UNIX/Linux "hacker".
The $HOME/bin directory
You'll see 'bin' directories in Linux/MacOS systems, commonly /usr/bin and perhaps /usr/local/bin. 'bin' stands for binary and is the traditional location to place executables (compiled programs). These days we often use programs which are not compiled, instead using interpreters like Python, or Bash. One tends to place these non-compiled and thus not binary files in a 'bin' directory anyway to keep programs together.
One can create one's own 'bin' directory under one's home directory and put within it any programs which are not a part of the operating system or the software channels which one uses to add software to one's system. If you don't have a $HOME/bin it is easy to make one and there is no risk in doing so.
Open a terminal. By default, you will be in your home directory. When using the command-line (i.e bash) it is important to know where one is as commands that operate on files can take paths to files which are 'relative'. These relative paths depend on where you are on the filesystem(s).
The following shows an example session using username 'foo' in a just opened terminal. '$' just means the command-prompt and will likely differ on your terminal. Don't let that dissuade you. We're talking about what comes after the '$ '. '#' is the comment character and means that it and anything after it on the current line are ignored. I use it (#) to explain what is happening:
$ pwd # where am ?
$ ls -d bin # does the bin directory exist? The '-d' flag just instructs 'ls' to not list the contents of 'bin' but rather information about it.
ls: cannot access 'bin': No such file or directory
$ # okay, bin does not exist, lets create it
$ mkdir bin
$ ls -d bin
$ exit # to exit bash, and thus close the terminal.
Now we'll create our little tool for launching Firefox with a collection of 'load on startup' URLs. We'll find out where 'firefox' is then create the file in our bin/ directory and then make it executable from the command-line. I like the 'vi' text editor, but we'll use nano below for that is easier for many. Use whichever text editor is familiar for you.
$ which firefox
# if this is different for you, then you'll need to change this in the text below. We revisit this again when we consider using the Tor Browser instead. For now, if it is different, *copy* it.
# A note on copy/paste to/from the terminal. In windows land you are trained to use Ctrl-C and Ctrl-V. Ctrl-C has a very different meaning in UNIX/Linux land (send the INTERUPT signal to the foreground process). The equivalent cut/paste keyboard commands in Linux additionally use the Shift key, the three finger Ctrl-Shift-C or Ctrl-Shift-V. It takes a little getting used to, but works reliably. One can, of course, use a mouse and right button for Copy or Paste from the menu.
$ nano bin/news.sh
# The terminal changes as nano takes over from bash. It shows an empty file into which we will cut/paste the following. Then we'll save and exit. It is important that the first line below is the FIRST line in the file.
BROWSER=/usr/bin/firefox # There is a big “gotcha” here for people who do a little programming. There can be NO SPACES anywhere between the ‘B’ and the ‘x’. VAR=value. No spaces.
# Start with a set of URLs to open
$BROWSER $(cat ~/.firefox.start.urls.rc)
Now you need to save and exit:
Press the Ctrl and X buttons together (Ctrl-X).
You will be asked if you wish to save. Press Y.
Then nano asks you to confirm the name of the file to write, just press Return.
So far, so good. Now we need to create that funny file called '.firefox.start.urls.rc'. We'll use nano again (or you use whichever text editor is easy for you). We cannot use comments in this file, so copy the command-line then paste all of the URLs and then follow the above process (Ctrl-X, Y, Return) to save and exit.
$ nano .firefox.start.urls.rc # and paste in the following
You have saved and exited, yes? Obviously, you can edit this file whenever you want to change the urls that are loaded or the order or whatever you want. This is why we have put this information in a separate file. But, first, lets get the program working.
We need to make the file bin/news.sh into a program (make it executable). Again, in the terminal paste:
$ chmod a+x bin/news.sh
Now it can be run.
Firefox should launch and begin loading each of the URLs specified in the .firefox.start.urls.rc file. If it doesn't either I screwed up or you did. Mistakes happen, don't beat yourself up about it. Go to the 'Cleaning up on error' section below.
If firefox did start and load those URLs you have not only a new tool, but a little framework which can be adjusted. This is the educational component of this little article. Learning how to create tools and adjust them to purpose. We'll get to that in a minute.
Now we need to make this little tool/framework easy to use. For that we need to adjust the configuration file for bash (the shell in the Terminal) itself. We will do two things:
We will include our new (or existing, if you already had one) $HOME/bin directory in the places where bash will look for programs and
we'll create a short-hand, an alias, for our news.sh program.
You could edit the $HOME/.bashrc file, but I suggest just copy-pasting onto the command-line the following. Don't play with this, just copy/paste, ONE LINE at a time. Every symbol (except the leading '$'s, don't copy them) matters.
$ echo 'PATH=$PATH:$HOME/bin' >> $HOME/.bashrc
$ echo 'alias news=news.sh' >> $HOME/.bashrc
You can now either start a new Terminal or ask bash in the terminal you're in to re-load its configuration. For the later type (or paste):
$ source .bashrc
Close the open Firefox which you launched a moment ago. Then, test the 'easy to use' version of our tool in the terminal:
This should launch firefox in exactly the same way.
If it does, pat yourself on the back and grab a celebratory cup of tea, piece of fruit, chocolate or whatever you do.
To adjust this little tool/framework the key file is .firefox.start.urls.rc which I recommend changing. First make a copy (backup). Then edit it using whichever text editor you like. As a first step, why not just re-order some of the lines? Then close the open firefox and relaunch from the command-line as above.
Within this file, blank lines do not matter. A URL should never have a space in it on the Internet, which is true for this file too. No spaces in the middle of a URL!
$ cd # back to home dir
$ cp .firefox.start.urls.rc .firefox.start.urls.rc.backup # make the backup
$ nano .firefox.start.urls.rc # edit the file
# re-order lines, save and exit
# close the open firefox and test
If you get lost or screw up the 'rc' file, just restore the original (that's why it was created):
$ cp .firefox.start.urls.rc.backup .firefox.start.urls.rc
Playing part II is to totally change the URLs to that which suits you. Make a backup again (good practice) and go nuts! Copy paste URLs from whichever browser you use to the file. Again, watch out for spaces. They should not ever be present within a line. That is, each line will begin ‘http’ (usually https) ‘://’ and then comes the domain (e.g moonofalabama.org) and then the file part (e.g /some/list-of/letters/perhaps_ending_in.html) for https://moonofalabama.org/some/list-of/letters/perhaps_ending_in.html
Enter the edit, test loop :)
Now, if you are like me and treat the record of what you read on the internet with the seriousness that librarians treat your borrowing record from their library then you may wish to use Tor to access your news. To achieve this, the use of Tor can be quickly substituted into the above little tool/framework.
When one installs the Tor Browser Bundle on a GNU/Linux system (and I presume this is also true of MacOS) by default it unpacks into the home directory. There will likely be a directory titled "tor-browser_en-US" (for English US people). Below that is "Browser" in which resides "start-tor-browser" which is the Tor launch script for its modified Firefox. So, if you would like to use Tor, first confirm the location of this script, and then edit the $HOME/bin/news.sh file to use it.
$ ls -d tor-browser_en-US # does $HOME/tor-browser_en-US exist?
$ ls -d tor-browser_en-US/Browser # and Browser below that ?
$ ls tor-browser_en-US/Browser/start-tor-browser # and within that the start script ?
Your file may turn up being coloured green or have an asterix after it. This just shows that it is executable. Once you've found this script, copy its location and you are ready to insert it into the news.sh script. Edit the line which said:
to now say wherever that script was under your home directory:
Now you have a customizable tool for launching Tor (or Firefox) with your choices of news (or anything) URLs. One can, of course, convert this into something launched graphically, but then we get into all sorts of differences in graphical environments which I shall avoid and leave you to conquer should you wish.
For people using GNOME type graphical interfaces, create a new launcher. The command to use is:
/bin/bash -c "$HOME/bin/news.sh"
Cleaning up on error
If things went wrong, it is easy to clean up.
We created two new files which can be removed. We'll use the interactive version of delete (rm, the remove command):
$ cd # to be sure we're in the home directory
$ rm -i ./bin/news.sh
rm: remove regular file './bin/news.sh'? y
$ rm -i ./.firefox.start.urls.rc
rm: remove regular file './.firefox.start.urls.rc'? y
$ # done
Those 'in the know' will recognize that the leading ./'s in the above commands are redundant (not needed). This is a habit I have developed whenever using the 'rm' (delete) command. The '.' creates an anchored path. It forces one to think where one is on the file system(s). I believe this to be entirely appropriate whenever one is deleting things. Lets just call this learned wisdom after 35+ years of accidentally deleting things. The trade off is that the './' is faster than recovering from backup.
If you're interested in more "unix-y" type articles like this, use the heart button or add a comment.
Sorry about the “unclean” publication. I need to be more careful with the “publish this later” button. Perhaps this article provided different lessons to different members of “the class”.
If you did try the above and struggled, perhaps try again with the added images. I hope they help you succeed.
I use this tool “news” every day. I stopped using RSS for a while, and this was the replacement I built. I’ll probably head back to RSS again, but it was a fun little diversion. What I like about the tool is that because I built it I have no qualms about modifying it or accidentally destroying it. I enjoy that sort of empowerment.
If this little exercise has given you any of that sense, then I wish you all the best in your future journey of getting software to do what you want by making or modifying it yourself. There is a wonderful community waiting for you if you wish to wander down the GNU/Linux road. The key term is Linux User Group or LUG. There will be one near you. Find them and say hello. They all went through the learning curve and will help people who embark on the same journey.
I’m in Sydney at the moment and just did a search for ‘sydney linux user group’ and what should show up but:
Here can be seen why I love old UNIX hackers reborn with GNU/Linux.
Sydney LUG —> SLUG: okay, lets run with that and just stick the Opera House on the back of a gastropod!
Its so good that I’ll just have to go and say hello.
The Tor Series, YesXorNo, 2022-04-09
Epic Linux Community Song Featuring Linus Torvalds, various GNU/Linux users, The Linux Foundation, uploaded 2012-09-01
Subscription is optional. Subscribers can expect notifications for most articles. Better is to use RSS (feed), or bookmark the Archive page and visit at leisure. If you use Twitter, following @YesXorNo1 is also a partially effective notifications strategy. A reliable notification mechanism is the use of Substack’s Notes facility.
Copyright and Licensing
None. Go nuts.
Comments: on topic, no abuse.