Configuring the Linux clock

A problem often reported by users in Linux forums is that the time displayed by the system clock is incorrect. Typically the problem is that it displays UTC instead of local time. The most common cause is incorrect configuration, although dual booting with Windows will also change the Linux system clock’s time unless either a) Linux is configured to use local time for the hardware clock, or b) Windows is configured to use UTC* and Windows’ time synchronisation with an Internet time server is disabled.

* A change to the Windows Registry is required in order to enable Windows to use UTC for hardware clock time, but even then you may still face problems (see e.g. Force Windows 8 to use UTC when dealing with BIOS clock).

Some terms you need to know: ‘hardware clock’, ‘RTC’ (real-time clock), ‘CMOS clock’ and ‘BIOS clock’ are terms commonly used for the same thing. The hardware clock is non-volatile. ‘system clock’ is the software clock the operating system uses. It is volatile (it is in the kernel). The system clock is normally set from the hardware clock when the operating system boots, taking into account various configuration options. I recommend that you read the manual for the hwclock command, as it explains in detail about clocks in Linux:

# man hwclock

To configure your time zone and clocks correctly, follow the steps below.

If your installation uses the OpenRC init system

  1. Set the time zone:

    1. Specify your time zone in the file /etc/timezone. If you are in Spain, for example, the contents of that file should be ‘Europe/Madrid‘ (without the quotes).

      # nano /etc/timezone
      

      You can find out which time zones are available by looking in the directory /usr/share/zoneinfo/ and its sub-directories.

    2. Provide the information for your time zone. If you are in Spain, for example, you would enter the following command:

      # cp /usr/share/zoneinfo/Europe/Madrid /etc/localtime
      

      Note: Some people recommend making /etc/localtime a symlink rather than creating it by copying a file from /usr/share/zoneinfo/, however I recommend copying. You should definitely not use a symlink if /usr is on a different partition (see Ref. 1).

  2. Set the system clock’s time to your local time now (I’ll assume it is 23:54:30 on 21 September 2014 when you press Enter):

    # date 092123542014.30
    
  3. Specify whether the hardware clock time is UTC:

    # hwclock --utc
    

    or local time:

    # hwclock --localtime
    

    It is preferable for the hardware clock time to be in UTC. However, if you dual boot with Windows it is recommended for the hardware clock time to be in local time rather than UTC unless both the following are true: a) the Windows Registry has been configured for hardware clock time in UTC; b) Windows’ time synchronisation with an Internet time server is disabled.

  4. Set the hardware clock’s time by specifying your local time (I’ll assume it is 23:54:50 on 21 September 2014 when you press Enter):

    # rm /etc/adjtime
    # hwclock --set --date="2014-09-21 23:54:50"
    

    Note: You must specify local time in the above command, even if you intend the hardware clock time to be UTC.

    Note that the third line in /etc/adjtime should be ‘UTC’ if the hardware clock time is in UTC, or ‘LOCAL’ if the hardware clock time is in local time. For example:

    # cat /etc/adjtime
    0.000000 1412038530 0.000000
    1412038530
    UTC
    
  5. Tell OpenRC whether the hardware clock uses UTC or local time, and to update the hardware clock time from the system clock time at every shutdown (taking into account any time zone difference between the two clocks):

    # nano /etc/conf.d/hwclock
    
    1. Make clock="UTC" (or clock="local" if you dual boot with Windows and the Windows Registry is not configured to use UTC for hardware clock time).
    2. Make clock_systohc="YES" to adjust the hardware clock time at shutdown based on the software clock time (taking time zone into account). However, you don’t need to bother doing this if your kernel configuration has CONFIG_RTC_SYSTOHC=y and your installation is configured to synchronise the system clock with a NTP time server (see my post Synchronise your Gentoo Linux clock with an Internet time server), i.e. make clock_systohc="NO" if CONFIG_RTC_SYSTOHC=y. You can check if clock_systohc="YES" is causing the hardware clock time to be updated from the software clock time (taking time zone into account) at shutdown by looking at the kernel messages displayed when in verbose mode during shutdown to see if the following message is displayed:

      Setting hardware clock using the system clock [UTC] ...
      
    3. Make clock_hctosys="YES" to adjust the system clock time at start up based on the hardware clock time (taking time zone into account). However, you don’t need to bother doing this if your kernel configuration has CONFIG_RTC_HCTOSYS=y, i.e. make clock_hctosys="NO" if CONFIG_RTC_HCTOSYS=y. You can check if clock_hctosys="YES" is causing the system clock to be updated from the hardware clock at boot by looking at the kernel messages displayed when in verbose mode during boot to see if the following message is displayed:

      Setting system clock using the hardware clock [UTC] ...
      
  6. Reboot and check everything is working as expected:

    # date
    Tue 30 Sep 01:55:55 BST 2014
    # hwclock
    Tue 30 Sep 2014 01:55:59 BST  -0.031877 seconds
    

    The hwclock command always shows local time, even if you keep your hardware clock in UTC.

  7. Optionally (but I recommend it), configure your installation to synchronise the system clock with an Internet NTP server (see my post Synchronise your Gentoo Linux clock with an Internet time server).

If your installation uses systemd

  1. Set the time zone:

    1. Find out the available time zones:

      # timedatectl list-timezones
      
    2. Specify your time zone (I’ll assume you are in Spain in this example):

      # timedatectl set-timezone Europe/Madrid
      
  2. Set the system clock time to your local time (I’ll assume it is 23:54:30 on 21 September 2014 when you press Enter):

    # timedatectl set-time "2014-09-21 23:54:30"
    
  3. Inform systemd that the hardware clock uses UTC, and set the current UTC in the hardware clock now:

    # timedatectl set-local-rtc 0
    

    Note that, by default, systemd assumes the hardware clock uses UTC. Although systemd can be configured to assume the hardware clock uses local time, for technical reasons it is not recommended (see man timedatectl and Arch Wiki article Time for an explanation of why this is not advisable).

    Note that the third line in /etc/adjtime should be ‘UTC’ if the hardware clock time is in UTC, or ‘LOCAL’ if the hardware clock time is in local time. For example:

    # cat /etc/adjtime
    0.000000 1412038530 0.000000
    1412038530
    UTC
    
  4. Reboot and check everything is working as expected:

    $ timedatectl
    
  5. Optionally (but I recommend it), configure your installation to synchronise the system clock with an Internet NTP server (see my post Synchronising the clock using NTP in Sabayon Linux).

References

[1] Gentoo Forums – how exactly to set timezone in /etc/localtime ?[solved]

Synchronising the clock using NTP in Sabayon Linux

In my previous post I explained how to install Sabayon Linux via the command line from the Sabayon Linux ‘SpinBase’ ISO.

If the system clock in your current installation is not being synchronised with an external time server over the Internet, the simplest way to achieve this is to install the net-misc/ntp package and configure systemd as shown below.

Note that I use net-misc/ntp rather than net-misc/chrony because the latter does not work in my Sabayon Linux installation; after I have configured the Chrony daemon, the command ‘systemctl status chronyd‘ returns the error message ‘Can’t initialise from real time clock, driver not loaded’. Of course, if Chrony happens to be installed and is working fine, you don’t need to do anything at all. But if Chrony is not working correctly and you want to try the ntp daemon instead, before performing the steps below you’ll first need to disable Chrony as explained under ‘Caveat’ at the end of this post.

  1. Install the ntp package:

    # equo install ntp

  2. Enable the ntp daemon so that it starts at boot:

    # systemctl enable ntpd
    # timedatectl set-ntp true

  3. Start the ntp daemon running now:

    # systemctl start ntpd

  4. Check whether the daemon is running:

    # systemctl status ntpd

Below I show the console output for the complete sequence from Step 2 to Step 4 with the command ‘timedatectl status‘ between each step so that you can see the effect. Note that I had previously set the hardware clock time (which, by default, systemd assumes to be UTC) to be the same time as local time. Since BST and UTC do not coincide, clearly both clocks should not both contain 10:06, so watch what happens below once the NTP daemon is launched.

sabayon fitzcarraldo # timedatectl status
      Local time: Mon 2014-09-22 10:06:06 BST
  Universal time: Mon 2014-09-22 09:06:06 UTC
        RTC time: Mon 2014-09-22 10:06:07
        Timezone: Europe/London (BST, +0100)
     NTP enabled: no
NTP synchronized: no
 RTC in local TZ: no
      DST active: yes
 Last DST change: DST began at
                  Sun 2014-03-30 00:59:59 GMT
                  Sun 2014-03-30 02:00:00 BST
 Next DST change: DST ends (the clock jumps one hour backwards) at
                  Sun 2014-10-26 01:59:59 BST
                  Sun 2014-10-26 01:00:00 GMT
sabayon fitzcarraldo # systemctl enable ntpd
ln -s '/usr/lib/systemd/system/ntpd.service' '/etc/systemd/system/multi-user.target.wants/ntpd.service'
sabayon fitzcarraldo # timedatectl status
      Local time: Mon 2014-09-22 10:06:39 BST
  Universal time: Mon 2014-09-22 09:06:39 UTC
        RTC time: Mon 2014-09-22 10:06:39
        Timezone: Europe/London (BST, +0100)
     NTP enabled: no
NTP synchronized: no
 RTC in local TZ: no
      DST active: yes
 Last DST change: DST began at
                  Sun 2014-03-30 00:59:59 GMT
                  Sun 2014-03-30 02:00:00 BST
 Next DST change: DST ends (the clock jumps one hour backwards) at
                  Sun 2014-10-26 01:59:59 BST
                  Sun 2014-10-26 01:00:00 GMT
sabayon fitzcarraldo # timedatectl set-ntp true
sabayon fitzcarraldo # timedatectl status
      Local time: Mon 2014-09-22 10:06:57 BST
  Universal time: Mon 2014-09-22 09:06:57 UTC
        RTC time: Mon 2014-09-22 10:06:58
        Timezone: Europe/London (BST, +0100)
     NTP enabled: yes
NTP synchronized: no
 RTC in local TZ: no
      DST active: yes
 Last DST change: DST began at
                  Sun 2014-03-30 00:59:59 GMT
                  Sun 2014-03-30 02:00:00 BST
 Next DST change: DST ends (the clock jumps one hour backwards) at
                  Sun 2014-10-26 01:59:59 BST
                  Sun 2014-10-26 01:00:00 GMT
sabayon fitzcarraldo # systemctl start ntpd
sabayon fitzcarraldo # timedatectl status
      Local time: Mon 2014-09-22 10:07:13 BST
  Universal time: Mon 2014-09-22 09:07:13 UTC
        RTC time: Mon 2014-09-22 09:07:13
        Timezone: Europe/London (BST, +0100)
     NTP enabled: yes
NTP synchronized: yes
 RTC in local TZ: no
      DST active: yes
 Last DST change: DST began at
                  Sun 2014-03-30 00:59:59 GMT
                  Sun 2014-03-30 02:00:00 BST
 Next DST change: DST ends (the clock jumps one hour backwards) at
                  Sun 2014-10-26 01:59:59 BST
                  Sun 2014-10-26 01:00:00 GMT
sabayon fitzcarraldo # systemctl status ntpd
ntpd.service - Network Time Service
   Loaded: loaded (/usr/lib/systemd/system/ntpd.service; enabled)
   Active: active (running) since Mon 2014-09-22 10:07:11 BST; 23s ago
 Main PID: 2420 (ntpd)
   CGroup: /system.slice/ntpd.service
           └─2420 /usr/sbin/ntpd -g -n

Sep 22 10:07:11 sabayon ntpd[2420]: Listen normally on 5 eth0 fe80::a00:27ff:fe86:21f3 UDP 123
Sep 22 10:07:11 sabayon ntpd[2420]: peers refreshed
Sep 22 10:07:11 sabayon ntpd[2420]: Listening on routing socket on fd #22 for interface updates
Sep 22 10:07:13 sabayon ntpd[2420]: Deferring DNS for 0.gentoo.pool.ntp.org 1
Sep 22 10:07:14 sabayon ntpd[2420]: Deferring DNS for 1.gentoo.pool.ntp.org 1
Sep 22 10:07:15 sabayon ntpd[2420]: Deferring DNS for 2.gentoo.pool.ntp.org 1
Sep 22 10:07:16 sabayon ntpd[2420]: Deferring DNS for 3.gentoo.pool.ntp.org 1
Sep 22 10:07:18 sabayon ntpd_intres[2422]: DNS 0.gentoo.pool.ntp.org -> 85.236.36.4
Sep 22 10:07:18 sabayon ntpd_intres[2422]: DNS 1.gentoo.pool.ntp.org -> 78.46.197.35
Sep 22 10:07:18 sabayon ntpd_intres[2422]: DNS 2.gentoo.pool.ntp.org -> 91.234.160.19
sabayon fitzcarraldo #

Notice that the NTP daemon synchronised the RTC (hardware clock) time to UTC (I had previously set the hardware clock time to be the same as local time to show what would happen when the NTP deamon was launched). That is correct: notice ‘RTC in local TZ: no‘ in the output above, meaning that systemd by default assumes the time in the RTC is UTC.

By the way, in case you’re wondering, the NTP daemon of course synchronises the time in the system clock too. You do not need to worry: the system clock uses the local time of the time zone you previously configured (see my previous post), so the Linux date command and the clock of the Desktop Environment will show you local time by default.

Caveat
Note that I am using the ntp daemon instead of the Chrony daemon or the OpenNTPD daemon. If Chrony happens to be installed and active in your Sabayon Linux installation, before performing any of the above steps you’ll first need to do the following:

  1. Uninstall the Chrony package:

    # equo remove chrony

  2. Disable the Chrony daemon so that it does not start at boot:

    # systemctl disable chronyd
    # timedatectl set-ntp false

  3. Stop the Chrony daemon running now:

    # systemctl stop chronyd

  4. Check whether the daemon is still running:

    # systemctl status chronyd

Change systemd’s binary logging to text logging in Sabayon Linux

systemd logs system messages in a binary file which the developers call a ‘journal’. However, if you would prefer system messages to be logged in a text file, here is how to do it for Sabayon Linux. The steps will probably be similar in other distributions.

1. See what log files currently exist in your installation:

# ls /var/log
anaconda btmp cups faillog kdm.log mysql portage sandbox tallylog Xorg.0.log
boot.log chrony entropy journal lastlog news samba spice-vdagentd wtmp Xorg.0.log.old

Notice that the traditional text log file /var/log/messages is not present. The systemd binary log files are in a sub-directory of /var/log/journal/:

# ls /var/log/journal
5d387e19d28644c5b24f06f8bc6e9b9c
# ls /var/log/journal/5d387e19d28644c5b24f06f8bc6e9b9c
system.journal user-1000.journal

2. Edit the file /etc/systemd/journald.conf and change #Storage=auto to Storage=none

# nano /etc/systemd/journald.conf

3. Install the system logger syslog-ng:

# equo install syslog-ng

If it’s not already installed, install the logrotate package:

# equo install logrotate

4. Enable the service so that it starts the next time you boot:

# systemctl enable syslog-ng.service
ln -s '/usr/lib/systemd/system/syslog-ng.service' '/etc/systemd/system/syslog.service'
ln -s '/usr/lib/systemd/system/syslog-ng.service' '/etc/systemd/system/multi-user.target.wants/syslog-ng.service'

5. Start the service now:

# systemctl start syslog-ng.service

6. Check if the text log file /var/log/messages has been created:

# ls /var/log
anaconda btmp cups faillog kdm.log messages news samba spice-vdagentd wtmp Xorg.0.log.old
boot.log chrony entropy journal lastlog mysql portage sandbox tallylog Xorg.0.log

If you now reboot you’ll see that the text file /var/log/messages is being used to log system messages, and you can view it easily using commands such as cat, more, less, nano or whatever, and search through it using grep etc. Note that the systemd journal service is still running; it is just not logging to a binary file any more and is forwarding system messages to syslog-ng.

How to install Sabayon Linux via the command line using the ‘text installer’

If you have trouble installing Sabayon Linux from one of the ISOs that include KDE, GNOME or Xfce, you could try installing from the ‘SpinBase’ ISO or ‘Minimal’ ISO instead and add a desktop environment later.

And sometimes the Sabayon Linux installer is unable to install the distribution correctly for the GPU or IGP in your machine, so installing the distribution to use the X.Org VESA video driver then later trying another video driver can also be a way to get you to a working installation.

Whichever ‘spin’ of Sabayon Linux I try to install, I find my success varies considerably with the release of ISO. So, if you end up with a blank screen when you reboot after installing the distribution, try installing it again with a different ISO, such as a Monthly release instead of a Daily release. If none of the current ISOs result in a working installation, you may have to wait a few days for a new Daily release to be uploaded. Despite the name, the Daily ISOs are not necessarily released daily.

I recommend you practice installation in VirtualBox before trying with an actual HDD. You can do this on a PC running VirtualBox under Windows, Mac OS or Linux. N.B. If the console goes black at any time in VirtualBox, press Enter to refresh the contents.

The steps below worked for me with a Sabayon Linux ISO dated 14 September 2014 in VirtualBox running under Windows 8.1 on a machine with Intel HD Graphics IGP. In the steps below I configure the installation for the time zone in which São Paulo is situated and specify British English and Brazilian Portuguese as the languages to be used. Obviously you should choose instead the time zone and language that you want in your installation.

1. Download the Daily SpinBase ISO (Sabayon_Linux_DAILY_x86_SpinBase.iso) from one of the ISO repositories (see the Download link on the distribution’s Web site).

2. Create a LiveDVD from the ISO (see my post Help for Windows users: How to create a Linux LiveCD, LiveDVD or LivePenDrive from an ISO file if you don’t know how to do that).

3. Boot the LiveDVD.

4. You have two choices here, really. Try (a) first and, if the LiveDVD will not continue to load the OS or it will but you end up with an installation that does not work, then re-boot the LiveDVD and perform (b) instead.

Either:

a) Press ‘Enter‘ at the Sabayon Linux boot menu, to start the OS from the LiveDVD.

or:

b) Press F5 at the Sabayon Linux boot menu, then Esc to close the pop-up list of boot parameters. Then delete the “---” at the end of the list of kernel boot parameters, delete the “vga=791“, add “xdriver=vesa” to the end of the list and press ‘Enter‘ to start the OS from the LiveDVD. Note that, unlike the other Sabayon Linux ISO releases, the SpinBase ISO does not include video drivers for X Windows. However, by booting the LiveDVD with xdriver=vesa the installation on the HDD will include that parameter in /etc/default/sabayon-grub and /boot/grub/grub.cfg.

In either case, Sabayon Linux on the LiveDVD should start in text mode and you should see a root user prompt:

sabayon ~ #

5. Enter the following command and follow the prompts to enter the relevant information to install Sabayon to your HDD:

# installer

Select 2) 'Use text mode' then work your way through steps 1 to 5, answering the installer’s prompts:

1) Timezone settings
2) Set root password
3) Create user
4) Network settings
5) Install Destination

When you select Step 5 (Install Destination) you will be presented with three ‘Autopartitioning Options’ (Replace Existing Linux System(s); Use All Space; Use Free Space). When you make your choice from those three options, you will then be presented with the options for partitioning:

Partition Scheme Options

[ ] 1) Standard Partition

[x] 2) LVM

[ ] 3) BTRFS

Select a partition scheme configuration.

Please make your choice from above ['q' to quit | 'c' to continue | 'r' to refresh]:

You may find that the installer crashes if you have selected either the default LVM partition scheme or the BTRFS partition scheme. If it does crash, run the installer again but select Option 1 instead (Standard Partition), which will create standard ext4 partitions. Actually, I prefer this option.

Quite a few Python-related error messages may be displayed towards the end of the installation process. I just ignore them.

6. Once the installer has completed installation, press Enter to quit, and you will see a root user prompt again.

7. Enter the following command to reboot (If you installed using VirtualBox, make sure you remove the ISO from the virtual CD/DVD drive, or you will just reboot from the ISO instead of the virtual HDD):

systemctl reboot

If you still have the LiveDVD in the drive, select ‘Boot from first hard drive’ in the LiveDVD’s boot menu.

8. You will see a log-in prompt:

sabayon login:

Log-in as user ‘root’ with the root user’s password you specified during installation.

9. List the available time zones:

# timedatectl list-timezones

(Press the Space Bar to page through the list, and the Q key to exit the list.)

10. Specify the timezone you want:

# timedatectl set-timezone America/Sao_Paulo

11. List the current locale:

# localectl list-locales
en_US
en_US.iso88591
en_US.utf8

12. If you want to change the current locale or add a locale, edit the locale.gen file:

# nano /etc/locale.gen

I wanted to have just British English and Brazilian Portuguese, so I made the file contain only the following:

en_GB.UTF-8 UTF-8
en_GB ISO-8859-1
pt_BR.UTF-8 UTF-8
pt_BR ISO-8859-1

If I only wanted one language (I’ll use Brazilian Portuguese as an example), I would have made it contain the following instead:

pt_BR.UTF-8 UTF-8
pt_BR ISO-8859-1

13. Generate the locale(s) you want:

# locale-gen
* Generating 4 locales (this might take a while) with 1 jobs
* (1/4) Generating en_GB.UTF-8 ... [ ok ]
* (2/4) Generating en_GB.ISO-8859-1 ... [ ok ]
* (3/4) Generating pt_BR.UTF-8 ... [ ok ]
* (4/4) Generating pt_BR.ISO-8859-1 ... [ ok ]
* Generation complete

14. List the locales you have configured, just to be sure:

# localectl list-locales
en_GB
en_GB.iso88591
en_GB.utf8
pt_BR
pt_BR.iso88591
pt_BR.utf8

15. Set the language you want to use:

# localectl set-locale LANG=pt_BR.UTF-8

16. List the console keymaps available:

# localectl list-keymaps

17. Chose the console keymap you wish to use:

# localectl set-keymap br-abnt2

N.B. The above systemd command does not change the console keymap specified in /boot/grub/grub.cfg, which remains as “vconsole.keymap=us“. You will have to fix that later by editing /etc/default/sabayon-grub and running grub2-mkconfig -o /boot/grub/grub.cfg, as I show further on.

18. List the X11 keymaps available:

# localectl list-x11-keymap-layouts

19. Chose the X11 keymap you wish to use:

# localectl set-x11-keymap br

20. Update the environment variables and profile to adopt what you specified:

# env-update && source /etc/profile

21. Reboot (Remove the LiveDVD if still have not already done so):

# systemctl reboot

22. Log-in as the root user.

23. Fix the console keymap specified in grub.cfg:

# nano /etc/default/sabayon-grub

and replace “vconsole.keymap=us” with “vconsole.keymap=br-abnt2“.

# grub2-mkconfig -o /boot/grub/grub.cfg

24. Make sure the Entropy package database in your installation is up to date:

# equo update

25. Roll (upgrade) all installed packages to their latest version:

# equo upgrade

If you are prompted regarding any package licences, just accept them.

26. Update any superseded configuration files:

# equo conf update

27. Check if there are any missing/incorrect dependencies:

# equo deptest

28. Check if there are any missing/incorrect libraries:

# equo libtest

29. Install the X.Org VESA video driver:

# equo install xf86-video-vesa

This is needed because the VESA video driver does not get installed even if you specify “xdriver=vesa” initially in the kernel boot parameter list when booting a LiveDVD using SpinBase.

30. Install the desktop environment of your choice (I’ll choose KDE):

# equo install kde-meta

31. If you are installing KDE, also install the KDE language pack(s) for the locale(s) configured earlier:

# equo install kde-l10n-en_GB kde-l10n-pt_BR

32. Install the Sabayon Linux theme for KDE and KDM (I find this package is not installed automatically, and stops KDM from working if it is not present):

# equo install sabayon-artwork-kde

33. Reboot:

# systemctl reboot

34. Log-in as the root user and, if you installed KDE, enable KDM as the display manager (log-in screen):

# systemctl enable kdm

35. Then reboot:

# systemctl reboot

The installation on your HDD should now boot to the KDM log-in screen. You should be able to enter your user name and password, and the installation should launch the Desktop Environment and display the Desktop. From here you will be able to open a Konsole/Terminal window and install other packages. If you want to change the video driver from the X.Org VESA driver to a driver for an AMD, Intel or NVIDIA GPU/IGP, you will need to install the relevant driver package and edit /etc/X11/xorg.conf and /etc/default/sabayon-grub accordingly (and regenerate grub.cfg). Post in the Sabayon Linux Forums to ask for help if you need it. Good luck!

Make Firefox for Linux use Dolphin to ‘Open Containing Folder’

When I click on the Download Manager icon on the tool bar, Firefox for Linux 32.0 opens a small pane listing downloads in progress, if any, and a link ‘Show All Downloads’. If I click on the link, Firefox pops up a window listing all the files downloaded via the browser, each with a folder icon beside it. Hovering the mouse pointer over the folder icon displays a tooltip ‘Open Containing Folder’. For as long as I can remember with Firefox for Linux, clicking that folder icon resulted in the Audacious music player launching and playing an MP4 file that happens to be in my ~/Downloads/ directory!

Firstly, I have no idea why Firefox was launching a media player instead of opening the directory. Secondly, I have no idea why Firefox wanted to open that specific file rather than any of the other files in the directory. Thirdly, I have no idea why it was launching Audacious, because Audacious is not even specified as the default media player for MP4 files in KDE’s ‘System Settings’ > ‘File Associations’.

This has annoyed me for a long time, but only today did I resolve to fix it, although it was not so easy to find a working solution by searching the Web. It seems it is a common problem with Firefox in Linux, and I found threads in various forums recommending the creation of a set of preferences by using about:config. Some of those threads state that one of those preferences should specify Konqueror; other threads state that one of the preferences should specify a shell script. In the end I discovered a post in an openSUSE Forums thread from 2012 Re: How use Dolphin to “open containing folder” from firefox downloads? providing a broken link to a thread at a different Web site and, fortunately, quoting the solution which worked for me, which is to create a file named ~/.local/share/applications/defaults.list containing the following:

[Default Applications]
x-directory/normal=kde4-dolphin.desktop;kde4-kfmclient_dir.desktop;

Now when I click on the ‘Open Containing Folder’ icon in Firefox, Dolphin launches and displays the contents of ~/Downloads/ just as I would have expected from the beginning.

Opening multiple browser tabs simultaneously — AutoKey comes to the rescue

I sometimes consult several dictionary Web sites concurrently. Typically I have them open simultaneously on different browser tabs so that I can switch between them quickly. Naturally I have the sites bookmarked, but it is still a bit of a nuisance to have to open each site by clicking on the browser’s ‘Open a new tab’ icon and then clicking on a bookmark. So I thought it would be nice if I could have an icon in the browser or on the Desktop that I could click to open all the desired Web pages at once.

Well, I could have created a Desktop Configuration File in ~/Desktop/ to launch a command such as the one listed below, and given the file a nice icon.

firefox http://www.oxforddictionaries.com/ http://michaelis.uol.com.br/moderno/portugues/index.php http://www.conjuga-me.net/ http://www.priberam.pt/dlpo/ http://www.wordreference.com/

Then I would have been able to double-click on the icon on my Desktop, which would have launched a separate Firefox window with those five required Web sites in different tabs. But what if I happened to have an existing window maximised? I would then have to move it to be able to see the icon on the Desktop. So I decided that was not an ideal approach.

Next I thought about the possibility of a Firefox extension, so I searched the Mozilla Add-ons site and found one called Open Multiple Locations. But, from what I read, it seems the extension is no longer being maintained. Furthermore, it appears it would have to be launched from the browser’s File menu, which would still be a little inconvenient.

Then I remembered that I have the excellent utility AutoKey installed, so why not define a hotkey sequence to do what I wanted? This is what I did.

When you install AutoKey, it creates a directory ~/.config/autokey/data/My Phrases/ which contains directories named Addresses and Sample Scripts. The latter two directories contain examples of what you can do with AutoKey. Now, one of the example scripts in Sample Scripts is Insert Date.py, a very simple script which enables you to issue the Linux date command with a hotkey combination, preconfigured as Ctrl-Alt-d (Click on the Insert Date entry in the left pane of the AutoKey window and notice in the lower right pane that the hotkey is listed and there are Set and Clear buttons to enable you to change it).

So I used the Desktop Environment’s GUI to navigate to the directory ~/.config/autokey/data/My Phrases/ and created a directory which I called ~/.config/autokey/data/My Phrases/My Scripts/. I copied the file ~/.config/autokey/data/My Phrases/Sample Scripts/Insert Date.py into the new directory and renamed it Launch_Firefox_with_dictionaries.py then set its AutoKey hotkey combination to be Ctrl-Alt-f and edited it to contain the desired command:

output = system.exec_command("firefox http://www.oxforddictionaries.com/ http://michaelis.uol.com.br/moderno/portugues/index.php http://www.conjuga-me.net/ http://www.priberam.pt/dlpo/ http://www.wordreference.com/")
keyboard.send_keys(output)

Now, when I am using a browser (be it Firefox, Chrome, Konqueror or whatever) or any other application and I need to consult those dictionaries, I just press Ctrl-Alt-f and up pops a Firefox window containing five tabs with the Web sites I wish to be able to use. Done and done.

Of course, if you happen to be using a Desktop Environment that has its own shortcut tool, you can use that instead. For example, in KDE I could have instead used ‘System Settings’ > ‘Shortcuts and Gestures’ | ‘Custom Shortcuts’ and configured Ctrl-Alt-f to run the above-mentioned command to launch Firefox with those five URLs. (You need to log out of KDE and log in again for the shortcut to become active.) That would have achieved exactly the same result as with AutoKey.