Geek-Tips

Didactic musings on assorted geekery

BASH Pushover Notifications

A few days ago, I started a process that involves very heavy file processing operations that take anywhere from 10 minutes on the low side to 30 minutes on the high side. Wanting to be as efficient as possible and not let the computer sit idle for any meaningful length of time, and since the range of time varies so widely, I found myself wandering back to my computer every few minutes to see how things were progressing. After a day of this I became very frustrated and since I expect this to be a fairly extended activity, I decided to set up a system to notify me when the operations were complete so I could go about my business without wondering about the current operation status.

Planning

The file processing exercise itself leverages a GTK based GUI tool but does not provide any kind of mechanism for notifications such as Growl. The processing tool is open source, so I could try to build my own hooks into the tool, but I’m all about finding an easy solution. I’m always more comfortable at the command line anyway, so I decided that a simple BASH script was the best solution for my needs.

The workflow for each file is as follows:

  1. load file into my GUI program
  2. set parameters, including output filename
  3. initiate processing operation

Once this is complete, my thought was to then jump to my terminal window and simply execute my script and pass the output file defined above as a parameter – EASY!

Build the script

In order to write the script open your terminal and navigate to your home directory and fire up vim or nano and follow along.

#!/bin/bash

MESSAGE=$1
while [ $(( $(date +%s) - $(stat -c %Y FILENAME) )) -lt 10 ]; /
   do sleep 1; done; echo DONE

Line 3 captures the filename parameter that’s passed in on the command line. Line 4 is where the magic of this script occurs. Since my file processing routine updates its output file in real-time, the modification date for that file is constantly updated. The loop we see in line 4 checks that modification date and stays at this point in the script until it sees a 10 second gap between the current time and the last time the file was updated. Once that condition is met, we can safely assume that the file processing operation is complete.

TITLE="Job Complete"
APP_TOKEN="1234567890abcdefhijklmnopqrstu"
USER_TOKEN="0987654321utsrqponmlkjihfedcba"

curl -s -F "token=$APP_TOKEN" /
   -F "user=$USER_TOKEN" /
   -F "title=$TITLE" /
   -F "message=$MESSAGE" https://api.pushover.net/1/messages.json

The remainder of the script is the code required to send a notification to my phone via Pushover. If you’re reading this post, I assume you’re familiar with Pushover, so I won’t delve into the details. If you’re not familiar with the service, you can read more about it at their website.

Now same the script as notify.sh and run the following command:

chmod +x notify.sh

Wrapping it up

Now that we have our monitoring script, we can extend our workflow as follows:

  1. load file into my GUI program
  2. set parameters, including output filename
  3. initiate processing operation
  4. open a terminal
  5. run the following command – ./notify.sh /path/to/filename.xxx

Until next time – GEEK OUT!

~GT~

Dim Bulb Tester

WARNING: This post involves live mains electricity and is EXTREMELY DANGEROUS! Do not attempt this project on your own unless you are qualified to do so. I advise you to engage a licensed electrician to help you build this test unit!

Most of my electronics projects involve modern devices that require low voltage DC and minimal current. Occasionally I take on a project that involves high voltages, but these usually involve new components which run little to no risk of internal faults that involve dead shorts. This all changed when, in a moment of nostalgia, I bought an old Marantz Stereo Receiver off of eBay. I knew from the description that the unit was “dead” and when I received it and broke open the case, I could see that there were indeed indications of serious problems. After performing diagnostics and making a number of repairs (capacitors, transistors and fuses), I was ready to conduct a test to see if the unit was working. The proper way to do this would be to have an isolation transformer and a variac and to slowly bring up the power to make sure there were no shorts. Since I don’t do enough of these types of projects I thought it might be nice to build myself a Dim Bulb Tester instead.

A Dim Bulb Tester is a very simple device that puts an incandescent light bulb in series with power running into an unknown device which acts as a current draw if there is a short in the device being tested. Not only is it really simple to build, it’s a rock solid way to safely test “new” old gear without fear of doing damage in the event that there is a problem.

I wanted to keep the tester as simple as possible. I wanted one dual outlet receptacle with one socket used for the bulb load and the other socket serving up power to my test load. I also wanted a switch to make it really easy to prepare my tests and to kill power in a hurry if needed.

Dim Bulb Tester Circuit
Dim Bulb Tester Circuit

After purchasing my parts, the first thing I did was cut the tabs between the neutral and hot connections on each side of the duplex receptacle. This allows each socket to function independently and is critical to this particular circuit design.

The next step involves wiring up the circuit. Even though the power in our homes is AC, most people don’t realize that that power is polarized. In other words, one lead is hot and the other is neutral. For safety reasons, we want to make sure we pay attention to how we hook these leads up in our circuit. This is particularly important when using a unit like this to test old electronic devices that use hot chassises such as All American Five radios and vintage TV sets. Wiring the circuit is very straightforward. Simply run the hot wire through the switch, through the bulb socket and then to the hot side of the load socket of our receptacle. Then connect the mains neutral to the neutral side of the load socket and, last, but not least, connect the ground to the duplex unit.

At this point, your Dim Bulb Tester is fully functional. Plug the unit into mains power and plug in a test load such as a lamp or radio. If you wired it up correctly, simply turn on the switch and the load should power up normally and the bulb will stay off. Now short the load socket (WARNING: Exercise EXTREME CAUTION!!!! DO NOT perform this test unless you know what you are doing! This is extremely dangerous!) and the bulb should light up.

It’s important to note that the incandescent light bulb you choose for your unit is important. First and foremost, the lower the impedance of your bulb the better. Secondly, the wattage of your bulb matters. If you’re goal is to test old HiFi gear from the 70s and 80s then a 40 watt bulb should be just fine. If you get into older vintage gear, here’s a guide that might help:

  • 25 – 40 Watts = All American 5 Radio
  • 40 – 75 Watts = 6 Tube w/Transformer
  • 75 – 150 Watts = TV
  • 200 – 350 Watts = Color TV

That’s it; so simple, yet so ingenious! Following are some images of my build.
 

Dim Bulb Tester Parts
Dim Bulb Tester Parts
Dim Bulb Tester Wiring
Dim Bulb Tester Wiring
Dim Bulb Tester Wiring Pt2
Dim Bulb Tester Wiring Pt2
Dim Bulb Tester Wiring Pt3
Dim Bulb Tester Wiring Pt3
Dim Bulb Tester Complete
Dim Bulb Tester Complete
Dim Bulb Tester Shorted
Dim Bulb Tester Shorted

Until next time – GEEK OUT!

~GT~

Evernote, Wine and Xubuntu Linux

When it comes to Linux, the best desktop note taking tool, in my opinion, is Zim Wiki. I love this tool and have used it for a long time. That said, the 800 pound gorilla of note taking tools is Evernote, but unless you want to use the web client, your options on Linux are limited and not always so great.

There are a number of unofficial Linux based Evernote clients with one of the better options being Everpad. The problem with Everpad is that it lacks a built-in option for searching your notes. The good news here is that the standard Ubuntu user gets search capabilities for Everpad via an Everpad lens that integrates into Ubuntu’s Unity standard search. If you run a desktop with KDE then you can search via Krunner. If, like me, you run an Xfce based desktop, there’s no way to search your notes which makes Everpad a no-go option.

I played around with some of the other Linux client options, but I wasn’t fully satisfied with any of them. Rather than give up, I decided I would try installing the latest Windows client on my Xubuntu machine using Wine. After a bit of fiddling with the setup, I managed to get a fully functional and pleasant looking install on my Xfce based machine.

Following are the versions of the various pieces of software that I’m using in my installation:

Versions

  • Xubuntu 14.10
  • Xfce v4.10
  • Evernote 5.8.5.7193
  • Wine 1.7.38
  • Windows 7

Install Wine

The first step in this process is to install Wine. The latest stable version of Wine is 1.6.2 but I opted to go with the latest development release available in the ubuntu-wine ppa.

sudo add-apt-repository ppa:ubuntu-wine/ppa
sudo apt-get update
sudo apt-get install wine1.7 winetricks

Install Evernote

The next step in this process is to get your hands on a copy of the Evernote Windows client. If you try to download the client from your Linux machine Evernote will frustrate your attempts by looking at your User Agent information and presenting you with a screen that suggests you use the web client. The options for getting around this are:

  1. download a copy of the client from a Windows machine and copy to your Linux box via a thumbdrive, dropbox or other similar method
  2. use a browser plug-in that can change your user agent to something such as Internet Explorer 10

After you have your exe installer, right click on it and select open with “Wine Windows Program Loader”.

Evernote Installation
Evernote Installation

At this point you’re likely to see a number of system updates occur. Just be patient until the Evernote installation fires off. Once it does, just follow the directions until complete.

Now reboot your machine and proceed to the next step.

Tweaking Installation

While not a problem per se, I make it a practice to configure my Wine installations as Windows 7 since most modern software expects to be running on a modern operating system. To make this change do the following:

  • Navigate to “Wine”, under the menu system
  • Select “Configure Wine”
  • Select Windows 7 in the dropdown at the bottom of the screen
  • Click OK

If you start Evernote at this point you will likely encounter two issues:

  1. Ugly fonts
  2. Note Titles are missing

Fonts

On my installation, most of the fonts looked fine. My issue was with the fonts in the actual notes (far right side panel), they looked absolutely terrible. To fix the issue, I enabled subpixel rendering/anti-aliasing as follows:

wine regedit

Now let’s make some registry changes:

  • Navigate to HKEY_CURRENT_USER>Control Panel>Desktop and set (or create the key if it doesn’t exist)
  • FontSmoothing=2 (string key)
  • FontSmoothingType=00000002 (dword key)
  • FontSmoothingGamma=00000578 (dword key)
  • FontSmoothingOrientation=00000001 (dword key)

Titles

Even though you can’t see the title, it’s actually there. If you click into the title area and start typing, the title will change, but not being able to see it is annoying.

Evernote02

To fix this issue execute the following command:

winetricks -q riched20

Final Verdict

After these changes were made, my install looks perfect. I have yet to try more advanced functions such as annotating images, webcam note captures etc, but this installation covers my day-to-day note taking needs.

Working Version of Evernote Xubuntu 14.10
Working Version of Evernote Xubuntu 14.10

The one issue that I have noticed has nothing to do with functionality but is an aesthetic issue. When resizing the window the rendering stutters creating some ugly artifacts on the screen. The good news is that as soon as you stop moving the mouse, the artifacts disappear, so it’s nothing more than a minor nuisance.

Ugly screen artifacts
Ugly Screen Artifacts

There you have it; an Evernote client running on Linux with very minimal effort.

Until next time – GEEK OUT!

~GT~