Ubuntu / Linux news and application reviews.

"When" (or "when-command") is a task scheduler which allows running unattended tasks when certain conditions are met.

When Command

Using "When", you can set your desktop to perform various tasks depending on certain conditions. For instance, you can synchronize files, perform some cleanup actions, auto import photos from external storage devices and many other tasks (these are examples and require adding commands or scripts to "When"), all based on conditions such as a command exit code or output, a given time interval, file/folder changes and more.

Even though for some tasks you'll have to write your own scripts, When makes it easier to use them as you won't have to include all the conditions supported by When in your scripts.

According to its developer, the application "is not generally intended as a replacement to cron and the Gnome Task Scheduler, although to some extent these utilities might overlap". 

He adds that "When is intended to be more flexible, although less precise, and to provide an alternative to more complicated solutions -- such as the implementation of cron jobs that check for a particular condition and execute commands when the condition is verified".

Using "When", you can create tasks that depend on the following conditions:
  • command: exit code, standard output, standard error, with options for exact match, case sensitive and regular expression;
  • time interval (every X minutes/hours);
  • at a given date/time;
  • idle session;
  • event: startup, shutdown, suspend, resume, connect/disconnect storage device, join/leave network, screensaver started / return from screensaver, session lock/unlock and a command line trigger (some conditions, like the session lock/unlock and the screensaver events might not work under Linux distributions other than Ubuntu due to the way they are currently detected);
  • file / directory change;
  • user defined event (dbus - advanced feature).

For each task, you can specify a command, a working folder, add environment variables and check for the command success or failure (or check for nothing and just run the command ignoring the output).

From the application settings you can change the tray/indicator icon theme, set the maximum concurrent tasks, log level, enable or disable file and directory notifications and more:

When Command

Other When features include an option to pause all tasks (can be accessed from the tray/indicator menu) as well as a task history window which includes the exit code for each tasks that ran so far, along with its result:

When Command

To use the application, firstly create a new task (from the tray/indicator menu select "Edit Tasks"), enter a name, command and so on and click "OK":

When Command

Then you need to assign a condition for the newly created task - to do this, from the tray/indicator menu, select "Edit Conditions", enter a name for your new condition, type, etc. and under "Tasks", select the task you've created from the drop-down:

When Command

Important: don't use spaces for the task / condition name as it won't work (the Ok button is grayed out if the name contains spaces). 

For more information on When and how to use it, see its GitHub page, the When tutorial and the examples available HERE.

Install When in Ubuntu or Linux Mint

To install "When" in Ubuntu, Linux Mint and derivatives, follow the steps below:

1. Download the latest When (deb) from GitHub and install it.

2. To complete the When installation, run the following command:
/opt/when-command/when-command --install
(without running the command above, you won't have a When menu / Dash entry, the option to allow it to start on login won't work, etc.)

3. (Optional) Install "python3-pyinotify" for file/folder notification support.
sudo apt-get install python3-pyinotify

Note that on some desktop environments (this happened in my test while using Linux Mint Cinnamon), the When menu entry might not show up until you restart your session (logout/login).

Report any bugs you may find @ GitHub.

Also see: