[SOLVED] Keyboard shortcut that types text

Quick to answer questions about finding your way around Linux Mint as a new user.
Forum rules
There are no such things as "stupid" questions. However if you think your question is a bit stupid, then this is the right place for you to post it. Stick to easy to-the-point questions that you feel people can answer fast. For long and complicated questions use the other forums in the support section.
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Locked
ellymae
Level 1
Level 1
Posts: 26
Joined: Mon Aug 01, 2022 6:41 pm

[SOLVED] Keyboard shortcut that types text

Post by ellymae »

I want to make a keyboard shortcut to simply type some text where ever the cursor is. I went into the Keyboard app ⇒ Shortcuts ⇒ Custom Shortcuts ⇒ Add custom shortcut. In the command area, I put echo testtext. Then I assigned a key combination to it. But when I press the key combination, the cursor quickly flickers once, and that's all. No text.

I know that Ubuntu used to have a "Typing" category of shortcut. But in Mint, it's missing.

So, how do I go about making a keyboard shortcut that simply types some text?

Thanks.
Last edited by LockBot on Tue Aug 01, 2023 10:00 pm, edited 2 times in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
Nikolai5
Level 4
Level 4
Posts: 309
Joined: Thu Dec 23, 2021 5:25 pm
Location: Northern England

Re: Keyboard shortcut that types text

Post by Nikolai5 »

You could write a script and use a program called xdotool to perform the key presses. This will actually simulate keyboard presses.

Code: Select all

apt install xdotool
In the keyboard shortcut, instead of putting the long xdotool sequence of stuff, you could instead execute a script file that contains it to make it look cleaner. So create a script file (e.g. PrintWord.sh) somewhere in your documents, and tell your shortcut to execute it like "bash ~/Scripts/PrintWord.sh"

there's a man page for xdotool but basically it works like this:

Code: Select all

xdotool key h e l l o
That presses the keys: h, e, l, l, o
one after the other.
You can do key combinations too, like ctrl + something else, etc.

You should be able to achieve what you want if you play around with that.
ellymae
Level 1
Level 1
Posts: 26
Joined: Mon Aug 01, 2022 6:41 pm

[SOLVED] Keyboard shortcut that types text

Post by ellymae »

Thanks a lot. That's what I'm looking for. Very helpful.
ander111
Level 3
Level 3
Posts: 179
Joined: Sat Jul 17, 2010 5:18 am

Re: [SOLVED] Keyboard shortcut that types text

Post by ander111 »

Just wondering―is there a way to use Cinnamon's "custom shortcut" feature (System Tools > Keyboard > Shortcuts) to make shortcuts that type text?

In my case, all I need are "hotkeys" to type four characters:




é

...which come up often in my work. I don't mind installing extra software, but it seems more efficient if I can use a built-in capability.
ander111
Level 3
Level 3
Posts: 179
Joined: Sat Jul 17, 2010 5:18 am

Re: [SOLVED] Keyboard shortcut that types text

Post by ander111 »

For anyone else seeing this---the procedure Nikolai5 describes is explained here in more detail:

How to Add Custom Keyboard Shortcut to Paste a Predefined Text in Linux Mint

That said, is there no way to use Cinnamon's existing "custom shortcut" feature (System Tools > Keyboard > Shortcuts) to make shortcuts that type text?

In my case, all I need are "hotkeys" to type four characters:




é

...which come up often in my work. Writing scripts and building and installing a separate software tool seems like overkill, but I'll do that if I must. (And yes, I know about the Character Map---but the amount of page-changing, scrolling and character-hunting it'd require wouldn't be worth it.)
Locked

Return to “Beginner Questions”