Sunday, November 24, 2013

Makeshift DIY Youtube and Flash Video Player w/o Flash

This is a dirty hack for a video stream player. It's using youtube-dl, a script which can download videos from Youtube, as well as many other sites, including those graphic ones. We will have youtube-dl download a temporary file which is played with a 5 second delay in mplayer. The script is completely immature and probably won't properly kill processes and such, so you've been warned!

1. Deps

1.1. Install youtube-dl

 # wget https://yt-dl.org/downloads/2013.11.24.1/youtube-dl -O /usr/local/bin/youtube-dl  

 # chmod a+x /usr/local/bin/youtube-dl  


1.2. Install mplayer and Zenity

 # apt-get install mplayer zenity


2. The script

 #!/bin/bash  
 URL=`zenity --title "Dirty Youtube Player" --text "Please paste URL here: " --entry`  
 if [ -f ~/.utubetmp ]  
   then  
    rm ~/.utubetmp  
   else  
    mkfifo .utubetmp  
    youtube-dl $URL -o .utubetmp &  
    sleep 5 && mplayer .utubetmp && rm .utubetmp  
 fi  


I called the temp file .utubetmp and made it reside in your current user's home folder. It's also a hidden file.

You run the programme (I called it utube and put it in my ~/.bin), paste a video URL in this dialogue:



 
and eventually, you'll get a video after 5 seconds or a bit more...





There you go! You've got yourself a lovely Flash video player which actually should be using less resources than actual Flash and doesn't even require you to have Flash installed.

Bugs: Skipping ahead is possible only until the point youtube-dl has already downloaded, skipping back breaks MPlayer and it exits, pausing and resuming works though.



Wednesday, August 14, 2013

Screenshots in Window Managers with Zenity, Scrot and Gpicview


TECHNICAL UPDATE: Code snippets will be dark green from now on. I am still working on making proper code boxes with select all function and all the jazz.


There are a lot of dedicated screenshooters out there, some more advanced than others. I need something simple and want to facilitate it with the tools I already have on my machine or that need just a few more lean programmes.

scrot (HQ, deb)
zenity (HQ, deb)
gpicview (HQ, deb)

scrot is just a small screenshot wrapper around imlib2 and quite lean.

Why gpicview? It's my go to image viewer and it can save files. So, if you substitute this with something else, choose one that lets you easily save the picture, since the script will only save into /tmp and then delete the file immediately!

Basically, there are 2 ways of using this script. It will wait for a certain interval (I've set it to 3s) after which it will either make a screenshot of the whole screen, or, in the second mode where you call the script with the -w flag, you either click on a window you want, or draw a rubber band around the screen portion you want.
In both cases, a zenity window will pop up to warn or instruct you.
After that, gpicview will display the image. That's where you can actually save the picture by using the right click dialogue, as the temporary picture in /tmp will be deleted once you close gpicview!

The script proper:


 .  

   
 #!/bin/bash  
   
 NEW_FILE=screenshot__`date +%d-%b-%Y_%T`.png  
   
 case $1 in  
   
  -w)  
    zenity --title "Selective screenshot" --info --text "Please select a portion of the screen by holding down the left mouse button and drawing a rectangle, or just click on the window you would like a screenshot of." && scrot -s -d 3 /tmp/$NEW_FILE && gpicview /tmp/$NEW_FILE && rm /tmp/$NEW_FILE  
  ;;  
   
   *)  
    zenity --timeout 2 --title "Fullscreen screenshot" --info --text "Making a screenshot of your entire screen..."  
    scrot -d 3 /tmp/$NEW_FILE && gpicview /tmp/$NEW_FILE && rm /tmp/$NEW_FILE  
  ;;  
   
 esac  
   
 exit 0  
   



WARNING: Both bold parts in the script are 1 line and are only broken up here because of the blog!


I save the script as scrnw and call the command

scrnw

with the Print Screen button in case I need a full screen shot, or as

scrnw -w

with Alt-Print Screen in case I need just a portion of the screen or a window.
Here's a screenshot of the dialogue in this case:




That's it.

Sunday, August 11, 2013

Wallpapers and System Messages on the Desktop

Being that I use a plain window manager on my machine, the desktop root window is just displaying a calm wallpaper for me. In order to facilitate this, I use Nitrogen (cf. website, debian package). It gives me a GTK+ window with thumbnails of my wallpaper directory. I click on the wanted wallpaper, apply and am good to go.




In Openbox, I call Nitrogen via a key combo (I use SUPER + b, as in background) which runs this command:


 nitrogen --no-recurse --sort=alpha ~/Pictures/wallpapers  


--no-recurse tells nitrogen not to go into subdirectories, which is a smart thing to do considering that file managers make smaller thumbnails of the images and you usually have a hidden subdirectory with loads of tiny pictures you actually don't want to be your wallpaper.

--sort=alpha is sorting the images alphabetically. 
Other options: ralpha - reversed alphabetical order, time - according to modified time, rtime - same as time, but reversed.


Of course, Openbox doesn't know that I want to load a wallpaper at startup, so I put this command in my .xinitrc / .xsession (my .xsession is actually just a symlink to my .xinitrc).


 nitrogen --restore &  


An empty root window with a wallpaper gives me the perfect opportunity to have a sort of live display of my system logs. There is this nifty command tool called tail which lets you view the last 10 lines of a text file in the console, while always listening in and updating, so you always get the last log entries.
The same is available for the root window, but as a different programme called root-tail (website, deb).

I have this in my .xinitrc:

 root-tail -g 800x250+40+460 -font -misc-fixed-*-*-*-*-*-100-*-*-*-*-*-1 /var/log/messages  


-g stands for geometry.  This is the standard X stuff - the first 2 numbers are the width and height of the invisible text window in which to present the message. The other 2 numbers are the x and y coordinates on screen. Note that, as root-tail is essentially just console output, the coordinates are lines rather than pixels! You will have to experiment with this one to fit your needs and screen resolution. Mine is 1366x768. Refer to the man page for more.

-font is obvious. I have chosen an old X font without antialiasing (though I'm not even sure if trutype fonts with smoothing are even supported). This is the standard fixed width font and it works well for me.

The last bit is the log file in question. On Debian, I had to allow read access for /var/log/messages. This log shows events like USB keys being plugged in and such and hence is rather useful.





Fin. 

Tuesday, July 9, 2013

Desktop Friendly Standby, Hibernation, Shutdown and Reboot in Openbox Through Dbus and ConsoleKit

There are quick ways to to shutdown, reboot or put your computer into standby or hibernation in Linux if you have permission to do so. Openbox however does not come with a way of facilitating this and you're stuck with becoming superuser to do so. This is a way to do all this as a normal user.

Basically, we will do what all the desktop environments pretty much also do - we will ask ConsoleKit to handle the machine for us. As normal users, we cannot shutdown the machine ourselves, but we do have permission to instruct ConsoleKit to do it. You most probably won't need to install it, since a lot of desktop programmes on distros that still use dbus depend on it.
This still, for instance, works properly on Debian 7 Wheezy. Bear in mind however that ConsoleKit is not very actively maintained anymore with many distros slowly going over to systemd. If you're using this, then YMMV as to whether and how well this will work. I might tackle that in the future if I ever move to a systemd distro.

We will also need zenity for the dialogue scripts. This is what you'll be seeing as a user:



I have the scripts all assigned to key combos. For instance, CTRL + SUPER (or WIN) + x gives me shutdown, CTRL + SUPER + r is restart, the same but with an h instead would be hibernate and  an s would give me standby.
The combos are basically calling the following scripts that firstly give you an "Are you sure" kind of dialogue, so you can still opt out. Answering No cancels everything, answering Yes commits to running said action. Basically, you paste the scripts from here into a text editor, save it under

 .  

 ~/.bin/  


You then have to make the scripts executable.


1. Shutdown Script

 .  

 #!/bin/bash  
 zenity --question --text="Shutdown?"  
 if [ $? == 0 ]  
 then  
  dbus-send --system --print-reply --dest="org.freedesktop.ConsoleKit" /org/freedesktop/ConsoleKit/Manager org.freedesktop.ConsoleKit.Manager.Stop  
 else  
  exit  
 fi  


WARNING! The long command between then and else must be in one line! Otherwise it won't work. Sorry, but I am yet to devise a better means for showing code samples properly. :( Bear with me!


2. Reboot Script

 .  

 #!/bin/bash  
 zenity --question --text="Restart?"  
 if [ $? == 0 ]  
 then  
  dbus-send --system --print-reply --dest="org.freedesktop.ConsoleKit" /org/freedesktop/ConsoleKit/Manager org.freedesktop.ConsoleKit.Manager.Restart  
 else  
  exit  
 fi  


Again, the dbus command has to be all in 1 line!


3. Suspend

This command will be a bit different, but you can leave out the parts that differ here and that I put out of convenience.
I personally use tint2 as my panel. It had a bug and I'm not sure if that's fixed or not. I keep this workaround just the same. When I resume out of suspend or hibernate, tint2 will show the clock incorrectly at the date I had suspended or hibernated at, that is until it eventually refreshes. Now, if you turned of the machine hours ago, this can be a bit fatal. The command will thus kill all instances of tint2, suspend, and when it resumes, it will start tint2 again.

There is another workaround - resuming from either standby or hibernation will open the desktop without asking for a password. To prevent others from easily using my computer I have told the script to lock the screen right before shutting down.
I have used xtrlock, but am sure that other screen locking or screensaver tools can be used just as well. I prefer xtrlock for its simplicity.

 .  

 #!/bin/bash  
 zenity --question --text="Suspend?"  
 if [ $? == 0 ]  
 then  
  killall tint2 && xtrlock & dbus-send --system --print-reply --dest="org.freedesktop.UPower" /org/freedesktop/UPower org.freedesktop.UPower.Suspend && tint2  
 else  
  exit  
 fi  


Again, pay attention to the commands between then and else staying in 1 line!
The bold parts are the optional workarounds you can ignore.


4. Hibernate

Quite similar, the only thing that's different is the dbus command:

 .  

 #!/bin/bash  
 zenity --question --text="Hibernate?"  
 if [ $? == 0 ]  
 then  
  killall tint2 && xtrlock & dbus-send --system --print-reply --dest="org.freedesktop.UPower" /org/freedesktop/UPower org.freedesktop.UPower.Hibernate && tint2  
 else  
  exit  
 fi  



That's all.

Monday, July 1, 2013

Sound Volume Management Through Multimedia Keys in Openbox

My laptop has those multimedia keys which don't work automatically in Openbox. This is how I fix it. You can use the same method for LXDE, just take note of the different config file location.
A lot of the Openbox stuff I use is from here.

Open the Openbox main config file. Check here for a preliminary reading on how to edit the bugger. It's XML, so it looks like a mess, but if you use a nice editor that has coloured mark up, like vim or nano, it will be easier.
The standard location for the config file in Openbox should be:



 .  
 ~/.config/openbox/rc.xml  



and for LXDE:



 .  
 ~/.config/openbox/lxde-rc.xml  



In the section called
 <keyboard> 
 you can add all your keyboard shortcuts.
In most cases, the kernel will automatically recognise your multimedia key input. However, in some cases you might have to manually assign those keys. In case these instructions don't work, this might be the culprit. See here for more help.

Make sure that amixer is available on your machine (in Debian, that would be the package alsa-utils). Even though this is an ALSA utility, this works perfectly well with Pulseaudio, too.

We will add the following code so the Volume Up button works:



 .  
   <keybind key="XF86AudioRaiseVolume">  
    <action name="Execute">  
     <startupnotify>  
      <enabled>true</enabled>  
      <name>volumeup</name>  
     </startupnotify>  
     <command>amixer -c 0 set Master 2%+ unmute</command>  
    </action>  
   </keybind>  



I've rendered the amixer command in bold letters. I've also set the command to raise the volume by 2% each time I hit the key. If that is too finely grained for you, just pick a higher percentage.

Here's the same example for a command to lower the volume:



 .  
   <keybind key="XF86AudioLowerVolume">  
    <action name="Execute">  
     <startupnotify>  
      <enabled>true</enabled>  
      <name>volumedown</name>  
     </startupnotify>  
     <command>amixer -c 0 set Master 2%- unmute</command>  
    </action>  
   </keybind>  



The only difference here is a minus instead of a plus sign.
Finally, we need a way to mute/unmute sound.
There is a little issue here which makes unmuting the sound on Pulseaudio not work, which is why I will present 2 separate configurations for ALSA and Pulseaudio, respectively.  I've fixed this issue based on this post.
For ALSA:


 .  
   <keybind key="XF86AudioMute">  
    <action name="Execute">  
     <startupnotify>  
      <enabled>true</enabled>  
      <name>volumemute</name>  
     </startupnotify>  
     <command>amixer -c 0 set Master toggle</command>  
    </action>  
   </keybind>  



For Pulseaudio:



 .  
   <keybind key="XF86AudioMute">  
    <action name="Execute">  
     <startupnotify>  
      <enabled>true</enabled>  
      <name>volumemute</name>  
     </startupnotify>  
     <command>amixer -D pulse set Master 1+ toggle</command>  
    </action>  
   </keybind>  



I hope you get the idea behind all this. The multimedia keys mostly already have a certain denominator in X.org, making it easier to assign anything to these keys. You could use xev as described in the preliminary link above on the Arch Wiki to find out what the other keys have as denominators. You can thus set up the rest of the bunch, such as the calculator or the play/pause/skip buttons and you could assign any command to them you like.

However, there is just one issue with all this - we don't get any visual feedback as to whether anything is happening, since amixer is a command line programme run in the background.
Fortunately, there is a nifty tool from the Xfce desktop environment that only pulls in gstreamer and a few basic libs you have on any Linux installation anyway. The tool is called Xfce Volume Daemon. In Debian, the package is xfce4-volumed.
You have to run the command in your .xinitrc / .xsession or Openbox autostart file. Just put this among your other commands:



 .  
 xfce4-volumed &  



You will get a libnotify pop-up window that actually follows your GTK theme.
Of course, in order for this to work, you need a notification daemon. I suggest xfce4-notifyd. It even comes with a very nifty tool to customise the looks of the notification bubble:



 .  
 xfce4-notifyd-config &  



That's all.

Sunday, June 23, 2013

The Intro

Welcome to "That Deprecated Linux Machine", that little blog with snippets about milking the most out of your Linux desktop experience.
The snippets will be as concise as possible, since that way they will be easier to navigate as a quick reference and I will be more likely to write them in the first place.
The primary tenets of this blog are:

- using open-source software
- using Debian GNU/Linux (although a lot of the things can be used in other distributions)
- using the KISS principle as much as possible (this will even include some scripting (bash, perl, python) to facilitate a leaner automation experience and reduce the reliance on UI which in time may or may not be available or running smoothly on older systems)
- portability is not much of a goal on this site, but I always try to at least have inter-distro compatibility
- there won't be much hand-holding here, sorry. However, I make it a habit to give further reading by linking to key elements (a lot of those might be Debian specific wiki links for instance)

I hope this will be useful.


Some further preliminary reading - some of it frighteningly indoctrinating :P :


Open-source and Linux in general

"The Cathedral and the Bazaar" - Eric Steven Raymond


Debian GNU/Linux

- Debian FAQ
- The Debian Social Contract
- The very lovely Debian Wiki
- Debian Reference (A bit of an intermediate read which will teach you a wide range of skills, from package management to little admin scripts)