-->

Monday, September 26, 2016

Using Multiple Language Keyboards in Linux

Gnome is one of the more popular of the many window managers which can be installed and used to handle functionality of the graphical user interface (GUI) in Linux and other operating systems. One of the responsibilities of the GUI is to handle keyboard and language input.

Gnome version 3.14.2 is currently packaged with Redhat/CentOS 7.2. While it has problems in several application-level regards, using more than one language's keyboard is one way in which it performs quite well. I barely needed a brain to set up my laptop for English (Am.), German and Russian phonetic keyboards and in the eight or so months I've been using it, it has only once given me a problem... in the beginning when it went crazy for some unknown reason but then somehow fixed itself ten minutes later.

Setting it up — and changing the setup later — is simply a matter of clicking on the down-arrow icon in the panel, clicking on the "crossed wrenches" icon (Settings) in the subsequent mini-window, and then selecting from that next window "Region and Language". Adding, deleting, and changing languages are all self-explanatory from that point, except that some languages, like Russian, can be a bit involved as there are about twenty different variations under "Russian". These mostly cultural distinctions, though, not technical. I chose "Russian (phonetic American)" which is an approximation of a key-by-key transliteration. "Phonetic" means that, for example, if I type, "Now is the time for all good men to come to the aid of their party." with "Russian (phonetic American)" selected, the resultant text looks like this:

Нов ис тхе тиме фор алл гоод мен то цоме то тхе аид оф тхеир парти.

Among the other keyboard layouts under the general rubric "Russian", a few provide a "standard" sort of "Russian keyboard". However, configuring for a "standard Russian" keyboard, and, yes, even for a phonetic keyboard, introduces the dilemma of knowing which (English-labeled) key produces which Russian character. Of course, if you can touch-type in Russian and don't need labels on all the keys to tell you what they are, then you're already home. Otherwise, this problem can be solved in large measure by clicking on "Show Keyboard Layout". As the name suggests, this opens another window containing a representation of a keyboard and shows where all the characters are on the keyboard of the currently selected language. Display this windown by clicking on "Show Keyboard Layout" in the language selection dropdown, discussed next.

After more than one language has been configured, there is then a dropdown in the panel which both shows the current language and allows selection of another, already-configured language. A different configured language-keyboard can be selected at any time, even in mid-sentence inside any application. Note, however, that selecting a keyboard makes it effective for all subsequent applications and navigation. It is desktop-wide. In fact, once I blanked/locked the screen, and when I wanted to log back in, the password I knew to be correct was repeatedly not accepted. My difficulty turned out to be due to the fact that I had a non-English language selected at the time I locked the screen, so even what I typed for my password (which appeared only as dots) was being entered in the current (non-English) language. Fortunately, the currently effective language keyboard is displayed and selectable also on the log-in screen, so once I noticed that, I was able to change the language back to English and successfully log in.

Because Gnome underlies the entire GUI interface, changing the language will, as said, affect all the GUI applications and functionality used. So changing the language will change it for all applications currently running or which you may subsequently launch until you select a different keyboard language. For example, if, while working on a Russian document in emacs, you then want to read email in Thunderbird, Russian will be in effect there too, even for any and all navigation keys you might try. If you want to reply to an email in English, or use alphabetic keyboard characters to navigate, then you'll need to change the language setting again. Constantly switching languages in such circumstances may become a bit tedious. What might work for you better then would be to configure the desired language keyboard for just the application(s) in which you want to use that particular language, instead of for all keyboard input.

Thursday, September 26, 2013

Transferring files between your Linux box and your Android device

There are a few ways to share files over wifi between your Linux machine and your Android device. The first method I used was to set up a web server on my CentOS box and then browse to it on the Android. This wasn't an ideal solution for a number of reasons, one being that the transfer worked in only one direction (from the web server to the Android) and the second being it was a solution too complicated for most Android users.

The second solution was much better, an app (free) at play.google.com called Software Data Cable. It's essentially an ftp server that runs on Android (version 2.1 and above— it was nice of the developers to backport it). Once installed, you simply start it running and then you can transfer files back and forth between your Android and Linux over wifi. Software Data Cable allows you to configure a password to access the server. Still I still don't leave it running all the time due to security concerns. It's simple enough just to fire it up when needed.

On the Linux side, open up two nautilus windows, one being Panel -> Places -> Network Places -> your Android's IP address, the other being your Home directory or Desktop or whatever. Then you can transfer files back and forth just by dragging and dropping them from one window into the other— in either direction. I've also found Software Data Cable to be the easiest way to rename files on Android: Right-click on the filename, select Rename, and type in the new name. If, in this process, Android gets confused about the contents of a local directory, on Android exit that directory to its parent, then go back into it. This seems to force a reread of the directory contents, bringing the cosmos back to sanity.

It would be nice to be able to use Software Data Cable to set up a file server for a group of people. In a sense, it already does this except, with no limits on who could download what, people can access files and/or directories everywhere, including your confidential information. A proper ftp server would institute limits on which users could access which files and directories. Perhaps we'll see this further development in future.

Tuesday, August 17, 2010

Which Printers Work on Linux?

It's a perennial question: Will this or that piece of hardware or peripheral work on Linux? (This is a question best asked before making the purchase.) In the case of printers, it's pretty easy to answer. You just have to know what to ask... not whom, but rather what.

The place to ask is CUPS. It's the standard print server for Linux and used on other OSs also. Most Linux distros install it by default. To find out if you have it, go to your favorite browser and type in the URL http://127.0.0.1:631/admin (and then bookmark it). If you get an error page from this, perhaps CUPS isn't running on your system. Check that by running service cups status as root. If that command tells you that CUPS is "stopped", then start it up with service cups start. Or, if it says "unrecognized service", then CUPS isn't installed. So install it. You'll need it.

Given that CUPS is installed and running, you should be prompted for a username and password. After entering those, click on Add Printer, enter "test" or whatever you want in the "Name:" field. Skip the "Location:" and "Description:" fields, and click Continue. On the next screen, it doesn't matter what you specify for "Device:" because eventually we're going to cancel out of this printer setup anyway. So just click on Continue again. You can't do the same on the next screen where it asks for the "Device URI"; "socket" won't work, so enter http://hostname:631/ipp/ and click Continue once more.

This gets us to the web page we actually want, a listing of various printer brands, or as the page says, the "Make" of the printer. Scroll down and select the printer you're curious about. And, yes, once again you'll click Continue. The next page to come up asks you for the "Model" of the printer. If you find the model of your printer listed, then CUPS supports it. Otherwise it doesn't, at least not yet... at least not for the version of CUPS you have installed. Once you're done looking, just click on the "Administration" tab at the top or close the web page and all the info you've entered will be discarded. If you inadvertantly click on "Add Printer", click on the "Printers" tab, find the printer you wrongly added, and then delete it.

If you found the printer in question isn't listed in CUPS, there's a few other avenues to try. First, check www.cups.org/ to see if there's a version of cups more recent than yours which might include support for your printer. Alternatively, sometimes a well known or major printer manufacturer will job out the manufacturing of a printer to an unknown printer manufacturer. If the brand of your printer is not listed in CUPS but you know the make and model it sells under from the major brand, then of course you can try configuring that. Finally, you might track down the printer manufacturer and ask them about, or search their website for, a CUPS driver. If they don't have one, let them know that Linux is here to stay and go shopping for a supported printer. Hewlett-Packard (HP) has been onboard with Linux for a long time and has an extensive list of HP-supported printers.

Sunday, August 08, 2010

Retrieve and Edit a Web Page in Emacs

While browsing the web, I often find a web page I want to save locally. As often as not, I'll want to do some editing on it. Of course Firefox and other browsers allow me to save a web page as a local file. And, yes, I could then pull the local file into emacs (what I use most often for editing web pages) and do whatever editing I wish. But I go through this routine often enough that I'd like a faster and more streamlined method. This is a computer, after all. And using open source software, I don't have to settle for just those capabilities that are built in to the software. If there's some functionality that I need and I can write the code for it, open source allows me to add functionality to what's already provided out of the box. Of course, once you start programming, it's just too tempting to add on another little feature... and then another... and then— why not?— another one.

One of two such add-ons had to do with text files created by an application on a Microsoft™ system. Such files commonly contain a Control-M character at the end of each line. On Linux and UNIX systems this appears as a ^M. It's part of the carriage return and linefeed pair of characters used in Microsoft™ files since the first days of DOS™. UNIX and Linux systems use just a ^J instead, so all the ^M characters at the end of every line are without purpose and just a nuisance. It's always a couple extra steps to remove all these characters, so I decided to insert a little extra bit of code to wipe out all of them automatically as soon as the file is loaded into emacs.

Another feature I wanted was the inclusion of citation. That is, when I download a web page, I want to save the URL where the web page came from— this in the event I want to cite the source of the web page (as is done in academic work) or if, later, I want to go back to the same website again to see what else they might have. So the code below automatically inserts the web address as well.

So, to review in brief, here's what this code does:

  1. Fetches a web page. You're prompted for the web address in the minibuffer.
  2. Strips out the ^M characters. If you're using Windows™, you might want to remove, or just comment out, the two lines of code for that.
  3. Inserts a paragraph containing the URL of the source web page. This paragraph is inserted at the top of the web page. You can change the location by replacing my re-search-forward search string with something which works for you. In a Linux or UNIX shell, do info elisp "Regular Expressions" for documentation.
;url-fetch-web-page ;From within emacs, download & locally edit a remote web page. ;Copyright (c) 2010, Kenneth Fisler, Cleveland, Ohio, USA. ;This program is free software; you can redistribute it and/or ;modify it under the terms of the GNU General Public License :as published by the Free Software Foundation; either version 2 :of the License, or (at your option) any later version. ; ;This program is distributed in the hope that it will be useful, ;but WITHOUT ANY WARRANTY; without even the implied warranty of ;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;GNU General Public License for more details. ; ;You should have received a copy of the GNU General Public ;License along with this program; if not, write to the Free ;Software Foundation, Inc., 59 Temple Place, Suite 330, ;Boston, MA 02111-1307 USA ;Using the url.el library, so probably need to load it. (require 'url) (defun url-fetch-web-page (url) "Retrieve minibuffer-specified web page, load into a new buffer, then call another function for editing." (interactive "sLoad URL: ") (with-temp-buffer (url-retrieve url 'edit-web-page (list url 'status)))) (defun edit-web-page (&optional redirect url status) "Switch to the buffer returned by `url-retrieve'. Automatically strip out all C-m characters and then insert after html body tag the buffer's URL, appropriately html-tagged." (switch-to-buffer (current-buffer)) ;; remove all instances of ^M (found in MS-created files). (goto-char 0) (perform-replace " " "" nil nil nil t nil nil nil) (let ((case-fold-search t)) ;case-insensitive search (goto-char 0) ;go to top of buffer (re-search-forward "<[\t\n ]*BODY[^>]*>" nil t) ) ;insert URL into page (insert "\n\n<p>From: <a href=\"" url "\">" url "</a>\n </p>\n\n"))

In the first function, interactive, prompts for the URL of the web page you want. The url-retrieve function then fetches that web page, puts it in a buffer created by the with-temp-buffer function, and calls the second function, edit-web-page, function for further processing.

The edit-web-page function, given the text of the web page from the first function, invokes switch-to-buffer to display it, then places the mark at the top of the buffer with goto-char 0. Then re-search-forward searches for any ^M (Control-M) characters and deletes them. (More precisely, each ^M is replaced by a one-character vacuum.) This function also gives a count of those "replacements" in the minibuffer.

The last four lines of code set the variable case-fold-search for a case-insensitive search, put the mark to the top of the buffer (again), then find the HTML <body> tag. Finding this tag places the mark at the end of that tag, which is where the HTML code displaying the URL is inserted. (Many thanks to Denny on the gnu-emacs-help mailing list for coming up with the search string for locating the HTML body tag with all its imaginable variations and combinations.)

Note that the code above does not save the buffer. You have to do that yourself manually. Or you can add code to do it if you want. I left this out by design so I could examine, and even edit the buffer first and then decide where I wanted to save it. Or, if I decided I didn't want to save it at all, I could just kill it. Again, as this code is open source, you're free to add code to automatically save the fetched buffer to a file.

There are a lot of other ways this code could be altered or rewritten for other purposes. For example, when a web page is fetched, along with the actual HTML code, some output from the web server shows up at the top of the buffer. I could have written code to automatically delete these several lines of text. But I find that information interesting, so I left it in. You may prefer not to ever see it. Or, this might be precisely the information you happen to be looking for, the HTML being of no interest. A little hacking of the above could accomplish either purpose.

Many other purposes are possible, especially if we consider that the specified URL can use internet protocols other than http. What's nice about the modular structure of the above code is that any function which works on an emacs buffer can, with little modification, be executed on any emission from any accessible URL. In effect, this code is a tool loosely coupled with a working example. So it's very much an invitation too.