GithubHelp home page GithubHelp logo

drarig29 / auto-paste-emoji Goto Github PK

View Code? Open in Web Editor NEW
7.0 3.0 0.0 5 KB

A script which automatically pastes an emoji if you just selected it from KDE Plasma's emoji picker

Shell 100.00%
automation xdotool clipboard emoji emoji-picker kde-plasma bash-script

auto-paste-emoji's Introduction

auto-paste-emoji

A script which automatically pastes an emoji if you just selected it from KDE Plasma's emoji picker.

You can tweak it to meet your needs.

Dependencies:

Usage

Download this script or clone the repository.

Then, symlink it somewhere like /usr/bin/auto-paste-emoji:

ln -s ~/path/to/auto-paste-emoji.sh /usr/bin/auto-paste-emoji

To run this script at startup, you need to put it somewhere which is loaded after X server starts, so forget systemd. Otherwise you'll get a Unable to connect to X server error.

You can use files like .xinitrc, .xsession or .xprofile. Keep in mind that by default, .xinitrc is only loaded when we use the startx command. So this file won't be loaded if you use a desktop environment.

Warning: this file contains an infinite loop, so you need to run the command in the background with &, otherwise your desktop environment is likely to freeze when you log in.

I personally used ~/.xprofile, here is its content:

#!/bin/bash
exec /usr/bin/auto-paste-emoji &

How it works?

  • It uses clipnotify, so no polling is involved
  • Any existing instance of the script is killed
  • All errors are ignored so that the program doesn't stop unexpectedly
  • When the selection changes, it checks if the emoji picker is open and a single emoji is in the clipboard
  • If it's the case, we assume the emoji was just selected: so the picker is closed and the emoji is pasted
  • A small delay is added between closing the picker and pasting the emoji to let the emoji picker's window disappear and let the focus change
  • To close the window we don't use xdotool windowclose but we simulate pressing EscEsc instead
    • For some reason, closing the window kills the whole process and the shortcut to open the picker won't respond afterwards
    • We simulate pressing Esc twice because if you used the search feature in the picker, pressing Esc will clear the search string, so we need a second key stroke

You can view the logs using journalctl:

journalctl -b | grep -E "\[$(pidof -x /usr/bin/auto-paste-emoji)\]"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.