Jacob Peddicord

Commandeer: Lock the display to run a command

| 1 Comment

Just to get this out of the way, I created this application this week as a Vala learning experience. It is by no means complete, but for the use cases I think it fits the bill nicely. Let's jump right in to those cases:

  1. Bill is a system administrator who needs to run a backup on the computers on the network, but employees can not be using them while this happens.
  2. Jane is running some important system operation and needs to make sure none of her friends use the computer.
  3. Bob wants to put his system on standby every night at 11 PM, but not if he is using it.

Enter Commandeer. It is a small application that is able to lock the display to run a command. Sounds simple, right? It is.

commandeer-example-backup

Commandeer allows commands to be started with a variety of options presented to whoever is currently using the computer. Commands may be optionally cancelled before they start, stopped and paused while running, and.. well that's all for the moment. Stopping and pausing are a little hacky; they just send SIGTERM, SIGSTOP, and SIGCONT to whatever child process is active. When the command starts, the above window becomes on-top, sticky, and fullscreen. Enough to keep out most users for now; hopefully I can improve on this "locking" support in the future.

For the first example: commandeer -d 60 --title "Backup" --text "Please save and close all work before the backup begins." /sbin/crazy-backup-plan. This would start a forced launch in 60 seconds.

The second: commandeer -d -1 important-command. A delay of -1 disables the timer, meaning that the Start button must be pressed to activate it.

And the last case, this could be started on cron: commandeer -c -d 30 --title "Standby" standby.sh.

For the above examples, the help output for context:
Application Options:
-d, --delay=SECONDS Delay before execution. If -1, disable the timer.
-p, --pause Enable execution pausing.
-c, --cancel Enable cancellation before command is run. Only valid if --delay is set.
-s, --stop Enable cancellation during execution. Implies --cancel.
-t, --title=TITLE Command title.
--text=TEXT Dialog text.

Commandeer will try to be somewhat smart about what to say and how the UI is presented, depending on what options are given on the command line. If --cancel is given but not --stop, then a Cancel button will appear and become insensitive when the command starts. If both --cancel and --stop (or just --stop) are given, the Cancel button will change to a Stop button on run. When --pause is active, a Pause button will be visible and will be enabled when the command launches. Pausing causes the Commandeer window to revert back to a small box to be resumed later.

A PPA is available here. Quite surprisingly, packages are only 11 KB, but are lacking some things (manpage).

Vala source is hosted, where else, on Launchpad, and is only about 300 lines long. I'm aware that I probably made some programming blunders with Vala -- for example, I'm still trying to figure out the whole construct statement vs a method with the class name... but hey, it's all working fine. I've been testing this code on my machine and it feels stable, but don't blame me if you somehow lock yourself out. If you want to play around with it, feel free. Got improvements? File a bug or merge request.

Enjoy it or not, I definitely had a good time learning how to write it.

1 Comment

Jacob, this looks like an interesting tool. It will be even more useful once you get proper locking support. In the meantime, I think I will stick with using the normal "Lock Screen" feature. However, I will keep an eye on the progress of this script.

Leave a comment





Feed identi.ca Twitter LinkedIn Launchpad OpenID