Opening multiple browser tabs simultaneously — AutoKey comes to the rescue

hotkey to launch an application

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.

WINE tips: File associations for Windows applications in Linux (continued)

There is a downside to the approach described in my previous post regarding file associations for Windows applications run via WINE, at least in the case of KDE.

By using KDE’s ‘System Settings’ > ‘File Associations’ to change the application launch command from:

env WINEPREFIX="/home/fitzcarraldo/.wine-visio5" WINEARCH="win32" wine /home/fitzcarraldo/.wine-visio5/drive_c/Program\ Files/Visio/Visio32.EXE

to:

env WINEPREFIX="/home/fitzcarraldo/.wine-visio5" WINEARCH="win32" wine C:\\windows\\command\\start.exe /Unix %U

the launch command in KDE’s Kicker application launcher menu is also changed to the latter. Trying to launch the Windows application from the Kicker menu (Wine > Programs > a_Windows_application) then fails. Presumably this is because the wine command expects a filename (the %U in the command string) but that is not being provided.

Alternative 1

One solution is to use a shell script as described in my earlier post: WINE tips: How to associate IrfanView with an image file type in Linux. Kicker can still be used to launch the application (e.g. Wine > Programs > IrfanView) when the menu command is of the following form but no filename is provided (even though the %f is left in the command string):

/home/fitzcarraldo/launch_IrfanView.sh %f

Alternative 2

Another solution – well, really a work-around – is to accept that the Windows application cannot be launched from the Kicker menu and to create a separate Desktop Configuration File in /home/fitzcarraldo/Desktop/ which uses a different command to launch the application. For example, in my previous post the file association I configured via ‘System Settings’ > ‘File Associations’ for Visio was:

env WINEPREFIX="/home/fitzcarraldo/.wine-visio5" WINEARCH="win32" wine C:\\windows\\command\\start.exe /Unix %U

and therefore the command in the Kicker menu entry is the same, but I created a Desktop Configuration File which I named ‘/home/fitzcarraldo/Desktop/Visio 5 Professional‘ which contains the command:

env WINEPREFIX="/home/fitzcarraldo/.wine-visio5" WINEARCH="win32" wine /home/fitzcarraldo/.wine-visio5/drive_c/Program\ Files/Visio/Visio32.EXE

$ ls -la ~/Desktop/Visio*
-rwxrwxrwx 1 fitzcarraldo users 562 Aug 26 17:42 /home/fitzcarraldo/Desktop/Visio 5 Professional

Notice that the command to launch the Windows application does not contain a filename parameter (%U), so when I double-click on the icon on the Desktop it launches Visio.

Summary

Ideally, KDE should be changed to allow the application launching command in ‘System Settings’ > ‘File Associations’ to be edited to be different to the application launching command in the Kicker menu. In the absence of that, you have two alternatives in the case of WINE:

  1. Create a shell script to launch the application. This allows you to launch the Windows application via Kicker and by double-clicking on a file of the applicable type.

    or

  2. Create a separate Desktop Configuration File in e.g. the ~/Desktop/ directory. This allows you to launch the Windows application by double-clicking on a Desktop Configuration File for the application and by double-clicking on a file of the applicable type. However you cannot launch the application from its entry in the Kicker menu.

WINE tips: File associations of Windows applications in Linux

I have several applications for Windows installed under WINE in Linux. These applications launch correctly if I double-click on a file for that application, but, in the case of some of these applications, the file itself is not opened. Therefore I first have to launch the application and then load the file from within the application (File > Open, or whatever). Some time ago I explained how to fix this in the case of IrfanView by creating a shell script – see my post WINE tips: How to associate IrfanView with an image file type in Linux – but there is an easier way to do it in many cases, as illustrated by the example below for another Windows application I use regularly in Linux. I finally got fed up with not being able to open .vsd (Visio drawing) files by double-clicking on them in Linux, and decided to fix this. The same procedure applies, whatever the Windows application.

I use KDE, but the principle applies whatever Desktop Environment you are using. Just use the relevant File Association configuration tool for that Desktop Environment.

  1. I selected ‘System Settings’ > ‘File Associations’ from the KDE Kickoff menu launcher.

  2. I entered ‘vsd’ (without the quotes) in the search field in order to find the application associated with that file type.

    The ‘Known Types’ box then displayed the following:

    >- application

  3. When I expanded that by clicking on it, the ‘Known Types’ box displayed the following two application file types:

    v- application
            vnd.ms-visio.viewer
            vnd.visio

  4. Clicking on either displayed ‘Visio 5.0 Professional’ in the ‘Application Preference Order’ box. I selected it and clicked on ‘Edit…’, which opened a Properties window for the application’s desktop configuration file.

  5. I clicked on the ‘Application’ tab. The ‘Command’ box contained the following command:
    env WINEPREFIX="/home/fitzcarraldo/.wine-visio5" WINEARCH="win32" wine /home/fitzcarraldo/.wine-visio5/drive_c/Program\ Files/Visio/Visio32.EXE

    (The wine command itself has to be preceded by the definition of the WINEPREFIX and WINEARCH environment variables because I specified those environment variables originally when I installed the application via WINE.)

    I changed the command to be the following:

    env WINEPREFIX="/home/fitzcarraldo/.wine-visio5" WINEARCH="win32" wine C:\\windows\\command\\start.exe /Unix %U

    for both vnd.ms-viso.viewer and vnd.visio application file types, and clicked on ‘OK’ and ‘Apply’.

That’s all there was to it. Now when I double-click on any file ending with ‘.vsd’, Visio launches as before but the actual file is opened in the application. Very straightforward, and I really should have made the effort to fix it sooner. :-)

Dragging windows between sides of the KWin Desktop Cube

The KDE Desktop Cube is one of the ‘eye-candy’ features provided by KWin’s Desktop Effects. Actually I use the desktop cube a lot at work (far more than at home), as I often have several windows open simultaneously on each virtual desktop (cube side) and, for some reason, I find it more natural (and fun) to rotate an on-screen cube rather than switch between 2D virtual desktops. Perhaps it’s because we live in a 3D world?

I also like to be able to drag windows from one cube face to another, a KWin feature I also find natural and fast to use. However, its configuration is not as intuitive as that of some of the other desktop effects. Also, this feature can be prevented from working if some of the other effects are enabled. Sometimes I find the feature has become disabled after I have upgraded KDE. For example, if I drag a window to the edge of the screen the cube stubbornly refuses to rotate and the window snaps to the side of the screen and expands vertically (something with which Windows 7 users will be familiar). I always forget how to reconfigure KWin to be able to drag windows between cube faces, and end up wasting several minutes fiddling with the KWin settings. This happened to me again today, so, in case others get fed up trying to get it working, here is a configuration that works for me:

  • Select ‘System Settings’ > ‘Desktop Effects’.
  • Click on the ‘All Effects’ tab.
  • ‘Desktop Cube’ and ‘Desktop Cube Animation’ should be ticked.
  • Click on the spanner icon of ‘Desktop Cube Animation’ and make sure ‘Start animation when moving windows towards screen edges’ is not ticked.

  • Select ‘System Settings’ > ‘Workspace Behaviour’.
  • Click on ‘Screen Edges’.
  • Make sure ‘Maximise windows by dragging them to the top of the screen’ and ‘Tile windows by dragging them to the side of the screen’ are not ticked.
  • Select ‘Only When Moving Windows’ for ‘Switch desktop on edge’.
  • Adjust the ‘Activation delay’ and ‘Reactivation delay’ to your taste. I find 150 ms and 1000 ms, respectively, work well on my main laptop.

KDE Connect – Link your Android device to your KDE desktop

KDE Connect app icon on my Samsung Galaxy Note II

KDE Connect app icon on my Samsung Galaxy Note II

KDE Connect is a nice tool that links your Android phone or tablet seamlessly via WiFi to KDE on your PC (the latter can be connected via WiFi or cable to the network). It allows your KDE desktop to receive notifications, files and media player commands from your Android device. The available KDE Connect plug-ins are:

Battery report
Periodically report battery status

Clipboard sync
Share the clipboard content

Multimedia remote controls
Control audio/video from your phone
(pause; first track; previous track; next track; last track; change volume)

Notification sync
Access your notification from other devices

Ping
Send and receive pings

Telephony notifier
Send notifications from SMS and calls

You will need to install the Android KDE Connect application on your Android device, and the Linux KDE Connect application on your PC.

Install the KDE Connect app on your Android device from the Google Play Store. You will then see the KDE Connect icon on the apps screen of your Android device.

For Gentoo users an ebuild for KDE Connect is available in the Gentoo KDE team’s testing overlay, so here are the instructions on how to install KDE Connect on your PC from there.

Firstly, mask the KDE overlay so that none of the packages in it interferes with the KDE software you installed from the main Portage tree:

# echo "*/*::kde" >> /etc/portage/package.mask

Then unmask the KDE Connect package in the KDE overlay:

# echo "kde-misc/kdeconnect" >> /etc/portage/package.unmask

N.B. If /etc/portage/package.mask is a directory rather than a file (either is possible) in your installation, and if /etc/portage/package.unmask is a directory rather than a file (either is possible) in your installation, use the following commands instead of the above two commands:

# echo "*/*::kde" > /etc/portage/package.mask/kde_overlay
# echo "kde-misc/kdeconnect" > /etc/portage/package.unmask/kdeconnect

Now add the KDE overlay and merge the package:

# layman -a kde
# emerge kdeconnect

If a firewall is running on your PC, you will need to configure it to allow tcp and udp traffic via a specific range of ports (1714 to 1764). I have UFW running on my main laptop, so in my case I used the following commands:

# ufw allow proto tcp to any port 1714:1764
# ufw allow proto udp to any port 1714:1764

The rules should look like this:

# ufw status verbose | grep 1714
1714:1764/tcp ALLOW IN Anywhere
1714:1764/udp ALLOW IN Anywhere
1714:1764/tcp ALLOW IN Anywhere (v6)
1714:1764/udp ALLOW IN Anywhere (v6)

If you have the KConfig Module kcm_ufw installed on your PC then you can instead use System Settings > Firewall to add the UFW rules via the KDE GUI.

By the way, to check which KConfig modules are installed on your PC you can use the following command under your user account:

$ kcmshell4 --list

Using KDE Connect is not difficult, so I will leave you to play with it. Obviously make sure WiFi is enabled on your Android device, and that it and your PC are connected to the same network. Tap on the KDE Connect icon on your Android device to launch the app, and you should see your PC’s name listed under CONNECTED DEVICES. Tap on the PC name and you should see the following screen:

KDE Connect screen

KDE Connect screen

If you tap on ‘Send ping’, the KDE Notification widget on the KDE System Tray should pop up a notification.

You can see what KDE Connect plug-ins are available, and select/deselect them:

KDE Connect plugins

KDE Connect plugins

KDE Connect also enables you to use your Android device as a remote control for media players running on your PC. When you launch a media player in KDE its name will appear in a list of selectable players in KDE Connect, and the name of the track currently playing will also be displayed:

KDE Connect - Remote control

KDE Connect - Remote control

When you select a file on your Android device and tap the Share icon, KDE Connect will be one of the options displayed on the ‘Share via’ menu. This is a handy way to send files from your Android device to your PC. The KDE Notification widget on your PC will notify you when the file has been transferred to ~/Desktop/ on your PC:

KDE on your PC notifies you when a file has been sent via KDE Connect

KDE on your PC notifies you a file has been sent via KDE Connect

You should also get notifications on your KDE desktop when someone phones or sends you an SMS.

Kudos and many thanks to the people responsible for KDE Connect. KDE is already a superb desktop environment, and with the addition of KDE Connect it is better still.

ARTE Live Web videos

The Franco-German cultural Web site ARTE Live Web is an excellent resource for lovers of music (classical, jazz, alternative and World) and dance. The show videos at the site are enjoyable but unfortunately only viewable for a fixed period of time before the site removes them. Back in 2011 I wanted to download the video of a performance I’d attended and loved. I searched for a Linux tool but could not find one, then found a Windows freeware GUI tool called artepupper, and used version 0.2 to download the video. You can read about the tool on the author’s blog pages artepupper 0.1, artepupper 0.2 and artepupper 0.3. The reason for the change from 0.2 to 0.3 was that ARTE Live Web changed the format of an embedded URL inside the XML page for the video on their Web site.

Now, artepupper is based on livewebarte1.1.sh, a 2010 Bash script by Carmelo Ingrao, and a Perl script livewebarte.pl by Juan Domingo based on livewebarte1.1.sh, both of which are still available on line at Carmelo’s download page and which I only discovered after using artepupper in Windows. I tried the Perl script in Linux back in 2011, and it worked for me.

Recently I wanted to download another video from the ARTE Live Web site and found that, although artepupper 0.3 in Windows worked, the Perl script livewebarte.pl no longer worked. Presumably this was because of the aforementioned change to the embedded URL. However, I found that the Bash script livewebarte1.1.sh still worked. Actually, I had to edit the script to replace “./rtmpdump” with “rtmpdump“, as I had installed the command-line tool rtmpdump using the Linux distribution’s package manager and the executable is not stored in the same directory as the Bash script. But, apart from that, it worked.

Carmelo is a star for having deciphered how to access and download videos from the site. However, looking at his Bash script, the part where he parses a line in the XML code and extracts a string between the delimiters “MP4″ and “mp4″ is based on a hard-coded character position, which could change if the Web site’s owners change the format of the URL. So I decided to modify the Bash script to avoid using character positions to extract a string. The Bash script livewebarte1.2.sh is an updated version of Carmelo’s livewebarte1.1.sh script.

#!/bin/bash
# Script pour récupérer les vidéos FLV du site liveweb.arte.tv
# par Carmelo Ingrao <carmelo42@gmail.com> http://c.ingrao.free.fr/code/
# version 1.0
# release date 21 février 2010
## modified by Fitzcarraldo 24 April 2013
## version 1.2
## release date 24 April 2013
# licence : GPLv2
# rtmpdump compilé doit être dans le même répertoire que le script
## rtmpdump must be installed and in user's $PATH (e.g. I have it in /usr/bin/)
# utilisation du script :
#
# ./script.sh url fichier.flv
# _______________

# url --> $1
# fichier --> $2

# fichier de sortie
# on efface l'écran avant de commencer
clear

# on affiche les infos sur le script
echo "livewebarte.sh version 1.0."
echo "(c) 2010 Carmelo Ingrao; License : GPL"
echo "livewebarte.sh version 1.2."
echo "updated from version 1.1 by Fitzcarraldo on 24 April 2013; License : GPL"
echo "usage : ./livewebarte.sh url_concert_sur_liveweb.arte.tv fichier.flv"
echo "rtmpdump must be installed and in your path."

# on télécharge le code source de la page streamant le concert dans le fichier sourceconcert.html
wget $1 -O sourceconcert.html

# on récupère le numéro d'event et on le copie dans eventok.txt
#cat sourceconcert.html | grep "new LwEvent" > event.txt
#cat event.txt | cut -b "15 16 17" > eventok.txt
grep "new LwEvent" sourceconcert.html | grep -E -o -e "[0-9]+" > eventok.txt

# on prend le fichier XML d'arte et on crée l'url avec le bon numéro d'event
# xmloriginal="http://arte.vo.llnwd.net/o21/liveweb/events/event-610.xml"

# url du xml sans le numéro d'event original (pour faciliter)
xmloriginal2="http://arte.vo.llnwd.net/o21/liveweb/events/event-"

# on assigne à la variable b le contenu de eventok.txt --> numéro correct d'event
b=$(cat eventok.txt)

# on créer l'url correct du fichier XML qu'on téléchargera
xmlok=$(echo $xmloriginal2$b)
finxml=".xml"
xmlfinal=$(echo $xmlok$finxml)

# on télécharge le bon XML
wget $xmlfinal -O xmlok.xml
echo "Fichier XML téléchargé"

## I have changed the code in this part:
# on extrait le nom du fichier MP4 depuis le fichier xmlok.xml
mp4hd=$(cat xmlok.xml | grep "urlHd")
# on efface le début de l'url du MP4
# on efface le surplus à la fin du nom du MP4 et on sauve le nom dans la variable mp4hdcut2
mp4hdcut2=${mp4hd#*MP4}
mp4hdcut2=${mp4hdcut2%%mp4*}
mp4hdcut2="MP4"$mp4hdcut2"mp4"
## end of my changes to evaluate mp4hdcut2

# on lance la commande rtmpdump avec les paramètres
# rappel :
# $2 = nom du fichier de sortie
# $mp4hdcut2 = nom du fichier MP4

## Carmelo had ./rtmpdump here, but I removed the "./"
rtmpdump -r rtmp://arte.fcod.llnwd.net:1935/a2306/o25 -a a2306/o25 -f LNX 10,0,45,2 -W http://liveweb.arte.tv/flash/player.swf -t rtmp://arte.fcod.llnwd.net:1935/a2306/o25 -p http://liveweb.arte.tv/ -o $2 -y $mp4hdcut2

# on efface les fichiers crées
rm sourceconcert.html
#rm event.txt
rm eventok.txt
rm xmlok.xml

# Affichage des infos de fin
echo "________"
echo "Voilà, le téléchargement est terminé."
echo "Le fichier se trouve ici :"
echo " "
echo $2
echo " "
echo "Bon visionnage"
echo " "
echo " "
exit 0

Save it in your home directory and make it executable:

$ chmod +x livewebarte1.2.sh

Also make sure you have the package rtmpdump installed and that it is in your $PATH.

Then you can browse the ARTE Live Web site and select the performance video you wish to download. Hover the mouse pointer over the video pane and click on “INTEGRER LA VIDEO” to find the URL for that video, which will be of the form http://liveweb.arte.tv/fr/video/foo/, where “foo” is some string of characters (not literally “foo”, of course). The command to download it is then as shown below. I’ll use a file name foo.flv here, but any prefix would do:

$ ./livewebarte1.2.sh http://liveweb.arte.tv/fr/video/foo/ foo.flv

Note that it is essential to include the forward slash at the end of the URL. The file will be downloaded to your home directory and you can watch it in VLC or any other Linux media player that plays Flash video.

So there you have it; currently you can use artepupper 0.3 in Windows or livewebarte1.2.sh in Linux to download from ARTE Live Web a video of a performance you attended and loved.

Switching the display quickly between a laptop monitor and an external monitor or projector in Linux

laptop_with_external_monitor_and_keyboardI connect my laptop to an external keyboard and an external monitor or projector in various offices and at home, and each of the monitors has a different resolution. Fn-F3 on my laptop keyboard allows me to toggle between monitors, but I want more control (including the ability to specify the resolution of the external display). Now, I find the GPU manufacturer’s application and the Desktop Environment’s GUI for switching monitors and changing screen resolution rather cumbersome, so I wanted an icon on the Desktop that I could double-click to switch monitors without having to enter the root user’s password and fiddle around too much. So I decided to create some simple Bash scripts and associated Desktop Config files with nice-looking icons on the desktop, which I can launch easily and quickly by double-clicking. Obviously the resolutions are limited to the range of resolutions supported by the GPU and external monitor.

The suite of Desktop Config files I created have self-explanatory names:

$ cd ~/Desktop
$ ls -1 Switch*
Switch_OFF_laptop_monitor_if_external_monitor_is_connected
Switch_OFF_laptop_monitor_if_external_monitor_is_connected_auto
Switch_ON_laptop_monitor_and_external_monitor
Switch_ON_laptop_monitor_and_switch_off_external_monitor
$ ls -1 Toggle*
Toggle_display

The difference between Switch_OFF_laptop_monitor_if_external_monitor_is_connected and Switch_OFF_laptop_monitor_if_external_monitor_is_connected_auto is that the former prompts for the resolution of the external monitor whereas the latter tries to find the resolution automatically. I have both because I have found that, for some external display devices (e.g. projectors), it is handy to have the ability to specify the resolution manually.

Switch off the laptop monitor if an external monitor is connected (find resolution automatically)

The Desktop Config file I double-click the most is ~/Desktop/Switch_OFF_laptop_monitor_if_external_monitor_is_connected_auto, and it contains the following text:

[Desktop Entry]
Comment[en_GB]=switch off laptop monitor if external monitor is connected auto
Comment=switch off laptop monitor if external monitor is connected auto
Exec=sh /home/fitzcarraldo/switch_off_laptop_monitor_if_external_monitor_is_connected_auto.sh
GenericName[en_GB]=Switch off laptop monitor if external monitor is connected auto
GenericName=Switch off laptop monitor if external monitor is connected auto
Icon=/home/fitzcarraldo/Pictures/Icons/display.png
MimeType=
Name[en_GB]=Switch_OFF_laptop_monitor_if_external_monitor_is_connected_auto
Name=Switch_OFF_laptop_monitor_if_external_monitor_is_connected_auto
Path=
StartupNotify=true
Terminal=false
TerminalOptions=
Type=Application
X-DBUS-ServiceName=
X-DBUS-StartupType=none
X-KDE-SubstituteUID=false
X-KDE-Username=

The Bash script it launches, ~/switch_off_laptop_monitor_if_external_monitor_is_connected_auto.sh, contains the following code:

#!/bin/bash
if xrandr -q | grep "CRT1 connected"; then
  xrandr --output LVDS --off
  xrandr --output CRT1 --off
  xrandr --output CRT1 --auto
else
  xrandr --output CRT1 --off
  xrandr --output LVDS --off
  xrandr --output LVDS --mode 1920x1080
# 1920x1080 is the native resolution of my laptop monitor
fi

Don’t forget to make them executable:

$ chmod +x /home/fitzcarraldo/Desktop/Switch_OFF_laptop_monitor_if_external_monitor_is_connected_auto
$ chmod +x /home/fitzcarraldo/switch_off_laptop_monitor_if_external_monitor_is_connected_auto.sh

If you’re wondering how I knew I had to specify ‘CRT1′ and ‘LVDS’ in the Bash script, I used the xrandr command to find out what names the GPU gives the monitors:

$ xrandr
Screen 0: minimum 320 x 200, current 1920 x 1080, maximum 1920 x 1920
LVDS connected (normal left inverted right x axis y axis)
1920x1080 60.0 +
1680x1050 60.0
1400x1050 60.0
1600x900 60.0
1280x1024 60.0
1440x900 60.0
1280x960 60.0
1280x768 60.0
1280x720 60.0
1024x768 60.0
1024x600 60.0
800x600 60.0
800x480 60.0
640x480 60.0
DFP1 disconnected (normal left inverted right x axis y axis)
CRT1 connected 1920x1080+0+0 (normal left inverted right x axis y axis) 476mm x 268mm
1920x1080 60.0*+
1280x1024 75.0 60.0
1280x960 60.0
1280x800 59.8
1152x864 75.0
1280x720 60.0
1024x768 75.0 70.1 60.0
800x600 72.2 75.0 60.3 56.2
640x480 75.0 72.8 67.0 59.9

Switch off the laptop monitor if an external monitor is connected (enter resolution)

The Desktop Config file I double-click is ~/Desktop/Switch_OFF_laptop_monitor_if_external_monitor_is_connected, and it contains the following text:

[Desktop Entry]
Comment[en_GB]=switch off laptop monitor if external monitor is connected
Comment=switch off laptop monitor if external monitor is connected
Exec=sh /home/fitzcarraldo/System_Administration/switch_off_laptop_monitor_if_external_monitor_is_connected.sh
GenericName[en_GB]=Switch off laptop monitor if external monitor is connected
GenericName=Switch off laptop monitor if external monitor is connected
Icon=/home/fitzcarraldo/Pictures/Icons/display.png
MimeType=
Name[en_GB]=Switch_OFF_laptop_monitor_if_external_monitor_is_connected
Name=Switch_OFF_laptop_monitor_if_external_monitor_is_connected
Path=
StartupNotify=true
Terminal=true
TerminalOptions=
Type=Application
X-DBUS-ServiceName=
X-DBUS-StartupType=none
X-KDE-SubstituteUID=false
X-KDE-Username=

The Bash script it launches, ~/switch_off_laptop_monitor_if_external_monitor_is_connected.sh, contains the following code:

#!/bin/bash
if xrandr -q | grep "CRT1 connected"; then
echo -n "Enter resolution width of external monitor (hint 1920 Doha, 1440 home): "
read EXTERNAL_WIDTH
echo -n "Enter resoluton height of external monitor (hint 1080 Doha, 900 home): "
read EXTERNAL_HEIGHT
  xrandr --output LVDS --off
  xrandr --output CRT1 --off
  xrandr --output CRT1 --mode $EXTERNAL_WIDTH"x"$EXTERNAL_HEIGHT
else
  xrandr --output CRT1 --off
  xrandr --output LVDS --off
  xrandr --output LVDS --mode 1920x1080
# 1920x1080 is the native resolution of my laptop monitor
fi

Don’t forget to make them executable:

$ chmod +x /home/fitzcarraldo/Desktop/Switch_OFF_laptop_monitor_if_external_monitor_is_connected
$ chmod +x /home/fitzcarraldo/switch_off_laptop_monitor_if_external_monitor_is_connected.sh

Switch on the laptop monitor and external monitor simultaneously

I don’t need to use this one much, only when I am using an external monitor but suddenly want to use the laptop’s built-in Webcam and so have to open fully the laptop’s lid. The file ~/Desktop/Switch_ON_laptop_monitor_and_external_monitor contains the following text:

[Desktop Entry]
Comment[en_GB]=switch_ON_laptop_monitor_and_external_monitor
Comment=switch_ON_laptop_monitor_and_external_monitor
Exec=sh /home/fitzcarraldo/switch_on_laptop_monitor_and_external_monitor.sh
GenericName[en_GB]=Switch_ON_laptop_monitor_and_external_monitor
GenericName=Switch_ON_laptop_monitor_and_external_monitor
Icon=/home/fitzcarraldo/Pictures/Icons/display.png
MimeType=
Name[en_GB]=Switch_ON_laptop_monitor_and_external_monitor
Name=Switch_ON_laptop_monitor_and_external_monitor
Path=
StartupNotify=true
Terminal=true
TerminalOptions=
Type=Application
X-DBUS-ServiceName=
X-DBUS-StartupType=none
X-KDE-SubstituteUID=false
X-KDE-Username=

and the Bash script it calls, ~/switch_on_laptop_monitor_and_external_monitor.sh, contains the following code:

#!/bin/bash
if xrandr -q | grep "CRT1 connected"; then
  echo "Note that the resolution specified must be the same for both monitors, and must be achievable on both monitors."
  echo -n "Enter resolution width of external monitor (hint 1920 office, 1440 home): "
  read EXTERNAL_WIDTH
  echo -n "Enter resoluton height of external monitor (hint 1080 office, 900 home): "
  read EXTERNAL_HEIGHT
  #xrandr --output LVDS --off
  xrandr --output LVDS --mode $EXTERNAL_WIDTH"x"$EXTERNAL_HEIGHT
  xrandr --output CRT1 --off
  xrandr --output CRT1 --mode $EXTERNAL_WIDTH"x"$EXTERNAL_HEIGHT
else
  xrandr --output CRT1 --off
  xrandr --output LVDS --off
  xrandr --output LVDS --mode 1920x1080
# 1920x1080 is the native resolution of my laptop monitor
fi

Don’t forget to make them executable:

$ chmod +x /home/fitzcarraldo/Desktop/Switch_ON_laptop_monitor_and_external_monitor
$ chmod +x /home/fitzcarraldo/switch_on_laptop_monitor_and_external_monitor.sh

Switch on the laptop monitor and switch off an external monitor

I don’t need to use this one much either, given that the display mode reverts to the laptop monitor after I reboot or shutdown/power-up the laptop. The file ~/Desktop/Switch_ON_laptop_monitor_and_external_monitor contains the following text:

[Desktop Entry]
Comment[en_GB]=switch on laptop monitor and switch off external monitor
Comment=switch on laptop monitor and switch off external monitor
Exec=sh /home/fitzcarraldo/switch_on_laptop_monitor_and_switch_off_external_monitor.sh
GenericName[en_GB]=Switch on laptop monitor and switch off external monitor
GenericName=Switch on laptop monitor and switch off external monitor
Icon=computer-laptop
MimeType=
Name[en_GB]=Switch_ON_laptop_monitor_and_switch_off_external_monitor
Name=Switch_ON_laptop_monitor_and_switch_off_external_monitor
Path=
StartupNotify=true
Terminal=false
TerminalOptions=
Type=Application
X-DBUS-ServiceName=
X-DBUS-StartupType=
X-KDE-SubstituteUID=false
X-KDE-Username=

The Bash script it launches, ~/switch_on_laptop_monitor_and_switch_off_external_monitor.sh, contains the following code:

#!/bin/bash
xrandr --output CRT1 --off
xrandr --output LVDS --auto
xrandr --output LVDS --mode 1920x1080
# 1920x1080 is the native resolution of my laptop monitor

I did also create a fifth Desktop Config file and associated Bash script, to toggle between the three modes (laptop monitor only > both monitors > external monitor only) rather than having to double-click three different icons. But, to be honest, it’s quicker and easier to have the three icons and double-click on the one I want rather than toggling through three display modes. Anyway, in case you are interested, the Desktop Config file ~/Desktop/Toggle_Display contains the follow text:

[Desktop Entry]
Comment[en_GB]=Toggle between laptop monitor, external monitor and both
Comment=Toggle between laptop monitor, external monitor and both
Exec=sh /home/fitzcarraldo/toggle_display.sh
GenericName[en_GB]=Toggle between laptop monitor, external monitor and both
GenericName=Toggle between laptop monitor, external monitor and both
Icon=video-display
MimeType=
Name[en_GB]=Toggle_display
Name=Toggle_display
Path=
StartupNotify=false
Terminal=false
TerminalOptions=
Type=Application
X-DBUS-ServiceName=
X-DBUS-StartupType=none
X-KDE-SubstituteUID=false
X-KDE-Username=

and the Bash script it launches, ~/switch_on_laptop_monitor_and_external_monitor.sh, contains the following code:

#!/bin/sh

# Using the xrandr command I found that the two video outputs from my laptop are named LVDS
# (the internal display) and CRT1 (the external display driven by the laptop's VGA socket).
# My external monitor at home has a resolution of 1440x900.

CONNECTED=`xrandr | grep -i ' connected' | grep LVDS | awk '{print $1}'`
CONNECTED="${CONNECTED} `xrandr | grep -i ' connected' | grep CRT | awk '{print $1}'`"

ENABLED=`awk '{print;exit}' ~/displays_enabled 2>/dev/null`

if [ "$CONNECTED" = "LVDS" -o "$CONNECTED" = "LVDS " -o "$CONNECTED" = " LVDS" ]; then
        # Only the internal display is connected, so don't do anything.
        echo "LVDS" > ~/displays_enabled
        ENABLED="LVDS"
        xrandr --output CRT1 --off
        xrandr --output LVDS --off
        xrandr --output LVDS --auto
        exit 0
elif [ "$CONNECTED" = "LVDS CRT1" ]; then
        # Both the internal and external displays are connected, so let's toggle
        # LVDS > LVDS,CRT1 > CRT1

        EXTERNALRES=`xrandr | awk 'c&&c--;/ connected/{c=1}' | awk '{print $1}' | grep 1440x900`
        if [ "$ENABLED" = "LVDS" ]; then
        # Switching on both displays.
                xrandr --output LVDS --off
                if [ "$EXTERNALRES" = "1440x900" ]; then
                         xrandr --output LVDS --mode 1440x900
                         xrandr --output CRT1 --off
                         xrandr --output CRT1 --auto
                else
                         xrandr --output LVDS --auto
                         xrandr --output CRT1 --off
                         xrandr --output CRT1 --auto
                fi
                ENABLED="LVDS CRT1"
                echo "LVDS CRT1" > ~/displays_enabled
        elif [ "$ENABLED" = "LVDS CRT1" ]; then
        # Switching on only external display.
                xrandr --output LVDS --off
                xrandr --output CRT1 --off
                xrandr --output CRT1 --auto
                ENABLED="CRT1"
                echo "CRT1" > ~/displays_enabled
        else
        # Switching on only internal display.
                xrandr --output CRT1 --off
                xrandr --output LVDS --off
                xrandr --output LVDS --auto
                ENABLED="LVDS"
                echo "LVDS" > ~/displays_enabled
        fi
fi

As I use KDE, I also used System Settings > Shortcuts and Gestures | Custom Shortcuts to create a keyboard shortcut which I named ‘Toggle display’, with Meta+P as Trigger and sh ~/toggle_display.sh as Action, but I tend to use the mouse rather than the keyboard in any case.

By the way, you might think some of the xrandr commands in the above Bash scripts are redundant. You would be correct in thinking that, but in practice I found that the displays did not switch if I didn’t include the additional commands shown (due to a bug in xrandr, perhaps?). Even then, when I switch to an external monitor, occasionally the screen resolution is slightly too big or too small, so I placed the icons at the top left of the desktop so that they are always accessible and I can just double-click on the same icon again if necessary. As I’m using KDE, I placed a Folder View Plasmoid for ~/Desktop/ at the top left of the desktop, as you can see in the screenshot.

Desktop showing icons for switching between monitors

Footnote

I’ve been using the above method of switching between displays for a couple of years now with an AMD ATI GPU. It works nicely and suits my needs perfectly. AMD has supported xrandr since 2008 (see Ref. 1), whereas NVIDIA only began to support xrandr last year (see Ref. 2) so I’m not sure how well these scripts would work with NVIDIA GPUs.

Ref. 1: AMD Catalyst 8.9 Gets WINE Fix, RandR 1.2 Support, September 18, 2008
Ref. 2: NVIDIA’s 302 Linux Driver Finally Has RandR 1.2/1.3, May 2, 2012

Setting the wireless regulatory domain in Linux on your laptop

I travel internationally and want to make sure that my laptop uses the legal wireless networking frequencies in the country I am visiting. In Linux, CRDA (Central Regulatory Domain Agent) is the udev helper used to communicate between userspace and the kernel, and it enables you to view and alter the wireless regulatory domain your kernel uses. For more information see the Regulatory page on the Linux Wireless Wiki site.

CFG80211 is the Linux wireless LAN (802.11) configuration API. The kernel on my main laptop has the following configuration settings relating to CFG80211:

# cat /usr/src/linux/.config | grep CFG80211
CONFIG_CFG80211=m
# CONFIG_CFG80211_DEVELOPER_WARNINGS is not set
# CONFIG_CFG80211_REG_DEBUG is not set
CONFIG_CFG80211_DEFAULT_PS=y
# CONFIG_CFG80211_DEBUGFS is not set
# CONFIG_CFG80211_INTERNAL_REGDB is not set
CONFIG_CFG80211_WEXT=y

and the cfg80211 module is loaded:

# lsmod | grep cfg80211
cfg80211 145747 3 iwlwifi,mac80211,iwldvm

I have the package crda installed, and I have the following udev rule file /etc/udev/rules.d/regulatory.rules to allow the kernel to communicate with userspace:

KERNEL=="regulatory*", ACTION=="change", SUBSYSTEM=="platform", RUN+="/sbin/crda"

So, how do you check which wireless regulatory domain your kernel is currently using, and switch to another domain if necessary? These tasks are performed using the iw command. You’ll need to install the package iw if it is not already installed.

To see the regulatory domain your laptop is using now, enter the following command as root user:

iw reg get

When I use the above command on my laptop after start-up, I normally see the following:

# iw reg get
country 00:
(2402 - 2472 @ 40), (3, 20)
(2457 - 2482 @ 20), (3, 20), PASSIVE-SCAN, NO-IBSS
(2474 - 2494 @ 20), (3, 20), NO-OFDM, PASSIVE-SCAN, NO-IBSS
(5170 - 5250 @ 40), (3, 20), PASSIVE-SCAN, NO-IBSS
(5735 - 5835 @ 40), (3, 20), PASSIVE-SCAN, NO-IBSS

The country code 00 is not the code of the country I am in at present. To tell the kernel which wireless regulatory domain you wish to use, enter the following command as root user:

iw reg set ISO_3166-1_alpha-2

where ISO_3166-1_alpha-2 is the 2-character code for the country you are in. You can find the list of ISO 3166-1 alpha-2 codes on the Wikipedia page ISO 3166-1 alpha-2.

For example, if I were in the UK then I would enter the following command:

# iw reg set GB

and the regulatory domain would then be reported like this:

# iw reg get
country GB:
(2402 - 2482 @ 40), (N/A, 20)
(5170 - 5250 @ 40), (N/A, 20)
(5250 - 5330 @ 40), (N/A, 20), DFS
(5490 - 5710 @ 40), (N/A, 27), DFS

It is not a big deal to use the command line, but I wanted to make it even easier. I’m using KDE on my main laptop, so I created a Desktop Configuration File /home/fitzcarraldo/Desktop/Set_wireless_regulatory_domain containing the following:

[Desktop Entry]
Comment[en_GB]=
Comment=
Exec=/home/fitzcarraldo/iw_reg.sh
GenericName[en_GB]=Set wireless regulatory domain
GenericName=Set wireless regulatory domain
Icon=/home/fitzcarraldo/national-flags-icon.png
MimeType=
Name[en_GB]=Set_wireless_regulatory_domain
Name=Set_wireless_regulatory_domain
Path=
StartupNotify=true
Terminal=true
TerminalOptions=\s--noclose
Type=Application
X-DBUS-ServiceName=
X-DBUS-StartupType=none
X-KDE-SubstituteUID=false
X-KDE-Username=

and gave it the following file permissions:

# chmod 744 /home/fitzcarraldo/Desktop/Set_wireless_regulatory_domain
# ls -la /home/fitzcarraldo/Desktop/Set_wireless_regulatory_domain
-rwxr--r-- 1 fitzcarraldo users 496 Jan 15 21:53 /home/fitzcarraldo/Desktop/Set_wireless_regulatory_domain

I used a search engine to find a nice PNG icon consisting of several overlapping national flags, and saved it with the file name name national-flags-icon.png in my home directory.

I created a Bash shell script /home/fitzcarraldo/iw_reg.sh containing the following:

#!/bin/bash
echo "First you need to enter the password of your user account..."
sudo echo ""
echo "The ISO 3166-1 alpha-2 codes are listed on Web page https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2"
echo ""
echo "The current wireless regulatory domain is set as: "
echo ""
sudo iw reg get
echo ""
echo -n "Enter the ISO 3166-1 alpha-2 code (upper case) for the country you are in now, and press ENTER: "
read REGULATORYDOMAIN
sudo iw reg set $REGULATORYDOMAIN
echo ""
echo "The current wireless regulatory domain is now set as: "
echo ""
sudo iw reg get
echo ""
echo "All done. You can close this window."

and gave it the following file permissions:

# chmod 744 /home/fitzcarraldo/iw_reg.sh
# ls -la /home/fitzcarraldo/iw_reg.sh
-rwxr--r-- 1 fitzcarraldo users 632 Jan 15 21:33 /home/fitzcarraldo/iw_reg.sh

Now, if I double-click on the icon for Set_wireless_regulatory_domain on my desktop, a Konsole window pops up with a prompt for me to enter my user account password. When I enter my password the window displays the current wireless regulatory domain the kernel is using and prompts me to enter the 2-character code for the regulatory domain I wish to use instead. When I enter the country code the window displays the new regulatory domain, as shown in the sample below.


First you need to enter the password of your user account...
Password:

The ISO 3166-1 alpha-2 codes are listed on Web page https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2

The current wireless regulatory domain is set as:

country SA:
(2402 - 2482 @ 40), (N/A, 20)
(5170 - 5250 @ 20), (3, 23)
(5250 - 5330 @ 20), (3, 23), DFS
(5735 - 5835 @ 20), (3, 30)

Enter the ISO 3166-1 alpha-2 code (upper case) for the country you are in now, and press ENTER: GB

The current wireless regulatory domain is now set as:

country GB:
(2402 - 2482 @ 40), (N/A, 20)
(5170 - 5250 @ 40), (N/A, 20)
(5250 - 5330 @ 40), (N/A, 20), DFS
(5490 - 5710 @ 40), (N/A, 27), DFS

All done. You can close this window.

The task of viewing and changing the regulatory domain after start-up is now very easy for me. The only thing that would be easier than this would be if Linux could detect automatically which country I’m in and set the regulatory domain automatically.

Converting ape music files to mp3 in Linux

I had a file in the lossless ape (Monkey’s Audio) file format, and wanted to convert it to a .mp3 file so that I could play it on my portable mp3 player. As is usual in Linux, several alternative solutions exist, and I thought I’d try three of them for fun: shntool, ffmpeg and KDE’s Konvertible (Konvertible is a GUI for ffmpeg).

I already had ffmpeg and Konvertible installed, but not shntool. So first I installed shntool and the Monkey’s Audio codecs it uses:

# emerge media-sound/mac
# emerge media-sound/shntool

Here are the details of these two installed packages:

# eix -I shntool
[I] media-sound/shntool
Available versions: 3.0.10-r1 {alac flac mac shorten sox wavpack}
Installed versions: 3.0.10-r1(08:11:30 19/12/12)(flac -alac -mac -shorten -sox -wavpack)
Homepage: http://www.etree.org/shnutils/shntool/
Description: A multi-purpose WAVE data processing and reporting utility

# eix -I media-sound/mac
[I] media-sound/mac
Available versions: 3.99.4.5.7-r1^m {mmx static-libs}
Installed versions: 3.99.4.5.7-r1^m(07:52:12 19/12/12)(mmx -static-libs)
Homepage: http://etree.org/shnutils/shntool/
Description: Monkey's Audio Codecs

Then I used the following command to convert the file My Band 1971 CoolSounds.ape to mp3:

$ shntool conv -i ape -o 'cust ext=mp3 lame - %f' My\ Band\ 1971\ CoolSounds.ape
Converting [My Band 1971 CoolSounds.ape] (59:15.39) --> [My Band 1971 CoolSounds.mp3] : 100% OK
$

The KDE utility Konvertible was also able to convert it. I double-clicked on the file My Band 1971 CoolSounds.ape in Dolphin to launch Konvertible, selected libmp3lame in the ‘Codec:’ drop-down picklist, 192.00 kbits/s in the ‘Bitrate:’ drop-down picklist, clicked on the folder icon and selected /home/fitzcarraldo as the destination directory, and finally clicked ‘Convert’.

The mp3 files created by shntool and Konvertible were of different sizes:

File created by Konvertible:

$ file My\ Band\ 1971\ CoolSounds.mp3
My Band 1971 CoolSounds.mp3: Audio file with ID3 version 2.4.0, contains: MPEG ADTS, layer III, v1, 192 kbps, 44.1 kHz, Stereo
$ ls -la My\ Band\ 1971\ CoolSounds.mp3
-rw-r--r-- 1 fitzcarraldo users 85334024 Dec 19 08:11 My Band 1971 CoolSounds.mp3
$

File created by shntool:

$ file My\ Band\ 1971\ CoolSounds.mp3
My Band 1971 CoolSounds.mp3: MPEG ADTS, layer III, v1, 128 kbps, 44.1 kHz, JntStereo
$ ls -la My\ Band\ 1971\ CoolSounds.mp3
-rw-r--r-- 1 fitzcarraldo users 56889259 Dec 19 08:29 My Band 1971 CoolSounds.mp3
$

So I added the bitrate to the shntool command:

$ shntool conv -i ape -o 'cust ext=mp3 lame -b 192 - %f' My\ Band\ 1971\ CoolSounds.ape
Converting [My Band 1971 CoolSounds.ape] (59:15.39) --> [My Band 1971 CoolSounds.mp3] : 100% OK
$

and this time the mp3 file created by shntool is comparable to the mp3 file created by Konvertible:

$ file My\ Band\ 1971\ CoolSounds.mp3
My Band 1971 CoolSounds.mp3: MPEG ADTS, layer III, v1, 192 kbps, 44.1 kHz, JntStereo
$ ls -la My\ Band\ 1971\ CoolSounds.mp3
-rw-r--r-- 1 fitzcarraldo users 85333889 Dec 19 08:56 My Band 1971 CoolSounds.mp3
$

The ffmpeg command to do the same thing is:

$ ffmpeg -i My\ Band\ 1971\ CoolSounds.ape -ar 44100 -ab 192000 out.mp3
ffmpeg version 0.10.6 Copyright (c) 2000-2012 the FFmpeg developers
built on Nov 26 2012 07:06:40 with gcc 4.6.3
configuration: --prefix=/usr --libdir=/usr/lib64 --shlibdir=/usr/lib64 --mandir=/usr/share/man --enable-shared --cc=x86_64-pc-linux-gnu-gcc --cxx=x86_64-pc-linux-gnu-g++ --ar=x86_64-pc-linux-gnu-ar --optflags='-O2 -march=native -pipe' --extra-cflags='-O2 -march=native -pipe' --extra-cxxflags='-O2 -march=native -pipe' --disable-static --enable-gpl --enable-version3 --enable-postproc --enable-avfilter --disable-stripping --disable-debug --disable-doc --disable-vaapi --disable-vdpau --enable-runtime-cpudetect --enable-gnutls --enable-libmp3lame --enable-libvo-aacenc --enable-libtheora --enable-libvorbis --enable-libx264 --enable-libxvid --enable-libfaac --enable-nonfree --enable-libdc1394 --enable-openal --disable-indev=v4l --disable-indev=oss --enable-x11grab --enable-libpulse --disable-outdev=oss --enable-libfreetype --enable-pthreads --enable-libgsm --enable-libspeex --disable-amd3dnow --disable-amd3dnowext --disable-altivec --disable-avx --disable-mmx2 --disable-ssse3 --disable-vis --disable-neon --cpu=ho
libavutil 51. 35.100 / 51. 35.100
libavcodec 53. 61.100 / 53. 61.100
libavformat 53. 32.100 / 53. 32.100
libavdevice 53. 4.100 / 53. 4.100
libavfilter 2. 61.100 / 2. 61.100
libswscale 2. 1.100 / 2. 1.100
libswresample 0. 6.100 / 0. 6.100
libpostproc 52. 0.100 / 52. 0.100
Input #0, ape, from 'My Band 1971 CoolSounds.ape':
Metadata:
Album : CoolSounds
Title : C:\1\My Band 1971 CoolSounds
Comment : Exact Audio Copy
Duration: 00:59:15.47, start: 0.000000, bitrate: 829 kb/s
Stream #0:0: Audio: ape (APE / 0x20455041), 44100 Hz, stereo, s16
Output #0, mp3, to 'out.mp3':
Metadata:
TALB : CoolSounds
TIT2 : C:\1\My Band 1971 CoolSounds
Comment : Exact Audio Copy
TSSE : Lavf53.32.100
Stream #0:0: Audio: mp3, 44100 Hz, stereo, s16, 192 kb/s
Stream mapping:
Stream #0:0 -> #0:0 (ape -> libmp3lame)
Press [q] to stop, [?] for help
size= 83334kB time=00:59:15.55 bitrate= 192.0kbits/s
video:0kB audio:83333kB global headers:0kB muxing overhead 0.000892%
$

and, as you can see below, the resulting mp3 file is the same size as the mp3 file created using Konvertible (not surprising, since Konvertible is a GUI front-end for ffmpeg) and virtually the same as the mp3 file created by shntool.

$ file out.mp3
out.mp3: Audio file with ID3 version 2.4.0, contains: MPEG ADTS, layer III, v1, 192 kbps, 44.1 kHz, Stereo
$ ls -la out.mp3
-rw-r--r-- 1 fitzcarraldo users 85334024 Dec 20 18:14 out.mp3
$

So, there you have it: GUI or command line; take your pick!

Selecting different keyboard layouts in Xfce

One of my laptops running Xfce has a British English keyboard. However, I write in Portuguese and Spanish as well and so I need to be able to switch keyboard layouts. Therefore I added the three keyboard layouts by clicking on ‘Applications Menu’ on the Xfce Panel, selecting ‘Settings’ > ‘Keyboard’ and clicking on the ‘Layout’ tab. I also created the file /etc/X11/xorg.conf.d/00-keyboard.conf containing the following:

Section "InputClass"
    Identifier "keyboard"
    MatchIsKeyboard "yes"
    Option "XkbLayout" "gb,br,es"
    Option "XkbVariant" ""
    Option "XkbOptions" "grp:alt_shift_toggle"
EndSection

As you can probably guess from the XkbOptions option I specified, pressing Alt-Shift enables me to toggle between the keyboard layouts declared in the XkbLayout option (‘gb’ = British keyboard layout; ‘br’ = Brazilian Portuguese keyboard layout; ‘es’ = Spanish keyboard layout). This works fine but I could not tell at a glance which keyboard layout was selected, without typing some text and seeing the result. It would be nice to see an icon on the Panel indicating which keyboard layout is currently selected, in the same way as is possible in KDE and GNOME. It turns out that Xfce has a plugin that does precisely this: Keyboard Layouts, which is available by installing the package xfce4-xkb-plugin. I installed it, right-clicked on the Panel and selected ‘Panel’ > ‘Add New Items…’ > ‘Keyboard Layouts’ to display the plugin’s icon on the Panel. Right-clicking on it and selecting ‘Properties’ allows you to configure the plugin, and I selected ‘Show layout as: image’ so that a flag indicating the current keyboard layout is displayed on the Panel, as shown in the snapshot below.

POWERED BY LINUX badge on Mesh Edge DX laptop

Keyboard layout icon on Xfce Panel

I can either use the keyboard shortcut Alt-Shift to toggle between the three keyboard layouts (in which case the flag changes on the Panel), or I can click on the Keyboard Layouts icon on the Panel and select the desired layout from there instead, as shown in the snapshot below.

POWERED BY LINUX badge on Mesh Edge DX laptop

Selecting keyboard layout from Xfce Panel

Follow

Get every new post delivered to your Inbox.

Join 51 other followers