Switching your monitor off remotely (linux, windows, and mac)

If you want to switch off your monitor from your command line in linux, there is an easy way:

sleep 1 && xset -display :0.0 dpms force off

What if you want to run this command remotely?

Here is my take on this question:
– use Python and Bottle to build a simple web server.
– use “/on” and “/off” pages to run command line scripts that switch the monitor on and off.

Let’s do this in Linux, Windows and Mac.


from bottle import route, run
import os
def off():
        os.system("xset -display :0.0 dpms force off")
        return "Screen is now off"
def on():
        os.system("xset -display :0.0 dpms force on")
        return "Screen is now on"
run(host='192.168.0.xxx', port=53535)

you just run this server in the background. If you need to switch the monitor off or on, just get any machine within the network and point its browser to these links:


To do the same in windows, you can use nircmd, a free utility, to switch off the screen.

To switch on the screen back, I’m using a simple autohotkey script, that just moves the mouse a bit:

MouseMove, 200, 100
MouseMove, 100, 100

Save the above two lines in a text file with the name mouse.ahk, in the same folder as the script below:

from bottle import route, run
import os
def off():
        os.system("nircmd.exe monitor off")
        return "Screen is now off"
def on():
        return "Screen is now on"
run(host='192.168.0.xxx', port=53535)

The command needs to be in your path (alternatively give it the full path of the nircmd binary).

with a bit of help from here, the script is as follows:

from bottle import route, run
import os
def off():
        os.system("pmset displaysleepnow")
        return "Screen is now off"
def on():
        os.system("caffeinate -u &")
        return "Screen is now on"
run(host='192.168.0.xxx', port=53535)

No security considerations taken into account here; we are assuming you are running this in a secure environment. Depending on your setup, you may have to use administrator/root privileges and make adjustments to your firewall.

The above is part of my IKEA mirror project. Some button combinations will be switching monitors on and off.

Hacking an IKEA mirror [part 5]

I needed a case for the RaspberryPi. The good thing about the RPi being a business card-sized computer is that it fits nicely in a plastic box from old business cards. If you look on Ebay, you can buy 20 of them for £5 including delivery.

The boxes make fantastic custom RPi cases! I didn’t spend too much time and effort in cutting these accurately, but the result is fine for the purpose. All the necessary ports are exposed and the GPio cables have a custom hole.

The board fits snuggly in the box, so I did not bother fixing it. A bit of bluetack was used to stick the plastic box on the metal frame.

Hacking an IKEA mirror [part 1]

In a recent trip to IKEA, I found an interesting and very “hackable ” item: the TYNSES mirror:

hackable mirror from IKEA

hackable mirror from IKEA

[link to IKEA]

I wasn’t really interested in the actual mirror. I was after the nice metal frame. I removed the mirror, which was held in place by 6 stickers and I’m planning on making it a panel on which I will add 8 buttons connected to a raspberry pi. Then the panel will be clamped on my desk, allowing me to run things by pressing a combination of the buttons.

The buttons will be at the bottom part, in two rows. I’m thinking of having an old Nexus at the top, as a mini screen connected to the Raspberry Pi.

I will post more on this later on, as I build it.

Python and PDF

Here is an example of how to merge the first pages of a number of pdf pages into a single file.

I wrote this script, because I needed to print the first page of 200 individual files and I didn’t really want to open each one manually…


import os.path, pyPdf
from os import walk
output = pyPdf.PdfFileWriter()
original = "c:\\original\\folder\\"
f = []
for (dirpath, dirnames, filenames) in walk(original): f.extend(filenames)
for eachfile in filenames: 
	ffile = original + "\\" + eachfile
	if "pdf" in eachfile:
		pdf = pyPdf.PdfFileReader(open(ffile, "rb"))
	print ffile
outputStream = open("c:\\out.pdf", "wb")

Raspberry Pi Samba Share

My RPi is the brain of my ARK-AV-01 robot. As I currently am in the programming phase, I found myself programming it from the command line. I wanted something easier, with no login/password, so I activated samba with the following samba.conf file:

workgroup = mygroup
interfaces = wlan
bind interfaces only = yes
server string = Arkadian's ARK-AV-01
security = share
guest account = nobody
log file = /var/log/samba.%m

comment = Robot Control Center
path = /robot/
available = yes
browseable = yes
public = yes
writable = yes
read only = no
guest ok = yes

The above configuration allows you to connect to the /robot/ folder from any windows or linux machine.

I had to also run the following commands

sudo chown nobody /robot


sudo chmod 777 /robot -R

to ensure the folder is owned by user nobody and is writable.

then, just restart the samba service:

sudo service samba restart

And now you can mount the folder /robot to your windows or linux machine!
if everything works ok, make sure to add samba to the startup script:

sudo update-rc.d samba defaults