You are not logged in.

#1 2012-11-11 23:28:24

gustavosg
Member
From: Viamão
Registered: 2012-10-22
Posts: 6

[KDE 4.9] Using a shell script as a KDE shortcut - Caps Lock Notify

Hi, all

I was trying to create a small script to send a notification if the Caps Lock is active or not. The script works correctly in the terminal, but when I use the script as a shortcut in KDE it does not work ... I simply trigger the shortcut with the "Caps Lock".

Below is the script that I created:

#!/bin/bash
#
# Send a notification of CAPS LOCK on/off

# Icon used in the notification
icon="/usr/share/icons/NITRUX/devices/48/keyboard.svg"

# verify if the CAPS is on/off
value=$(xset q | grep "LED mask" | sed -r "s/.*LED mask:\s+[0-9a-fA-F]+([0-9a-fA-F]).*/\1/")
if [ "$value" == "0" ]; then
  output="Off"
else
  output="On"
fi

# Send notification (use Gnome or KDE)

# GNOME
#notify-send -i $icon "Caps Lock $output" -t 1000 

#KDE
kdialog  --icon $icon --passivepopup "Caps Lock $output" --title "Keyboard" 1

Could someone help me pointing what I'm doing wrong?


Thanks in advance!

EDIT: If I do not use the "caps lock" as a trigger, the script works as it should (I tried using "ctrl + alt + L") ...

Last edited by gustavosg (2012-11-13 00:06:46)

Offline

#2 2012-11-12 01:21:48

cfr
Member
From: Cymru
Registered: 2011-11-27
Posts: 7,198

Re: [KDE 4.9] Using a shell script as a KDE shortcut - Caps Lock Notify

Is caps lock set to do something in KDE settings? I don't know but usually KDE won't let you use a shortcut which is assigned to do something else. I'm not sure whether you can use a single key as a shortcut but, if you can, wouldn't you have to dedicate that key to just doing that? Not sure about this...


CLI Paste | How To Ask Questions

Arch Linux | x86_64 | GPT | EFI boot | refind | stub loader | systemd | LVM2 on LUKS
Lenovo x270 | Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz | Intel Wireless 8265/8275 | US keyboard w/ Euro | 512G NVMe INTEL SSDPEKKF512G7L

Offline

#3 2012-11-12 08:46:14

Pajaro
Member
Registered: 2004-04-21
Posts: 884

Re: [KDE 4.9] Using a shell script as a KDE shortcut - Caps Lock Notify

I have no problem setting shortcuts for scripts with kde. Are you using systemsettings to stablish the shortcut?

Offline

#4 2012-11-12 10:49:38

Box0
Member
From: Italy
Registered: 2011-09-21
Posts: 218

Re: [KDE 4.9] Using a shell script as a KDE shortcut - Caps Lock Notify

cfr wrote:

I'm not sure whether you can use a single key as a shortcut

yes, you can.

Offline

#5 2012-11-12 19:05:13

gustavosg
Member
From: Viamão
Registered: 2012-10-22
Posts: 6

Re: [KDE 4.9] Using a shell script as a KDE shortcut - Caps Lock Notify

Pajaro wrote:

I have no problem setting shortcuts for scripts with kde. Are you using systemsettings to stablish the shortcut?

Hi, all.

Sorry, I think I expressed myself badly.

When I use my scrip "caps.sh" as a shortcut and use the "caps lock" key as a trigger, whenever I press the caps lock key the shortcut works and the script runs, but the information he gives me is wrong (it always says the caps is on). When I use a different trigger key, for example "ctrl + shift + L", everything works like a charm...

I hope I have made my issue clearer.

Also, sorry for my bad english.


Thanks for all the replies.

Last edited by gustavosg (2012-11-12 19:05:42)

Offline

#6 2012-11-12 20:03:51

Pajaro
Member
Registered: 2004-04-21
Posts: 884

Re: [KDE 4.9] Using a shell script as a KDE shortcut - Caps Lock Notify

try sending the dialog with a delay in background

Offline

#7 2012-11-12 20:06:49

Xabre
Member
From: Serbia
Registered: 2009-03-19
Posts: 757

Re: [KDE 4.9] Using a shell script as a KDE shortcut - Caps Lock Notify

SysSettings->Input edvices->Keyboard, Advanced tab, under 'Caps lock behaviour', disable usage of caps lock.

I think the problem is that both kde and your script manage the same thing, so when you press Caps, two things happen, and they collide.

Offline

#8 2012-11-12 21:10:45

gustavosg
Member
From: Viamão
Registered: 2012-10-22
Posts: 6

Re: [KDE 4.9] Using a shell script as a KDE shortcut - Caps Lock Notify

Pajaro wrote:

try sending the dialog with a delay in background

Hi! Thanks for replying. I've tried the sleep command, still saying that caps is always on (if it is what you mean).

Xabre wrote:

SysSettings->Input edvices->Keyboard, Advanced tab, under 'Caps lock behaviour', disable usage of caps lock.

I think the problem is that both kde and your script manage the same thing, so when you press Caps, two things happen, and they collide.

If I disable the caps, the shortcut don't trigger. And what my script does is just check the caps "statuts". But thanks for the reply, I didn't noticed that function. Now i'm using "shift disables caps" smile

Last edited by gustavosg (2012-11-12 21:16:52)

Offline

#9 2012-11-12 21:41:42

Pajaro
Member
Registered: 2004-04-21
Posts: 884

Re: [KDE 4.9] Using a shell script as a KDE shortcut - Caps Lock Notify

gustavosg wrote:
Pajaro wrote:

try sending the dialog with a delay in background

Hi! Thanks for replying. I've tried the sleep command, still saying that caps is always on (if it is what you mean).

What I meant is to do something like:

$(sleep .5; echo kdialog  --icon $icone --passivepopup "Caps Lock $saida" --title "Teclado" 1) &

Offline

#10 2012-11-12 22:20:40

cfr
Member
From: Cymru
Registered: 2011-11-27
Posts: 7,198

Re: [KDE 4.9] Using a shell script as a KDE shortcut - Caps Lock Notify

Maybe you could post the script if you are still having trouble?

Thanks for the info about single key short cuts. I guess it has never occurred to me. (Maybe because on a laptop you can't usually spare a whole key for a single short cut!)


CLI Paste | How To Ask Questions

Arch Linux | x86_64 | GPT | EFI boot | refind | stub loader | systemd | LVM2 on LUKS
Lenovo x270 | Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz | Intel Wireless 8265/8275 | US keyboard w/ Euro | 512G NVMe INTEL SSDPEKKF512G7L

Offline

#11 2012-11-13 00:04:13

gustavosg
Member
From: Viamão
Registered: 2012-10-22
Posts: 6

Re: [KDE 4.9] Using a shell script as a KDE shortcut - Caps Lock Notify

Pajaro wrote:
gustavosg wrote:
Pajaro wrote:

try sending the dialog with a delay in background

Hi! Thanks for replying. I've tried the sleep command, still saying that caps is always on (if it is what you mean).

What I meant is to do something like:

$(sleep .5; echo kdialog  --icon $icone --passivepopup "Caps Lock $saida" --title "Teclado" 1) &

When I use it on the script it just printi "Caps" on the notification, as if it was reading just the first word of the "Caps Lock $saida".

Edited the script to this:

#!/bin/bash
#
# Manda aviso de CAPS LOCK on/off

# icone pra usar na notificacao
icone="/usr/share/icons/NITRUX/devices/48/keyboard.svg"

# verifica se o Caps esta ligado
valor=$(xset q | grep "LED mask" | sed -r "s/.*LED mask:\s+[0-9a-fA-F]+([0-9a-fA-F]).*/\1/")
if [ "$valor" == "0" ]; then
  $(sleep .5; echo kdialog  --icon $icone --passivepopup "Caps Lock Off" --title "Teclado" 1) &
else
  $(sleep .5; echo kdialog  --icon $icone --passivepopup "Caps Lock On" --title "Teclado" 1) &
fi

# Dispara alerta (usar Gnome ou KDE)

# GNOME
#notify-send -i $icone "Caps Lock $saida" -t 1000 

#KDE
#$(sleep .5; echo kdialog  --icon $icone --passivepopup "Caps Lock $saida" --title "Teclado" 1) &
cfr wrote:

Maybe you could post the script if you are still having trouble?

Thanks for the info about single key short cuts. I guess it has never occurred to me. (Maybe because on a laptop you can't usually spare a whole key for a single short cut!)

The script is the one in the OP. I'm using a laptop.


EDIT:
Updated OP script to english...

Last edited by gustavosg (2012-11-13 00:07:38)

Offline

#12 2012-11-13 11:42:52

Pajaro
Member
Registered: 2004-04-21
Posts: 884

Re: [KDE 4.9] Using a shell script as a KDE shortcut - Caps Lock Notify

Well, you can try to just put $saida as --passivepopup argument to at least see if it is working.

Another way to achieve the same is this. I didn't test it, fix it if you need to.

function delayed() {
    sleep .5
    kdialog  --icon "$1" --passivepopup "Caps Lock $2" 0 --title "Teclado"
}
delayed $icon $saida &

Last edited by Pajaro (2012-11-13 11:43:36)

Offline

#13 2012-11-13 20:39:39

gustavosg
Member
From: Viamão
Registered: 2012-10-22
Posts: 6

Re: [KDE 4.9] Using a shell script as a KDE shortcut - Caps Lock Notify

Pajaro wrote:

Well, you can try to just put $saida as --passivepopup argument to at least see if it is working.

Another way to achieve the same is this. I didn't test it, fix it if you need to.

function delayed() {
    sleep .5
    kdialog  --icon "$1" --passivepopup "Caps Lock $2" 0 --title "Teclado"
}
delayed $icon $saida &

Hi! Just tested... Didn't work. Still just saying Caps is ON.

Thanks for the reply.

Offline

Board footer

Powered by FluxBB