KDE provides users with the tools to run software automatically using two features: Autostart and Task Scheduler (formerly called KCron). These tasks can be initiated immediately prior to KDE startup, during KDE startup, or scheduled at anytime: daily, hourly, weekly, or even every five minutes. Both of these features were present in KDE 3. Autostart programs could be dropped into the ~/.kde/share/autostart directory, and automated programs (cron jobs) could be created through a standalone application called KCron.
With KDE 4, Autostart and KCron are now both integrated into System Settings. To start either one, simply click on the K menu and then click System Settings. Next, click the “advanced” tab. Under the Advanced User Settings section, you should see Autostart, and under the System section, make sure that you see Task Scheduler. On my Kubuntu system, Task Scheduler was not installed, so I had to start kpackagekit and install the kcron package.
Running applications at KDE startup
To run an application at KDE startup, follow these simple steps:
- In System Settings, click Autostart.
- Click Add Program.
- Select the application that you want to run (for this example, I will select KRandTray, as it is an application that will start in the system tray).
- Click OK.
That is all it takes. You can remove the check from the Enable box anytime you do not want KDE to start with that application.
To run a script on or before KDE startup, follow these simple steps:
- Click Add Script.
- Type the full path to the script or click the folder to browse your computer for it. (for the example, I am choosing a script I made called startxrandr).
- Check or uncheck the Create as symlink box. (If unchecked, it will make a copy of the script in your ~/.kde/share/autostart directory).
- Click OK.
Running periodic tasks
Most Unix-like operating systems have a feature that allows the user to run scripts and services on a schedule. For example, if you want a log file to be purged at midnight every night, you can schedule a script to do that. Scheduled tasks are called “cron jobs” because they are handled by a program called Cron, and the schedule is controlled in a configuration file called crontab. In a previous article, MTE taught you how to schedule cron jobs in GNOME. Now, you will learn how to do it in KDE.
To schedule a task in KDE, follow these simple steps:
- Open System Settings, click the Advanced tab, and then click Task Scheduler.
- Decide whether you want to run a Personal Cron (affecting only your user space) or a System Cron (affecting all users on your system and for which you will need root permissions).
- Click New Task.
- Enter the command, browse, or begin typing the path (i.e. /usr/bin/), and it will show you a list of commands in that folder in a drop-down menu.
(For this example, I am selecting a script called my-sync-script.sh that will sync my Google calendar with KOrganizer.)
- Next, you simply decide when you want the task to run. Selecting every day will gray out day and month selection, or you can specify a certain month, day, hour, and minute.
( For my example, I want it to run every day at 3:30 PM right before I leave work.)
- Click OK.
You can also use the Task Scheduler to setup environment variables. In the example image, I have setup one to force KDE into realizing that the system is connected to two monitors (KDE_MULTIHEAD=true).
That is all it takes. With two simple graphical tools, you now have the power to run applications, commands, and scripts whenever and as often as you want.
Our latest tutorials delivered straight to your inbox