Tuesday, August 27, 2013

How to change weather location in xmobar

Xmobar is the default bar of the xmonad Window Manager. It defaults to Glassgow, Scotland, as a little homage to the Glassgow Haskell Compiler, the compiler which xmonad was compiled in. However, for most users, Glassgow is not the city that we want to see displayed for our weather (if it is, you really did luck out with that one, huh?).

So, to change the location displayed, you just have to change four letters in you ~/.xmobarrc. You will see near the "commands" words "[ Run Weather "XXXX""

That four letter code is an ICAO code. The ICAO (International Civil Aviation Organization) provides information about where to look the weather up. Weather stations around the world use this as the standard for displaying local weather. Issue a google search for "ICAO [name of your town]" toget the code, and then replace the 4 letters between the quote with the ICAO you get. Restart xmobar, and the changes will take effect immediately.

To get my configuration, which defaults to Millville, New Jersey's airport, copy and paste this into a file in your home directory called .xmobarrc: (this is a good starting point if you don't have a file already, or you broke yours with hacks and tweaking)

Config { font = "-misc-fixed-*-*-*-*-10-*-*-*-*-*-*-*"
       , bgColor = "#0a0a0a"
       , fgColor = "#558e7d"
       , position = Bottom
       , lowerOnStart = False
       , commands = [ Run Weather "KMIV" ["-t","<station>: <tempF>F","-L","18","-H","25","--normal","green","--high","red","--low","lightblue"] 36000
                    , Run Network "eth0" ["-L","0","-H","32","--normal","green","--high","red"] 10
                    , Run Network "eth1" ["-L","0","-H","32","--normal","green","--high","red"] 10
                    , Run Cpu ["-L","3","-H","50","--normal","green","--high","red"] 10
                    , Run Memory ["-t","Mem: <usedratio>%"] 10
                    , Run Com "uname" ["-s","-r"] "" 36000
                    , Run Date "%a %b %_d %Y %H-> %l:%M:%S" "date" 10
       , sepChar = "%"
       , alignSep = "}{"
       , template = "%cpu% | %memory% | %eth0% - %eth1% }{ <fc=#ee9a00>%date%</fc>| %KMIV% | %uname%"

It is also available as a raw file on my github. These commands will install that file (ASSUMING YOU ARE IN YOUR HOME DIRECTORY):

rm .xmobarrc
wget https://raw.github.com/dymatic/dotfiles/master/xmobar/.xmobarrc

If you aren't in your home directory, this will work.

rm ~/.xmobarrc
wget https://raw.github.com/dymatic/dotfiles/master/xmobar/.xmobarrc -o ~/.xmobarrc

1 comment:

  1. I stumbled across this blogpost when searching for how to identify the code for my town. Thanks a lot!