Posts Tagged 'Linux'

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”:

#!/bin/sh
mv ~/Pictures/Webcam/*.jpg ~/Pictures/Webcam/2016backup
mv ~/Pictures/Webcam/*.png ~/Pictures/Webcam/2016backup
cheese
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">
 <vbox>
 <hbox>
 <vbox>
 <hbox>
 <button>
 <label>"Cheese"</label>
 <input file>"/usr/share/icons/Moka/64x64/apps/cheese.png"</input>
 <action>mycheesyphotoboothscript</action>
 </button>
 </hbox>
 </vbox>
 <vbox>
 <hbox>
 <button>
 <label>"Close"</label>
 <input file>"/usr/share/icons/Moka/64x64/actions/exit.png"</input>
 <action>EXIT:close</action>
 </button>
 </hbox>
 </vbox>
 </hbox>
 </vbox>
</window>
'
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
Exec=/home/ed/Programs/MyBinaries/PhotoBooth
Icon=/home/ed/.local/share/icons/Moka/64x64/apps/cheese.png
Terminal=false
Type=Application
Categories=Graphics;
StartupNotify=true
MimeType=application/x-ms-dos-executable
NoDisplay=false

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).

Kodi-fying an old computer

(Here’s 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.)

A friend came over to my home and saw my living room Linux computer set up to play media: movies, music, pictures, that kind of thing. He asked how it was done, and I mentioned the program KODI as the media server I was using. He was impressed, and asked if I could convert an old computer (or three) that he had to do the same thing.

“Of course!” I replied, with a far too inflated view of my own competence.

So, a few days ago, he dropped off the two computers he could find. Once was an eMachine AMD 2650e, with 1GB of RAM running Windows XP. The other was a Dell tower, with 512MB of RAM running Windows 7. (Don’t ask me how.)

I tackled the eMachine first. Getting the latest version of Lubuntu Long Term Support version was a matter of using the alternate install iso, burned to a USB. Nothing out of the ordinary to set it up: I installed the bare minimum I could, added just the packages I wanted to install a **very** minimal desktop (jwm, if anyone’s curious), and rebooted.

The challenge came in when my friend wanted his NTFS external USB 3.0 drive to be recognized. It’s got a lot of his media on it, and he wanted it available for his Kodi use. But it was NOT as easy as just plugging in the drive. (And here’s where I’m posting stuff for my own remembrance, and you, good reader, will probably have your eyes roll back in your head. Sorry.)

After MUCH experimentation, I had to add an entry into /etc/fstab that read:

UUID=<his identifier> /home/hismountpoint ntfs-3g nofail,x-systemd.automount,x-systemd.device-timeout=1 0 0

And that made the drive viewable by Kodi after I got it to start. (I also did an autologin for Kodi, but I won’t post that info here: it’s available by Google search. Just remember that now that Ubuntu is using systemd, I had to created a kodi.service which launched an xinit session. I warned you that your eyes would roll back, didn’t I?)

All is hunky-dory, right? Well, the eMachine was a 64bit computer… and the Dell was a 32bit computer that wouldn’t boot correctly from the USB stick, no matter what I tried. I had to old-school burn a DVD with a 32bit alternate install iso, and once that booted, I chose the expert install option, to replicate the same packages I selected for the first machine.

But the Dell would NOT recognize this drive upon boot, even when I copied the /etc/fstab word-for-word from the eMachine. It kept hanging: my guess is, it didn’t like the USB 3.0. SO… I created this kludgy workaround in the .xinitrc file:

.xinitrc:
dbus-launch Thunar
xmessage -center -geometry 300x120+0+0 "Attach external drive now"
sleep 30
pulseaudio &
killall Thunar
kodi &
exec jwm

And THAT allowed me to boot up, and step by step plug in the external USB drive so that Kodi could recognize it and use it.

how-to-download-and-use-kodi-addons-1

Digitizing Media with Linux

Hello, faithful readers – all two of you –

Be warned that this is another Linux post, intended for me to keep track of a task I’ve done, so if I need to repeat it, I don’t have to reinvent the wheel from scratch.

Today’s task: to record video from my old VCR into my computer.

If you wanted to do this on your own Linux computer, you’d need:

  • a computer
  • a video capture card
  • a vcr
  • wires to hook everything together

Specifically, you’d need to make sure that your vcr output is going into the video capture card’s input. On my setup, I’m using a pcHDTV 3000 card, and I’m using the composite input. That’s considered “input 1” in the code below.

I’m using Mencoder to record the video, as I like the settings it has: I get a good balance of quality video and size with the setting below.

#!/bin/bash

export MAIN_DIALOG='
  <window title="MyDVR" icon-name="gtk-preferences" resizable="true" decorated="true" width_request="320">
 <vbox>
  <hbox>
    <text>
      <label>Time to record (hh:mm:ss):</label>
    </text>
    <entry activates_default="true">
      <default>00:00:05</default>
      <variable>ENTRY1</variable>
    </entry>
  </hbox>

  <hbox>
    <text>
      <label>Name of recording:</label>
    </text>
    <entry editable="false">
      <default>MyMovie</default>
      <variable>ENTRY2</variable>
    </entry>
  </hbox>

  <hbox>
      <button>
        <label>Record!</label>
        <action>xterm -e mencoder tv:// -tv driver=v4l2:device=/dev/video0:norm=NTSC:input=1:width=720:height=480:audiorate=44100:alsa:adevice=hw.0:brightness=17:contrast=0:hue=0:saturation=0 -oac copy -ovc lavc -noskip -quiet -vf crop=720:460:0:20 -vf yadif=0.5 -lavcopts vcodec=mpeg4:vbitrate=3000 -endpos $ENTRY1 -o  "$ENTRY2.mp4"</action> 
        <action type="exit">OK</action>
      </button>
      <button>
        <label>Cancel</label>
        <action type="exit">Exit</action>
      </button>
    </hbox>
  
 </vbox>
</window>'

gtkdialog --program=MAIN_DIALOG

So, this may not have been the most interesting post I’ve ever written, but I’m putting it up here so I can refer to it later if need be. Thanks for your patience, readers!

My Daily Bible Reading, automated

Bible and glasses

Readers, be warned: this is one of those geeky posts of mine. I basically put these up to remind myself how I did something.

One thing I’ve noticed is that I tend to be much more intentional about reading what shows up on my computer screen than I am in reading a physical book. Everything I want to read (almost) can be found at my fingertips through the internet.

Now, like some of you, I have tweaked the settings in my browser so that the tabs to which I always need access are set to open as default. And I thought how neat it would be to create a script that would take my daily bible readings, and put them into a webpage so that I would read the text as I start my day.

The challenges:

  1. To insert the text according to my preferred reading plan (by Grant Horner, found here).
  2. To set up a web page for each day of the year with that day’s readings.
  3. To serve each day’s webpage to my browser.

Here’s how I did it.

To set up the text the way I wanted, I wrote a script using the excellent tool “diatheke”. It’s a command-line tool that comes with my bible program (Xiphos, in case anyone is wondering). Diatheke allows me to search and select Bibles for verses (or topics, or phrases), and use the results of that search in lots of interesting ways. I won’t show you the whole script, but I will show you a line of the file, and explain what it does.

diatheke -b ESV -f HTML -k Matthew 1, Genesis 1, Romans 1, Job 1, Psalm 1, James 1, 1 Samuel 1, Isaiah 1, Acts 1, Proverbs 1 > biblechapter1.html

“diatheke” is the name of the program. “-b ESV” selects the version to read. “-f HTML” selects the format that will create a webpage. “-k Matthew 1, Genesis 1, etc.” selects each chapter of each book I want to read. And finally “> biblechapter1.html” puts all of the gathered information into a single webpage (called biblechapter1.html”).

The script does this 365 times, with the different chapters that I want. After running it, I now have 365 little webpages with just the text of Scripture for that day of the year.

INSERT EDIT: After having used this for a few days, I noticed that the version of diatheke has an annoying little bug in it: it appends the last verse of whatever the search terms as an extra line. I wanted to get rid of this extra appendage, and I used the following command to do it.

sed -i “s/^: .*/<br>/g” biblechapter*.html

“sed” is the Stream EDitor program on most Linux systems, and with the input -i, the specific command s/ switches every line that starts with a colon and a space ^: , no matter what comes behind it .* with an HTML carriage break <br>, and does so globally /g for every file that starts with the name biblechapter, and ends with .html.

Finally, I wrote a little “home page” file that would select a different Biblechapter page depending upon the day of the year. This one page has a script that calculates the day of the year, and then serves that numbered biblechapter file to my browser. Here’s what that file looks like, shortened for readability:

<html>
  <body>
<script type="text/javascript">

var ie=document.all
var doy=document.getElementById

//How will the IFRAME be displayed?
var iframeprops='width=1400 height=6000 marginwidth="0" marginheight="0" hspace="0" vspace="0" frameborder="0" scrolling="yes"'

//Show all days of the year
var daycontent=new Array()
daycontent[1]="biblechapter1.html"
daycontent[2]="biblechapter2.html"
.
.
.   all the way through the whole year, 1 - 365
.
.
daycontent[364]="biblechapter364.html"
daycontent[365]="biblechapter365.html"

if (ie||doy)
document.write('<a href=""></a>')

var now = new Date();
var start = new Date(now.getFullYear(), 0, 0);
var diff = now - start;
var oneDay = 1000 * 60 * 60 * 24;
var mytoday = Math.floor(diff / oneDay);

function dayofyear_iframe(){
if (ie||doy){
var iframeobj=document.getElementById? document.getElementById("dynstuff") : document.all.dynstuff
iframeobj.src=daycontent[mytoday]
}
}

window.onload=dayofyear_iframe

</script>  </body>
</html>

Once that was working, I simply had to tell my browser (Chrome) to open three tabs every time it started: my calendar, my email, and my Bible reading for the day.

Well, that’s what works for me. Are you using some kind of system or specific discipline to keep you in the Word… and the Word in you?

Personal Linux Notes

Occasionally, I’m going to post notes to myself on this blog, just so I’ll have a place to look for not-frequently-needed-but-still-needed notes that does NOT reside on my computer.

This is a post to help remind me how to get surround sound working on my HP Envy 7 laptop with Ubuntu.

Step 1: Install the alsa-tools-gui package from the regular archive.
 Step 2: Start "hdajackretask"
 Step 3: Select the IDT 92HD91BXX codec (may be different on other models)
 Step 4: Check the "Show unconnected pins" box (the internal speakers do not show as connected)
 Step 5: Remap 0x0d (Internal Speaker, Front side) to "Internal speaker"
 Step 6: Remap 0x0f ("Not connected" but is the under-display speakers) to "Internal speaker"
 Step 7: Remap 0x10 ("Not connected" but is the subwoofer) to "Internal speaker (LFE)"
 Step 8: echo autospawn = no >> ~/.pulse/client.conf
 Step 9: sudo killall pulseaudio
 Step 10: sudo fuser -v /dev/snd/* (to check to see if Pulseaudio is still going)
 Step 11: Apply now, then test with your favorite audio program (some may not work due to Pulse reset, so find one that does, verify sound is coming from all speakers).
 Step 12: If it works, select "Install boot override" to save the settings to apply at boot time.
 Step 13: pulseaudio -D
 Step 14: Reboot. When it comes back, you should have full sound from all speakers. Also test headphones. Plugging in headphones should disable sound from all internal speakers.

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">
 <vbox>
  <text><label>What NIV Scripture do you want?</label></text>
   <entry activates_default="true">
    <default>John 3:16</default>
     <variable>ENTRY</variable>
      <action>diatheke -b NIV -k $ENTRY | sed "s/^:.*//g" | sed "/^(NIV)/d" | xclip -selection c</action>	   
    </entry>
   <hbox>
    <button can-default="true" has-default="true" use-stock="true"></button>
   </hbox>
  </vbox>
</window>'

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.

Sub NIV
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.)

((mostly))

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.

VirtualBox.

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:

#!/bin/sh
#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 http://www.sitepoint.com/virtualbox-branched-snapshots-tutorial/ and http://www.virtualbox.org/manual/ch08.html#idp58552576


Pastor Ed Backell

Flickr Photos

Pastoral Tweets

  • Check out this photo of Pho Yelm Restaurant on #Yelp yelp.com/biz_photos/pho… 2 days ago
  • How Does God Show Us He Loves Us? God Brings Us Into His Family (Romans 8:14-16) 4 days ago
  • God chooses US, just like He chose Jacob. He calls us His own; we belong to God, and there’s nothing we can do to break God’s promise to us. 4 days ago
  • How Does God Show Us He Loves Us? God’s Plans Change Us (Genesis 28:16-19) 4 days ago
  • How Does God Show Us He Loves Us? God Has Plans For Us (Genesis 28:10-15) 4 days ago

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

Join 774 other followers


%d bloggers like this: