Y = Code

Software development and computer science

Optimizing KDE Activities For Max Productivity

Tips and Tricks to Improve Productivity in Linux with the KDE Desktop Environment

July 2, 2024

KDE is an incredible Linux Desktop with a powerful and mysterious feature called Activities. If you are a heavy multitasker with lots of responsibilities, then learning how to use KDE Activities will unlock a productivity edge that you cannot find anywhere else!

If you are new to Linux, I suggest reading my previous post, This Is Why I Linux.

What is A Desktop Environment?

Linux is so different from Windows and Mac. Everything is customizable. Not only do you have thousands of distributions to choose from, but you can combine those distributions with dozens of desktop environments. The distribution sets the foundation your applications run on, it determines how the subsystems work and how everything is installed, but the desktop environment determines the look and feel. Everything you see and click on, starts with the desktop environment, and the K Desktop Environment is one of the best.

The desktop environment sets the appearance of the application windows on screen, how you interact with them, and how they interact with each other. It determines how you place icons, widgets, files, folders and more. They often include a system for virtual desktops, allowing you to spread your work across multiple desktops even if you only have one monitor. Additionally, many have window tiling features, allowing you to automate the layout of windows on screen. Then they have special effects which add style and fun to the experience.

Desktop environments determine what technologies are used to render your windows. This impacts hardware compatibility with your graphics card and monitor. For example, if you have a 4k or other high resolution monitor, you will need a desktop environment that can scale "high DPI" text so that you can benefit from the sharper resolution, without needing a magnifying glass to read the words on screen. Moreover, the desktop environment comes without its own suite of software. Most often these are the default utilities, like the file manager that allows you to find your files, the default text editor, the terminal, the system configuration menu, and other tools.

The most prominent default software is the "Software Center," which is like an "App Store" for Linux. There you can find applications to install on your system, which have already been vetted to be safe and free of malware.

The Ultimate Virtual Desktop

Most desktop environments support virtual desktops, which allow you to arbitrarily add "virtual screens" to your computer which you can use to spread your work-out. Virtual desktops can greatly increase productivity, especially when you do not have enough space on your monitor. Virtual desktops are all available on Mac and Windows, however the KDE Activities feature adds another layer to it. Using Activities in KDE is like working on multiple computers at once, within the same computer. With Activities, you get a virtual desktop within a virtual desktop, except this one has its own customizations, and user session, focused on individual tasks. In that way, your Activity desktop becomes a powerful way to organize your work by task. This means that you can take things that are potentially distracting, and wall them off into a separate activity, allowing you to focus on one task at a time.

For heavy multi-takers, this provides an incredible opportunity to maximize your focus.

The Power Of Activities

Each Activity in KDE allows you to have activity specific customizations, within the following features:

  • Favorite applications in the launcher menu.
  • Pinned applications on the taskbar.
  • Widgets on the desktop.
  • Wallpaper on the desktop.
  • Favorite file folders.
  • Desktop layouts, including icons and folders shown on the desktop.
  • Scripts triggered by opening the activity, closing the activity, and switching to and from the activity.
  • System configurations.
  • Applications running in the activity.

Unfortunately, 3rd party applications lack integrated support for KDE Activities, this imposes many limits on what activities can do. One especially troublesome case of this, is the lack of web browser integration with KDE Activities. For example, imagine that you want to search DuckDuckGo in your "Search" activity, and you want to read your email in your "Communications" activity. In this case, clicking on a link from your email will open in the "Search" activity, instead of your intended "Communications" activity. This happens because the browser in your "Search" activity was the last window you clicked on, before clicking the link. This is because your browser has no idea what activity it is running in, and it will open new links in the last active browser window. Fortunately, as we will later discover, there are workarounds to mitigate this behavior.

Optimizing KDE For Work

In customizing KDE to fit productivity needs, the first task is to divide the work into a series of activities. This is not easy, in fact I went through a whole stage of creating a list of activities, hating them, removing the feature entirely, and then crawling back to it with a more mature approach. While the presented solution here is by no means a one-size-fits-all, I have found it to be very productive for me. My solution comes down to the following core elements:

  • KDE Activities
  • Note-Taking
  • Folder Organization
  • Web Browser Setup
  • Launch Menu Customization
  • Custom Scripting
  • Tiling Window Management

Activity Setup

I've organized my KDE Activities into nine categories, each of them are things that I can easily become immersed in. There are activities that require a lot of focus to complete, and that do not have much overlap between each other in practice. That is how I determined this KDE Activities list:

Activity Purpose
Home System Administration, email, and chat.
Art Drawing, photo manipulation, video editing, audio editing.
Gaming Steam, Minecraft, etc.
Movies/Music Mostly streaming, Netflix, YouTube, Spotify, etc.
Research Studying, note-taking, learning.
Software Development Programming, debugging, testing, etc.
Writing Mostly blogging, but also business writing.
Business Business emails, PDFs, document signing, and Trello tasks
Bills Paying bills

By far, my most used activity is the Research activity. As you may remember the browser issue from before, clicking on a link in one activity, could result in that link opening in another activity. By keeping all "research" activities under one KDE Activity, it becomes much easier to avoid this. If a link opens in the Research activity, that is fine, because that is the primary place where I browse the web and open links. The downside, of course, is that you may want to see the web resource right next to the work you are working on. This could be a show-stopper for you, but there is a great workaround in my note-taking system. Nearly every task on this list requires looking things up, downloading files, and taking notes. The Research activity gives me a place to focus on just that. Another notable Activity is Home, this is basically my "catch-all" activity. When I start my computer, I start from the Home activity. My email is there, I install/update software from there, and I maintain my system from there.

To create an activity, simply go to "System Settings," select "Activities," and click "Create New." You can set the name, the description, and the icon. You can see the menu to switch between them with Meta + Q, the "Meta" key is usually the "Windows" key or a "Mac" key on your keyboard. However, I recommend setting up Meta + Tab and Shift + Meta + Tab as shortcuts to cycle through your open activities. You can do that by going into Settings, Keyboard, Shortcuts, and then search for "plasmashell." Next, you need to search for "Switch to Next Activity" and "Switch to Previous Activity," to set them to your new hotkeys.

Tip: Do not keep more activities open than you are actively using. Closing an activity does not close the apps in the activity, it just removes it from the list of activities that you can quickly switch to with Meta + Tab. I usually only keep my Research activity open in the background so that I can quickly switch between it and whatever other activity I am doing research for. Having a third activity open often results in me going into the wrong activity. Of course, you can also have a hotkey per activity, and completely eliminate that issue.

Virtual Desktop Setup

While virtual desktops are less critical to my system, I frequently use this setup in my Software Development activity. If you go into Settings and then Virtual Desktops, you'll see controls to specify your number of virtual desktops. I created three rows of three desktops, as that neatly creates a 3 x 3 grid that is easy to navigate. If you then set a shortcut key to display the desktop grid, you can zoom out and see the entire grid at once and drag windows across them. Just go into Settings, Keyboard, Shortcuts, search for "KWin," then search for "Toggle Grid View," and set that to Meta + G. By default, you should be able to switch desktops with Meta + Ctrl + Arrow Key to move in that arrow key direction. Then you'll want a way to pin windows to all desktops, which you can do with the pin icon in the window title bar. However, for windows that don't have this, you can set "Keep Window On All Desktops" to Meta + Ctrl + P.

While you are in there, if you lose your mouse often on large screens, there are two features to help you out. Under Settings, Window Management, Desktop Effects, there is a "Track Mouse" option. Turn it on and configure the shortcut key. I'm using Meta + Ctrl since that's usually what I am pressing anyway, when I want to find my mouse again. This effect shows a ring around your mouse. For users from the macOS world, there is a more familiar option called "Shake Cursor," this is under Settings, Accessibility, Shake Cursor. If you check the "Enable" box, it will make your mouse cursor grow larger when you shake the mouse. Between these two, you should never lose your mouse again.

Markdown Notes With Typora

Next to the Research activity, note-taking is the next-biggest element to my custom KDE setup. Inspired heavily by Joplin, I realized that GitHub style Markdown files are a very powerful way to take notes. For one, you can use any text editor to write Markdown and the syntax is very easy. Additionally, it has support for inserting blocks of code. As a software developer, this is very useful. If I get an interesting log output from an app, or I see some example code that I need to study further, I can just copy and paste it into a Markdown code block and often get syntax highlighting too. This functionality is so invaluable, that this very blog is built on Markdown text, with every entry being a separate Markdown file.

Additionally, when paired with a fantastic Markdown editor like Typora, this system can become a real joy to use. Not only does Typora render Markdown with its formatting rendered beautifully, but it is also designed to keep you focused on writing, and not distracted by Markdown syntax, or the typical features found in writing software. Furthermore, Typora supports opening an entire folder of markdown files, and loading those files and folders into a tree. This makes it easy to navigate between related files without leaving the editor.

To use Typora, you will first have to install it. You can start by opening the Discover app in KDE, then click on "Home," then type "Typora" into the search bar. You may see options for either a Snap or Flatpak version. I prefer Flatpak on KDE, so that is the version I went with.

Note Folders

In Joplin, you can organize notes by tags and folders. As wonderful as tags are, folders are much easier to use, so I didn't worry about losing the tagging support. Regardless, with support for symbolic linking on Linux, you can do something better than tags. You can use symbolic links to give yourself multiple paths to the same shared information. Because of this, you never need to maintain duplicate folders and files on Linux, you can simply use a link. Since Typora opens folders and renders a file folder tree, just by organizing Markdown files into a folder, and opening that in Typora, you have already duplicated most of what Joplin does.

Since I do note-taking mostly in the Research activity, my note-taking folder starts with a special folder for research. However, note-taking is also the way that I connect research results with my other activities. Because of this, my note-taking folders include a folder for nearly each activity I have. Then the folder for research, has a symbolic link back to each of these activity notes. This allows me to see all activity specific notes from the research activity, while focusing only on the activity relevant notes when working in the individual activities. My folder setup roughly looks like:

├── Art
├── Gaming
├── Household
│   └── Bills
├── Business
├── Movies
├── Research
│   ├── Art -> ~/Documents/Notes/Art
│   ├── Gaming -> ~/Documents/Notes/Gaming
│   ├── Household -> ~/Documents/Notes/Household
│   ├── Business -> ~/Documents/Notes/Business
│   ├── Movies -> ~/Documents/Notes/Movies
│   ├── Software Development -> ~/Documents/Notes/Software Development
│   └── Writing -> ~/Documents/Notes/Writing
├── Software Development
└── Writing

To create this, I needed to create a "Notes" folder under my ~/Documents folder, then create each of the sub folders and symbolic links. That can be done by opening the terminal and typing:

cd ~/Documents
mkdir Notes
cd Notes
mkdir Art
mkdir Gaming
...
mkdir Research
ln -s Art Research/Art
ln -s Gaming Research/Gaming
...

File Association

Now you want to ensure that Typora is able to open folders and files so that it is easy to use. There are many ways to do this, but the most direct is to:

  1. Open the System Settings app.
  2. Search for "File Associations."
  3. Type "markdown" in the file type field.
  4. Select "markdown."
  5. Make certain that Typora is at the top of the "Application Preference Order" list, and if not, add it and drag it to the top.
    1. You can add Typora by clicking the "Add" button and searching for Typora in the list. Typing the name "Typora" should find it for you.

Then you want to search for the "directory" type under inode, and do the same, except make sure that Typora is second to Dolphin. You don't want to move Dolphin, as that will make it very hard to use Dolphin.

Note History

Now we just need another important feature from Joplin, version history. Now you could use something like Git to create a detailed version history of all of your Markdown files, however, that seems like overkill. So instead of Git or some other version control system, I deferred to using the incremental snapshot backup software Back In Time. While Back In Time is designed more for tracking critical system files, and creating timed snapshots of them, there's no law against us using it for our Markdown text files.

You can install it through Discover, just click Home and search for "Back In Time." Back In Time has both a root user launcher and a non-root user launcher. Since our files are in the user space, we want the non-root launcher. Once you have Back In Time installed and running, your next steps are:

  1. Create a New Profile. You can use the default profile from the "Profile" menu or click "Add" to create a new backup profile.

  2. Under "Mode" select "Local."

  3. Under "Where to save snapshots" I created the hidden folder ~/.back-in-time and specified that. The dot preceding the folder name makes it hidden so that I am unlikely to mess with it accidentally.

  4. Under "Schedule" you can select a time frame you deem appropriate. For me, I chose "Every 30 minutes."

  5. Under the "Include" tab, folder, select the ~/Documents/Notes folder.

  6. Under the "Exclude" tab, make certain that anything you don't want is specifically excluded.

  7. Inside the "Auto-remove" tab, you can specify precisely how long you want to keep your snapshots for.

  8. You can check the settings under the other tabs, but for these purposes the defaults should be fine.

  9. Click Ok.

Now Back In Time will keep snapshots of your Notes, so if you inadvertently delete something or mess up a note, you can go "back in time" and retrieve prior versions of your notes and restore them.

Cloud Sync And Mobile Access?

The one piece of this note-taking system is the lack of cloud synchronization. You can achieve that with folder syncing apps, you can sync your entire Notes folder to Google Drive or a number of other cloud storage providers. That may work for you. If you are syncing this to another Linux system with a similar set-up, that may work very well. Even if you are syncing to Mac or Windows, those both support Typora, so that may be fine as well. However, if you want to use it on your phone, this may be difficult. There are Markdown editors that you can use on your phone, but I have not yet hashed out the details of making that work smoothly. If you manage to figure it out, please share.

Folder Organization

The next part of my KDE productivity setup is folder organization. For the most part, my folders for files mimics the setup I have for note-taking. Under the ~/Documents folder I have a folder for each activity. This is rough picture of my configuration:

├── Archive
├── Art
├── Audio
├── Household
│	└── Bills
├── Business
├── Notes
├── Research
├── Writing
└── Projects
	├── Archive
	├── github.com
	│	├── bernardigiri
	│	│	├── TurtleBas
	│	│	├── TurtleGo
	│	│	├── TurtlePy
	│	│	└── vernelltaylor
	│	├── bevyengine
	│	└── Trouv
	├── gitlab.com
	│	├── username1
	│	└── username2
	└── Local

For software development, I keep a ~/Documents/Projects folder that closely mirrors the services I use to host my git repositories. Additionally for items like taxes, accounting, and even resumes, I organize things in yearly and sometimes monthly folders. For my resume, I always send it with the same file name, so the folder name is the only thing that differentiates each version of it. Additionally, I litter "Archive" folders around the place, especially in places where dates are important. That way I have a place to stash compressed folders of stuff I might need in the future, but definitely won't touch for years.

With these folders in place you can switch between activities and customize the desktop. By right-clicking on the desktop and clicking "Desktop and Wallpaper" you get the option to edit your wallpaper, and set the desktop layout. In the desktop layout options, if you choose "Folder View" you can make folders visible on your desktop. If you then select Location, you can specify a "Custom location." This is your chance to associate the folders you just made with the Activity you will use them on.

The ~/Downloads Folder

I use my ~/Downloads folder basically as a scratch pad. Anything left in there I expect to be able to delete at any time without consequence. When I am downloading things online, they go there first, and then I move them to somewhere permanent. When I need to put files into an email or move them between activities, I switch to the activity that has the files, move them to the ~/Downloads folder, switch to the destination activity, and then access the files from there. Since I use the ~/Downloads folder everywhere, I also symlink it to every activity folder with ln -s ~/Downloads ....

Anything left in there I expect to be able to delete at any time without consequence.

Since this folder is a scratch pad, I make sure to delete everything inside of it every so often.

Browser Workaround

Using web browsers in KDE Activities can be a pain, as the browser is not aware of the Activity it is running in or being called from. As a result, you'll have to use some tricks to work around this. My first attempt at this with Google Chrome on KDE, was to use a Chromium Activities script in the KDE Store. Unfortunately, this script was incompatible with the flatpak version of KDE, so I had to modify it:

#!/bin/bash

ChromeFolder="~/.var/app/com.google.Chrome/config/\
google-chrome"

AC=$(kactivities-cli --current-activity | grep -v \
  "()" | awk '{print $3}')
[ "$AC" = "" ] || HOME=$HOME/"$(mkdir -p \
  $HOME/.Activity/"$AC" ; echo .Activity/"$AC")"

if [ ! -e $HOME/.config/$ChromeFolder/Default/\
  Preferences ]; then
  rsync -r --exclude 'Sessions' /home/$USER/.config/\
    $ChromeFolder $HOME/.config/
else
  rsync -r --exclude 'Preferences' --exclude \
    'Sessions' /home/$USER/.config/$ChromeFolder \
    $HOME/.config/
fi

/usr/bin/flatpak run --branch=stable --arch=x86_64 \
  --command=/app/bin/chrome --file-forwarding \
  com.google.Chrome @@u %U @@

Unfortunately, even after these changes, I still found it to be unreliable and buggy. Perhaps I missed something in this code? Regardless, these issues led me to stop using KDE Activities entirely. I needed my web browser everywhere, but having it drag work from one Activity to the next, effectively defeated the purpose of separate activities. Fortunately, Google Chrome now has a feature called Profiles and since I have multiple Google Accounts, each profile of Chrome behaves as a separate application instance. That means that if I use a different Chrome profile for each Activity, then those Chrome instances will not cross between Activities. However, you probably don't want to create 9 independent Google Chrome profiles.

Fortunately there are more tricks we can use, here is a list of the strategies I have thus far discovered:

  1. Multiple Browser Profiles (only tested with Google Chrome)
    • If you only use a certain profile on a certain activity, then actions in that profile will stay in that Activity.
  2. Multiple Web Browsers
    • Just like browser profiles but stronger. If you only use a certain browser in a certain activity, then it will stay in that Activity.
  3. Don't use the browser in every activity.
    • With the previously mentioned note-taking system, I can browse in the Research activity, write or copy the relevant parts into Typora, and then open that in the Activity that I need the information in.
    • Also, some activities are less distracting without the web browser. If you can leave it out, you should.
  4. Create a launcher/script that explicitly creates a new browser window.
    • That new window will spawn in the Activity you are in when it launches. Additionally, if you need to open links from that window you can force them to open as new tabs in that window. Unfortunately, there is still a risk that a link may open in another Activity.
  5. Use KDE's "Special" Window/Application Settings to lock applications to the activity that you want them to live in.
    • KDE allows you to specify lots of neat rules to applications and windows that allow you to customize window behavior. This includes the ability to force windows to stick to a specific activity.

Combining all of these techniques, you can greatly reduce the incidence of browser links opening in the wrong Activity. In my setup, I use two Chrome profiles for my personal and business email, I use a separate browser for movie streaming, and I use a launcher and custom scripts to create new browser windows where I need them. I also avoid using browsers in activities that don't need them. As for the KDE window settings, I use that for many other apps, but I haven't needed it for my browser.

Chrome New Window Script

Regardless, creating the custom launcher and script deserves a bit more explanation, as that is not obvious. If you notice the script from before, you'll see the code for launching the flatpak version of chrome:

/usr/bin/flatpak run --branch=stable --arch=x86_64 \
	--command=/app/bin/chrome --file-forwarding \
	com.google.Chrome @@u %U @@

Chrome has a command line flag for opening a new window, it is --new-window. Additionally, you can specify the chrome profile it opens with --profile-directory=$PROFILE_DIRECTORY, where $PROFILE_DIRECTORY is the name of the profile directory. All the profile directories should be in ~/.var/app/com.google.Chrome/config/google-chrome/. To find them all, I would run something like this in the terminal:

find ~/.var/app/com.google.Chrome/config/google-chrome/ \
	-maxdepth 1 -type d \( -name "Default" -o \
	-name "Profile*" \) -exec echo {} \; -exec grep -oP \
	'"email":"\K[^"]+' {}/Preferences \; -exec echo \;

You should get an output like

/home/youruser/.../google-chrome/Profile 1
some_email_1@google.com
docs-hosted-app-own@google.com

/home/youruser/.../google-chrome/Profile 2
some_email_2@google.com
docs-hosted-app-own@google.com

/home/youruser/.../google-chrome/Default
some_email_3@google.com
docs-hosted-app-own@google.com
keep-eng@google.com

That lets you know that the profile directory "Profile 1" is for the "some_email_1" email address, and the profile at "Default" is for the "some_email_3" email address, and so on. If you cannot differentiate by email address, then you may have to look into these folders so see what they each represent. Regardless, once you have that, you can launch a new Chrome window with a something like:

/usr/bin/flatpak run --branch=stable --arch=x86_64 \
	--command=chrome com.google.Chrome \
	--profile-directory=Default --new-window

To turn that into a launcher, you can launch "KDE Menu Editor," select a folder you want the launcher in, click New Item, specify /usr/bin/flatpak as the Program, and the rest of that code goes in the "Command-Line Arguments" field. Then you can set the icon by clicking on the icon button. Finally, set the name, description, and comments, and save it. After that, you can favorite the launcher and pin it to the task bar for specific activities.

Optimizing KDE Menus

Optimization is not a task, it is a process. Over time, things will change, and you may find that some settings are hurting more than helping. Because of this, it is important to regularly reevaluate your configuration, looking for opportunities to improve it. The one place in KDE where that is more apparent than ever, is in the launch menu. As you install new apps, remove apps, apply upgrades, KDE will alter your menu, occasionally in ways that you may not agree with. Additionally, as your usage changes, you may find that the menu you first built for yourself is no longer the best menu. So to make certain that you always have the best menu, you will need to become familiar with the "KDE Menu Editor."

The first step is to launch the menu editor, next you will see buttons to create a new "item," "submenu," and "separator." You can also adjust the sort order of items with the move up and down buttons. If you'd like, you can edit the submenus to match your activities. However, duplicating items in the menu is tedious and adds more items to maintain in your menu. Instead, I suggest relying more on the favorites menu, which can be customized per activity. You should organize your menu in a manner that feels logical, and fits your workflow. Here is a rough example of how I organized my menu:

├── Office <- Business activity tools goes here
│	├── LibreOffice Calc
│	├── SpeedCrunch (calculator)
│	├── GnuCash (Finance Management)
│	├── Xournal++
│	├── PDF Arranger
│	└── Trello Desktop
├── Development <- My software dev tools go here
├── Creativity <- My artistic tools go here
├── Writing <- Writing apps go here
├── Multimedia <- Audio/Video playing apps go here
├── Internet <- Browsers & Torrent apps
├── Science & Math
├── Games
├── Education
├── Settings
└── Utilities

I recommend keeping your most frequently used items near the top of their lists. Doing so will make those priority items easier to find. Once you are done configuring your menu, remember to click the save button to persist your changes.

Pinned & Favorite Apps

From the launcher menu, you can right-click on any app, and you see options to pin it to the task bar which is referred to here as the "Task Manager," the desktop, or add it to the favorites. Within favorites, you have the option to specify which activity it is a favorite under. If you right-click items on the task bar, you can select which activities that icon will show up under.

Scripting KDE Activities

Now that you have your activities, folder, notes, browser, and menu customized, you may find that you want a bit more automation to make using activities smoother. Thankfully, KDE has a feature for triggering scripts when you start an activity, stop an activity, and switch to and from an activity. Given that functionality, you may be tempted to configure it to launch certain apps as soon as you start an activity so that you don't have to start them yourself. Unfortunately, KDE does not have a GUI for any of that. Even worse, in my experience launching apps from these scripts frequently results in multiple instances of your app being launched which can quickly become overwhelming.

One thing you can do to reduce the incidence of unwanted apps opening is to turn on the "Start with an empty session option" in the Settings menu under "Desktop Session." That alone does not fix the issue of multiple app instances opening when you have scripted them to open once on activity start. As a result, I no longer use that method and instead use a launcher icon to manually trigger it. This is a bit more tedious, but it has the benefit of allowing me to opt out of the default app's auto starting, when I don't want that. As I often use my laptop with an external monitor, opening all of my apps there is very different from when the external monitor is disconnected. In that situation, I don't have the screen space to see everything, so I don't want it open.

Regardless, for my app launcher I wrote a series of scripts in a structure like this:

├── launch.sh
└── scripts
    ├── bills.sh
    ├── gaming.sh
    ├── home.sh
    ├── business.sh
    ├── movies.sh
    ├── research.sh
    ├── software-development.sh
    ├── art.sh
    └── writing.sh

The launch.sh script looks like:

#!/usr/bin/env bash
cd "$(dirname -- "$(readlink -f -- "$0")")" || exit

CurrentActivity=$(
  dbus-send --session --dest=org.kde.ActivityManager \
    --type=method_call --print-reply=literal \
    /ActivityManager/Activities \
    org.kde.ActivityManager.Activities.CurrentActivity | \
    tr -d "[:blank:]"
)

ActvityName=$(
  dbus-send --session --dest=org.kde.ActivityManager \
    --type=method_call --print-reply=literal \
    /ActivityManager/Activities \
    org.kde.ActivityManager.Activities.ActivityInformation \
    "string:$CurrentActivity" | awk 'NR==2' | \
    grep -oP '([\w]+[ .+_-]?)+([ ]{2,})' | \
    awk 'NR==2 {print tolower($0)}' | xargs | \
    sed 's/ /-/g'
)

"./scripts/$ActvityName.sh"

This script first changes directories to its installed folder so that it can access the scripts subfolder, then it gets the activity ID of the current activity from KDE, then it uses that ID to get the activity name. Finally, it uses that name to call the appropriate script, which in this example is named the same as the activity, in lower cases, with special characters mapped to dashes so that the file names are safe.

In the scripts under the scripts/ folder, I have things like:

#!/usr/bin/env bash
/usr/bin/flatpak run --branch=stable --arch=x86_64 \
  --command=typora --file-forwarding io.typora.Typora \
  $HOME/Documents/Notes/Household &

flatpak run --branch=stable --arch=x86_64 \
  --command=chrome com.google.Chrome \
  --profile-directory="Default" --new-window \
  "https://mail.google.com" "https://calendar.google.com" &

flatpak run --branch=stable --arch=x86_64 \
  --command=chrome com.google.Chrome \
  --profile-directory="Default" --new-window \
  "https://duckduckgo.com/?q=weather+forecast&ia=web" &

This does the following:

  1. The first line opens up the ~/Documents/Notes/Household folder in Typora, so I can see my notes under "Household."
  2. The second line opens a new window of Google Chrome in the "Default" profile with Gmail and Google Calendar.
  3. The last line opens another such window with the weather forecast in DuckDuckGo.

The next step is to create a launcher that runs your script, just make sure the script is runnable with chmod +x. I like to develop my scripts in my "Projects" folder structure and keep them in version control. To install them, I like to symlink them to ~/.local/bin/ so I can run them easily and from anywhere. In my case, I ran:

ln -s ~/Documents/Projects/github.com/bernardigiri/\
	activity-launcher/launch.sh ~/.local/bin/activity-launcher

Then I can create a launcher in the KDE Menu with activity-launcher in the "Program" field, give it a nice icon, name, description, etc., and save it. From there you can favorite it, pin it to the task-bar, whatever you want. Whenever you click on it, it will read which activity you are currently in, and run the launch script you wrote for that specific activity.

KDE Window/Application Settings

Now that you have a way to launch apps for your given activity, you may also want a way to position them on screen automatically. For those of you with widescreen monitors like I have, that can be really useful. Unfortunately, if you are running KDE under "Wayland" scripting this is really difficult. I have yet to find a convenient way to do it. However, you can use the KDE "Special" Window/Application settings to position your windows. You can force them to stay in one spot, you can make them start up in one spot, you can set the width and the height, and lots more. Unfortunately, these rules will apply to all matching windows, regardless of which activity you are opening the window in. So if you want Typora to open in one corner in the Art activity, and you want Typora in another corner in the Software Development activity, you can't do that. Thus, your options for automatically positioning windows on launch are limited. Regardless, you still have an incredible amount of scripting power here.

Tiling Window Management

If you have a wide screen monitor, you may find it a bit challenging to maximize all of your screen real estate. You may want your apps to automatically position themselves on screen, however, as previously mentioned, there are some limitations there. Fortunately, we still have something called a Tiling Window Manager that opens up a lot of possible solutions. In KDE, the default KWin window manager has many window tiling features. Window tiling managers provide a system for automatically positioning windows on screen so that the user doesn't have to manually drag window edges. Many of these systems tile windows based on which one was launched first, and they include keyboard shortcuts to move things around. In KWin however, you can do everything with the mouse, and mix conventionally positioned windows with automatically positioned windows.

To enable that, go into Settings, Desktop Effects, and turn on the Tiling Editor. Then click on the Settings button on the tiling editor to make sure the shortcut key is configured. By default, that key is Meta + T. When you press it, you are presented with an onscreen editor that allows you to divide your desktop into tiling zones. Once you have done that, you can press escape to exit. From there, you can drag windows into tiling zones just by holding down the shift button as you drag the window. Just let go of the mouse, and the window pops into the zone.

By using KWin's tiling editor, you can make it easy to quickly lay out your apps into your desired regions of your desktop. It's unfortunate that you cannot automate the whole process into a single click, or even into auto starting when you launch an activity, but it is still very powerful, and saves a lot of time. Additionally, I do hope that KDE extends this tiling editor to add support for activities. Being able to have a different layout per activity would be really nice.

Conclusion

Using KDE Activities is a powerful way to increase your productivity on Linux, by providing new techniques for organization, removing distractions, and automating your system. Using a thoughtful note-taking system, well organized folders, and clever scripting, you can make it easier to get to the information you need quickly. Additionally, using KWin's Tiling Editor you can maximize your use of screen real-estate, allowing you to see more information at once. Furthermore, by thinking of optimization as a process and not a task, you can make a habit of boosting the performance of your work-flow. When put together, these strategies unlock a productivity edge that you cannot find elsewhere.