How to Set Up Automated Tasks with Cinnamon Desktop on Linux Mint

Learn how to set up automated tasks on Linux Mint using various methods.

Automation can make using your Linux Mint system more efficient, reducing repetitive tasks and improving productivity. Cinnamon, the default desktop environment of Linux Mint, doesn’t include a built-in task scheduler, but Linux itself offers powerful tools like cron, systemd timers, and third-party automation utilities. This guide will walk you through setting up automated tasks on Linux Mint using these methods.

Understanding Task Automation on Linux Mint

Automated tasks, also known as scheduled jobs, allow your system to perform specific actions at predefined times. Common uses include:

  • Running backups at night
  • Updating software automatically
  • Cleaning up temporary files
  • Sending reminders or notifications
  • Automating file transfers

Linux Mint provides multiple ways to set up automation, each suited to different types of tasks.

Method 1: Using Cron Jobs

cron is a time-based job scheduler that allows users to execute scripts, commands, or programs at scheduled intervals.

Installing Cron (if not already installed)

Most Linux Mint installations come with cron pre-installed. You can verify its presence with:

crontab -l

If cron is missing, install it using:

sudo apt update && sudo apt install cron

Enable and start the cron service:

sudo systemctl enable cron
sudo systemctl start cron

Editing the Crontab

Each user has their own crontab file, which defines scheduled tasks. To edit it, use:

crontab -e

This will open the default text editor. Add a new task using the following format:

* * * * * command-to-execute

The five asterisks represent:

  1. Minute (0-59)
  2. Hour (0-23)
  3. Day of the month (1-31)
  4. Month (1-12)
  5. Day of the week (0-7, where both 0 and 7 represent Sunday)

For example, to run a backup script every day at 2 AM:

0 2 * * * /home/user/scripts/backup.sh

Save and exit the file. cron will now run the task as scheduled.

Checking Cron Logs

To check if your cron job is running, use:

journalctl -u cron --since today

Or redirect output to a log file by modifying the job:

0 2 * * * /home/user/scripts/backup.sh >> /home/user/logs/backup.log 2>&1

Method 2: Using Systemd Timers

For more reliability and flexibility, systemd timers can be used instead of cron.

Creating a Systemd Timer

  1. Create a systemd service file:
nano ~/.config/systemd/user/mytask.service

Add the following:

[Unit]
Description=My Automated Task

[Service]
ExecStart=/home/user/scripts/task.sh

Save and exit.

  1. Create a timer file:
nano ~/.config/systemd/user/mytask.timer

Add the following:

[Unit]
Description=Runs My Automated Task

[Timer]
OnCalendar=*-*-* 02:00:00
Persistent=true

[Install]
WantedBy=timers.target

This schedules the task to run daily at 2 AM.

  1. Enable and start the timer:
systemctl --user enable mytask.timer
systemctl --user start mytask.timer

To check status:

systemctl --user list-timers

Method 3: Automating GUI Actions with AutoKey

For users who want to automate keyboard and mouse actions in Cinnamon, AutoKey is a useful tool.

Installing AutoKey

sudo apt install autokey-gtk

Launch it from the applications menu.

Creating an Automation Script

  1. Open AutoKey and create a new script.
  2. Enter Python code to simulate actions. For example:
import time
keyboard.send_keys('<ctrl>+t')  # Opens a new tab in a browser
  1. Assign a trigger key or set it to run automatically at login.

Method 4: Using Bash Scripts with Startup Applications

For simple automation tasks, you can use shell scripts executed at startup.

Creating a Bash Script

  1. Open a terminal and create a script:
nano ~/scripts/startup_task.sh

Add:

#!/bin/bash
echo "Startup task running" > ~/logs/startup.log

Save and make it executable:

chmod +x ~/scripts/startup_task.sh

Adding to Startup Applications

  1. Open Startup Applications in Cinnamon.
  2. Click Add, give it a name, and set the command to:
/home/user/scripts/startup_task.sh
  1. Click Save. The script will now run at login.

Conclusion

Automation in Linux Mint using the Cinnamon desktop can streamline tasks and improve efficiency. Whether you use cron, systemd timers, AutoKey, or simple bash scripts, there’s a method to suit your needs. Start with basic automation and expand as you get more comfortable with Linux’s powerful scheduling capabilities.