Posts Tagged 'Ubuntu'

My little photobooth app for Linux

(Here’s yet another Linux entry that I’m posting to remind me of what I’ve done to solve a problem. If you’re a regular reader of my sermon blog, this entry might not make sense to you.)

outputEvery year our church hosts a Harvest Carnival for the neighborhood children on whichever Sunday night is closest to Halloween. We have a sit down meal for families, lots of carnival games, and more than enough candy to send any twelve diabetics into a coma. Fun times.

One of the events we offer is a photo booth, where the kids come and strike cheesy poses in their costumes, and then they get a photo strip for a souvenir. To RENT a photo booth that does this is expensive, and besides – we already OWN a computer and a printer. It must be a simple matter to set it up to fulfill that function, right?

Yes. So simple, in fact, that I forget to save the work that I’ve done on this year after year. I end up hacking this together FROM SCRATCH every year. No more. I’m saving my work here for future reference.

Since I use Linux, it’s a matter of gathering the tools, and figuring out how to chain them together to make them do what I want: to result in this filmstrip format shown here. That means I have to make sure I have the physical equipment as well as the software. Here’s the shopping list, as it were:

  • computer (using the church laptop)
  • printer (I normally use the color laser printer, but it wasn’t working: enter a cheap HP inkjet)
  • bright light (an old overhead projector works well here)
  • webcam (Logitech USB, not the one on the laptop)

And then there’s the software to pull it all together:

  • Cheese (webcam software)
  • ImageMagick (to manipulate the images taken)
  • gtkdialog (an old school graphic user interface scripting tool – to make it all pretty)

Now that I’ve got all those tools installed, I write three scripts to make them dance. The main script that does the work I call “mycheesyphotoboothscript”:

mv ~/Pictures/Webcam/*.jpg ~/Pictures/Webcam/2016backup
mv ~/Pictures/Webcam/*.png ~/Pictures/Webcam/2016backup
cd ~/Pictures/Webcam/
convert 2016*.jpg[400x400] -splice 0x10 -background "#ffffff" -append -crop -0+10 output.png
lpr -o fit-to-page -PHP_ENVY_4520 output.png

All of the photographs taken by Cheese are placed in the Pictures/Webcam subdirectory of my Home. So, the first two lines move any existing photos to a backup directory (~/Pictures/Webcam/2016backup).

Next, the Chesse program is started. I then aim the camera, turn on the lights, make funny faces to get good shots… and when I have three or four good shots, I **close** the Cheese program. That tells the script to do the NEXT commands, which is to move into the Pictures/Webcam directory.

Next, we CONVERT the existing pictures just taken into a single vertical strip named “output.png”.

Finally, we send that file to the printer with the LPR command, making sure it fits on the page.

When I use this program next year, I’ll have to change the printer name from HP_ENVY_4520 to whatever printer I’m using.

The other scripts are really just for housekeeping/ease of use. I create a pretty launcher script called “PhotoBooth”:

#! /bin/bash

export MAIN_DIALOG='
<window title="PictureBooth-O-Matic" icon-name="gtk-preferences" resizable="true" decorated="true">
 <input file>"/usr/share/icons/Moka/64x64/apps/cheese.png"</input>
 <input file>"/usr/share/icons/Moka/64x64/actions/exit.png"</input>
gtkdialog --program MAIN_DIALOG

Which gives me this: cheezy

And finally, to make sure I can FIND the program, I write a little launcher that makes it show up in my menus. In Linuxland, we call these .desktop files, and here’s the PhotoBooth.desktop file:

[Desktop Entry]
Name=Cheezy PhotoBooth
Comment=create photo booth strips

Hope that helps someone (and reminds me to NOT erase all this work so I don’t have to do this from scratch next year).

BASHing the Bible

Hello, readers. Before any of you get up in arms about the title of this post, relax, take a deep breath, and read on if you’re interested in inserting Scripture into documents, because that’s all this post is about.

The church I serve recently got a new laptop for my use (yay, thank you trustees!), and while it already had Windows 8 pre-installed, I carved out some space on the hard drive, and installed Linux, because that’s what I actually use.

So, that means a new installation for me. I *thought* I had transferred all of my favorite little tools and scripts that I put together from my old laptop, but apparently, I had forgotten a couple, including some BASH scripts that I used every single week in my sermon preparation. BASH means “Bourne Again SHell”, a scripting language for Linux and OSX (and yes, it’s also available on Windows). A script, for those of you who are Windows users, is like a batch file. You put a bunch of commands that you want run in sequence in it, and then just run that script. (Anyone remember AUTOEXEC.BAT?)

What I want to do is insert Scriptures into my text documents. How I’ve ended up doing this is by using a couple of tools, and chaining them together. This is done on an Ubuntu Linux system – your milage may vary. Frankly, I’m writing this post so that if I ever have to do this again, I won’t have to do it from scratch. Again.

Tools you’ll need:

  • diatheke – a command-line tool that uses the Crosswire Bible libraries. All of my Linux Bible programs are in this format, so this is what I use.
  • gtkdialog – a neat little tool that allows me to make fancy GUI front ends for scripts.
  • xclip – this command-line program allows me to specifically insert things from the command-line into the clipboard for use in GUI programs.

So, the workflow is this:

  1. Select the Bible references you want to use in your document.
  2. Tell the bible retrieval program (diatheke) which verses you want.
  3. Capture the results from the retrieval program in the clipboard.
  4. Paste the contents of the clipboard into your document.

If this seems a *lot* like ZipScript from the old WordSearch programs, you’ll know where I got the idea! Here’s the actual script itself.

#! /bin/bash

export MAIN_DIALOG='
<window title="Scripture Grab-O-Matic" icon-name="gtk-preferences" resizable="true" decorated="true" width_request="225">
  <text><label>What NIV Scripture do you want?</label></text>
   <entry activates_default="true">
    <default>John 3:16</default>
      <action>diatheke -b NIV -k $ENTRY | sed "s/^:.*//g" | sed "/^(NIV)/d" | xclip -selection c</action>	   
    <button can-default="true" has-default="true" use-stock="true"></button>

gtkdialog --program MAIN_DIALOG

UPDATE: in the middle of the action tag, there’s a couple of extra sed entries. These are placed here because diatheke keeps repeating the last line of whatever verses were requested. These sed commands remove the extra data, and the version label.

I don’t know if this will help anyone but me, but it’s a handy little script.

dialog box for Bible text

Scripture Grab-O-Matic dialog box

And here’s the code snippet that is inserted into Libreoffice. This simply calls a bash script to run. I made my script listed above executable, put it in my /usr/local/bin/ directory (where I put all my local stuff), and when I run the macro in Libreoffice, the bash script is launched.

Shell "bash -c NIV"
End Sub

Taming VirtualBox – or How I Learned To Love Launching Scripts

First off, let me say that I am an avid Linux user. I converted to using Linux as my main operating system in 2000, and I’ve never looked back. In fact, I’ll admit to being pretty smug about it for a long time, and if I’ve annoyed any of my long-time friends by snidely remarking about “upgrading” their Windows machines to Linux, I apologize.

(I wasn’t *wrong*, mind you… it really is an upgrade, but I apologize for the snide way I might have come across.)


ANYWAY, one of the things I’ve always been frustrated with is the very few programs that I really appreciate using which are not available on the Linux platform. As a minister, there are a couple of Bible programs that simply do not play nice with Linux. I have had some moderate success getting older versions of Windows bible programs to run in Linux using Wine, but as for the more highly integrated-with-internet-access offerings, I’ve had to resort to another trick.


For my non-geek readers, VirtualBox is a program which allows the user to create an operating system WITHIN an operating system. If you are running Windows, and you’d like to experiment with using a Linux app, you can create a virtual machine, and run Linux inside of that. I, of course, do the opposite – I run Linux full time, but for those Windows programs I just can’t live without, I run them in a virtual machine of Windows XP.

To clarify: my Bible applications are running on Windows XP *inside* of a virtual machine, which is actually a program running on my Linux box. Clear as mud, right?

Well, here’s the nifty part, as far as I’m concerned: I’ve found a way to set up a specific shortcut which allows me to specifically launch one particular program within WinXP inside of my virtual machine from my home system. I imagine a Windows user could do the opposite process and launch Linux programs like GIMP directly from their Start menu if they wanted. Here’s how it works on my system, assuming that a Linux user already has VirtualBox installed, with a WinXP virtual machine:

1) in virtualbox, start your virtual XP machine, and install whatever program you want to access. In my case, I installed two Bible programs, WORDsearch and Logos 4. Once everything was installed, I opened ONE of these programs, and set it up to be exactly how I wanted it to be when I access it (maximized window, resources that I knew I’d use already loaded, that kind of thing).

2) Once the program is running the way you want it, CLOSE the virtual machine (not within WinXP, but within the “Machine” menu of VirtualBox, and SAVE the MACHINE STATE. This means that the next time you start the virtual machine in VirtualBox, Windows XP will fire right up with your program already started and ready to go – no login, no boot up sequence, just the program.

3) Once complete, shut down the VM, return to the main VirtualBox window, and click the Snapshots tab. Highlight the Current State, then click the Take Snapshot icon and give it a name and description, e.g. “WORDSearch″.

4) Now, start your virtual machine from your saved snapshot (which will put you right back to where you left), and set up your NEXT program you want to use. Close the first one (I closed WORDsearch), and then start your next program (Logos 4, in my case), and get IT set up just how you want it. Once set up, then within the “Machine” menu of VirtualBox, and take a different snapshot. Give it a different name (in my case, Logos). You should now have two different snapshots, each with a different saved instance of Windows running the specific program you like.

5) The cool bit: you can directly from the command line access specific snapshots. It takes two commands:
> vboxmanage snapshot “YourVirtualMachineName” restore “YourSnaphotName”
> vboxmanage startvm “YourVirtualMachineName”

The first command tells VirtualBox to select the specific snapshot that you’ve named. In my case, it’s either WORDSearch or Logos. The second command tells VirtualBox to start using that specific snapshot. When you combine these two commands in one shell script (or batch file, for you Windows people), you can directly launch your virtual machine with your saved state with your preferred program already running. Here’s the script that I’m using:

#launcher for virtualbox logos4
vboxmanage snapshot "XtraPainfulToo" restore "Logos"
vboxmanage startvm "XtraPainfulToo"

I’ve saved this script, make it executable, and put in with all my other scripts.

6) Create a launcher which calls your script. Some of you might use a desktop icon launcher, or a .desktop file, or a keyboard shortcut. The end result is that you’ll need some way to launch this script. In the background, your computer will run the script, and the only thing you’ll see is your Windows program popping up on your Linux screen.

I hope that’s clear enough for you to start using this process. I have found it very helpful in my day-to-day use of WinXP programs inside of Linux, for those programs that I just can’t work without. Clarification for this process was found in articles at and

Pastor Ed Backell

Flickr Photos

Pastoral Tweets

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 230 other followers

%d bloggers like this: