Focusing linux frame on x server in shell script

The SignagePlayer executable in my installation was located in /opt/SignagePlayer/bin/SignagePlayer

I replaced the actual executable with a script of mine which gets autostarted instead of the player.
I moved the actual executable of the player into a different file.
The script once started, starts the actual player (which is now called SignagePlayerApp) and then uses a linux program which is called "xdotool" that allows you to perform all kinds of different options on open windows using the shell.

the following retrieves the window id of the player window by its title, which is "Signage Player"

xdotool search --onlyvisible --name "Signage Player"

the id is stored in a variable, if the player was not yet launched (so the window did not exist when the "search" was run) the script waits 1 second and then tries again and again until it finally finds the window

then the following line is executed on the id of the window to give it focus and bring it in front of the gnome panel

xdotool windowactivate $windowId

the entire script can be found here:

#This script belongs into the signage player install directory
#ie /opt/SignagePlayer/bin

#start the player
sudo /opt/SignagePlayer/bin/SignagePlayerApp &
#wait for the window to spawn
while : ; do
windowId=`xdotool search --onlyvisible --name "Signage Player"`
if [ -n "$windowId" ]
#once spawned give it focus and exit the script
xdotool windowactivate $windowId
#if it is not yet spawned wait 1 sec until checking again
sleep 1

Controlling application frames (windows) in linux

Signage Player is a program created by MediaSignage which is available for free and allows the user to set up linux or windows pcs that display advertisement or other sorts of content in slideshows etc. The player launches after the pc does and starts displaying its campaign in fullscreen. If you use an older version of linux it will automatically remove the gnome-panel (the taskbar) if you selected that option during installation. If you did not select that option or are using a new linux version with a more recent gnome ui, the player will not remove the panel. If the panel is not removed the player will still launch in full screen but the panel will be visible. The player can be brought to the front by clicking the mouse once, but naturally in a real environment you want it to launch into proper fullscreen because nobody will be there to click anything. What's needed is a script solution that will automatically give focus to the player window (which is what happens when you click inside that window manually) so the player will be brought to the front and the gnome panel will become invisible.

Executing an action or a set of actions on files.

Sometimes, you want to execute specific commands on a set of files, or manipulate some files with the same commands. Eg: - rename all files in a directory with a specific filename scheme. - extract id tags information from mp3s etc.

Share files in a Linux Network

Sometimes you want to share files in linux via network. Windows has the file sharing mechanism since Windows 98 or so. Whats there on Linux.

use available tools provided by your Platform(Linux)

Linux provides a nice tool called ImageMagick. This tool makes converting images to pdfs very easy.
> convert rofl.jpg rofl.pdf
It can also convert recursively, eg: whole directory trees.

> convert *jpg foo.jpg


Wakeonlan + ssh + VNC

*) Check if your IP address is static. If not you should use a service like dyndns to find your home IP.
*) Install an alternative firmware on your router like DD-WRT.
*) Install the program wakeonlan and ssh on your router.
*) If your workstation is switched off you can now use ssh to open a shell on your router and run wakeonlan from there to boot the workstation.
*) For secure remote access to your workstation you can install ssh.
*) Choose an unused port on the router and forward it to the ssh-port on your workstation so you can access it from the outside.
*) ssh can also deal with graphical user interfaces but this is quite slow and needs quite a lot of bandwidth.
A better option is to install a VNC-server on the workstation and a VNC-client on the laptop. The connection can be tunneled through ssh so it is encrypted.


Remote access to workstation

Sometimes I am at the university and I need some files I got on my workstation at home or I need to run some software I do not have installed on my laptop. Therefore I would like to have a tool or a collection of tools to turn on my workstation remotely if it is switched off and to interact with it. I want to be able to access all files on it and transfer them to my laptop if needed or copy data from my laptop But sometimes it is also necessary to start a program on the workstation. Theses programs could be simple shell scripts or other command line tools but also software with a graphical user interface. The workstation is connected to a Wifi-Router that is always turned on. Security is import, no one else should be able to gain access or intercept the communication.

Password recovery

Last summer I got a bit paranoid and created a very strong password for my laptop. I used a random generator to create an extremely strong password and for safety reasons I did not write it down. After a few weeks of vacation I forgot of course the password. I could have reinstalled the operating system but I was not in the mood to search for and reinstall all the software that I had on my laptop. I just wanted to have full access again to do some updates. The laptop did not have any other operating system installed. It had an internal DVD-driver but I was not sure if it was working or were my bland DVDs were. The BIOS was resent enough to allow booting from a USB pen drive. I also had another PC with Linux on it available.

Getting image width and height in Linux

imagemagick is a linux command line tool with many options to manipulate image files.
It allows you to resize an image, change between image formats and also work with pdfs (converting pdfs to images and vice versa, split and merge pdfs etc.)

One of the tools that come with imagemagick is called identify, which produces an output like

Image: rose.jpg
Format: JPEG (Joint Photographic Experts Group JFIF format)
Class: DirectClass
Geometry: 70x46+0+0
Resolution: 72x72
Print size: 0.972222x0.638889
Units: PixelsPerInch
Type: TrueColor
Endianess: Undefined
Colorspace: RGB
Depth: 8-bit
Channel depth:
red: 8-bit
green: 8-bit
blue: 8-bit
Channel statistics:
min: 37 (0.145098)
max: 255 (1)
mean: 145.58 (0.5709)
standard deviation: 67.3195 (0.263998)

The "Geometry" line: Geometry: 70x46+0+0 contains the width x height, in this case 70x46 pixels, if you want to get the width "70" and height "46" without messing around with regexp you can use awk to do this in the following way

res=`identify -verbose $f | grep Geometry | awk '{print $2}' | awk -F+ '{print $1}'`
width=`echo $res | awk -Fx '{print $1}'`
height=`echo $res | awk -Fx '{print $2}'`

you first get the geometry line from the identify output using grep, then split it along white spaces getting "70x46+0+0", further you split that up along the + getting "70x46"

you then extract the width doing the exact same thing but splitting along the x and then getting the first element (the width) and the second (the height)

How to use LAN services over the Internet ?

Local Networks have many advantages when it comes to more complicated services like file sharing, remote desktop, network printer usage or NAS. Of course, I could use web space like DropBox, and there might be many other ways to make LAN services available over the internet. But what I am searching for, is an all built-in solution which is secure and easy to use. I want be able to connect several clients together for my LAN services. Not at least, LAN-Party’s without all the disadvantages due do local management and mobility are one of my expectations.


Subscribe to linux