Skip to content

Instantly share code, notes, and snippets.

@networkException
Last active December 15, 2023 11:52
Show Gist options
  • Save networkException/5a68299accc1872749c86301c1449690 to your computer and use it in GitHub Desktop.
Save networkException/5a68299accc1872749c86301c1449690 to your computer and use it in GitHub Desktop.
Setup Plasma Custom Shortcuts for macOS like Screenshots

Introduction

After moving to Linux and KDE Plasma from macOS, I only missed one thing that I used all the time: The Screenshot tool. The Shortcuts on macOS have been engraved in my head after probably thausand of uses so I figured I'd give replicating them a try.

Creating new Shortcuts was surprisingly easy so here is a rundown of it

NOTE: A recent edit of this document now includes a Plasma Native approach using Spectacle. I would recommend using Spectacle as it directly integrates with KWin and the clipboard, will support wayland in the future and is a lot cleaner to work with.

Setup (Plasma Native Version)

You will need

  • A directory to store screenshots in (I use ~/pictures/screenshots)
  • Spectacle set up to use said screenshot directory
  • Spectacle set up to use "Accept on click-and-release" for rectangular regions

Adding Custom Shortcuts

As I already said this is surprisingly easy.

Open System Settings, then go to Shortcuts > Custom Shortcuts. Here I created a group called "Screenshot" so that its all tidy.

I added the following:

  • Area
    Comment: Makes a screenshot of an selected area and saves it to a file
    Trigger: Shift + Command + 4
    Action: spectacle --background --region

  • Area Clipboard
    Comment: Makes a screenshot of an selected area and copies it to the clipboard
    Trigger: Shift + Control + Command + 4
    Action: spectacle --background --region --copy-image

  • Full
    Comment: Makes a screenshot of all screens and saves it to a file
    Trigger: Shift + Command + 3
    Action: spectacle --background

  • Full Clipboard
    Comment: Makes a screenshot of all screens and copies it to the clipboard
    Trigger: Shift + Control + Command + 3
    Action: spectacle --background --copy-image


Setup

You will need

  • A directory to store screenshots in (I use ~/pictures/screenshots)
  • An install of maim
  • An install of either xclip or copyq (I will go into this in the next secion)

xclip vs. copyq

At first I just used the example from the maim readme to put screenshots into the clipboard, meaning xlip. Sadly this was giving me issues (similar to this) so I decided to switch to copyq.

As I only use copyq for screenshots I set the following config values

autostart true
maxitems 1

I also unchecked every option in Clipboard Manipulation in the config menu and hid its tray icon

If xclip does not have issues on your system it is surely a more lightwight solution, I will include command for both tools down below

Adding Custom Shortcuts

As I already said this is surprisingly easy.

Open System Settings, then go to Shortcuts > Custom Shortcuts. Here I created a group called "Screenshot" so that its all tidy.

I added the following:

  • Area
    Comment: Makes a screenshot of an selected area and saves it to a file
    Trigger: Shift + Command + 4
    Action: maim -su ~/pictures/screenshots/$(date --iso-8601=seconds).png

  • Area Clipboard
    Comment: Makes a screenshot of an selected area and copies it to the clipboard
    Trigger: Shift + Control + Command + 4
    Action: maim -su | copyq write image/png - && copyq select 0 or maim -su | xclip -selection clipboard -t image/png

  • Full
    Comment: Makes a screenshot of all screens and saves it to a file
    Trigger: Shift + Command + 3
    Action: maim -u ~/pictures/screenshots/$(date --iso-8601=seconds).png

  • Full Clipboard
    Comment: Makes a screenshot of all screens and copies it to the clipboard
    Trigger: Shift + Control + Command + 3
    Action: maim -u | copyq write image/png - && copyq select 0 or maim -u | xclip -selection clipboard -t image/png

Flags

Of course you can also set your own flags for maim, there is a lot to choose from! I'm just using -u everywhere, which hides the cursor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment