Xfce Forum

Sub domains
 

You are not logged in.

#1 2021-08-09 01:19:36

manola
Member
Registered: 2021-08-09
Posts: 5

script does not echo into desktop

Hello I'm trying to paste a code with a keyboard shortcut.
I made this mini shell script.

#!/bin/sh
date "+%Y%m%d%H%M%S"

And I added to the Keyboard/Application Shortcuts menu. sh /home/manola/zcode.sh

I made executable and it works on the terminal. But I can not make it work everywhere with the keyboard shortcut.

What am I missing? Thank you

Offline

#2 2021-08-09 01:40:31

ToZ
Moderator
From: Canada
Registered: 2011-06-02
Posts: 8,040

Re: script does not echo into desktop

Hello and welcome.

Unless specified, a keyboard shortcut does not include a default standard out, meaning the result is sent into nowhere-ness (more or less). When run in a terminal window, you have a standard out - the terminal - and the result is displayed there.

What are you trying to do with this command?

For example, to open a terminal and display the result, set the shortcut to:

xfce4-terminal -H -x date "+%Y%m%d%H%M%S"

...this creates a terminal to output the result to.

Offline

#3 2021-08-09 02:23:57

manola
Member
Registered: 2021-08-09
Posts: 5

Re: script does not echo into desktop

Oh yes that is what I was suspecting.

I want to press the shortcut and echo the output if I am typing on an editor or naming a new a file. I use those codes as IDs for notes.

I did not find another app to do that yet.

Maybe the clipboard can be used as intermediary I do not know.

thank you ToZ I will keep looking.

Offline

#4 2021-08-09 02:51:39

ToZ
Moderator
From: Canada
Registered: 2011-06-02
Posts: 8,040

Re: script does not echo into desktop

You can use xdotool. For example:

#!/bin/bash

OUTPUT=$(date "+%Y%m%d%H%M%S")
sleep .25s
for (( i=0; i<${#OUTPUT}; i++ )); do
	xdotool key "${OUTPUT:$i:1}"
done

Offline

#5 2021-08-09 03:25:37

manola
Member
Registered: 2021-08-09
Posts: 5

Re: script does not echo into desktop

For some reason does not seem to work. But I will take it from here. I didn't know about xdotool. I think this is the way to go.

That script give me this output.

"="!=(=)==%==!

later this one

"="!=(=)==%##$

If I make it work I will post it. Thank you for the help.

Last edited by manola (2021-08-09 03:55:01)

Offline

#6 2021-08-09 08:32:24

Tamaranch
Member
Registered: 2020-12-31
Posts: 34

Re: script does not echo into desktop

I recently gave such a solution to the same question on Gitlab, you can try it if you want: https://gitlab.xfce.org/apps/mousepad/- … note_33833

In short, with your date format, it consists in putting as command in the shortcut:

sh -c 'xdotool sleep 0.5 type "$(date "+%Y%m%d%H%M%S")"'

Last edited by Tamaranch (2021-08-09 08:36:03)

Offline

#7 2021-08-10 00:30:18

Skaperen
Member
From: right by Jesus, our Saviour
Registered: 2013-06-15
Posts: 558

Re: script does not echo into desktop

suppose you are running 3 terminal windows?  where do you expect the output to go?  what if there are no terminal windows?

the shortcuts get run in the context of XFCE itself, not in the context of any TTY being emulated by any terminal program like xfce4-terminal.

make another script that runs your first script with stdout redirected to a file.  use >> instead of > so it appends to the file so you can see all the output.  assign this new script to a shortcut.  now, press the new shortcut a couple times and see if it created that file.

the 2nd script only needs one line:

sh zcode.sh >> zcode.out

if you always run the script with the "sh" command then you don't need the "#!/bin/sh" line in the script file and you don't need to set execute permission on the file.  this works with almost every script interpreter for it's own language.  i do that with python a lot.  and it runs in your home directory with a default path list that includes /bin.  try this script to see what is there:

exec &> look.out
pwd
env|sort

there are many things that scripts you can find have that only bash can do and sh cannot.  so you might want to switch to bash for your scripting if not one of the higher level scripting languages like lua, perl, or python (the one i use).

Last edited by Skaperen (2021-08-10 00:34:08)

Offline

#8 2021-08-28 05:46:52

manola
Member
Registered: 2021-08-09
Posts: 5

Re: script does not echo into desktop

I end up using Autokey

I modified a default script available

output = system.exec_command("date '+%Y%m%d%H%M%S'")
keyboard.send_keys(output)

So now I can use a hotkey on any program and I get my date code.

Maybe is an overkill but it works well and I think I can use these program for something else also.

Thanks for all the help!

Offline

#9 2021-08-28 16:35:20

Misko_2083
Member
Registered: 2015-10-13
Posts: 163
Website

Re: script does not echo into desktop

It's easiest to copy to clipboard, but install xclip first.

#!/bin/sh
date "+%Y%m%d%H%M%S" | xclip -selection clipboard

Then you can paste to terminal with ctrl+shift+v or ctrl+v to paste anywhere else.

Or paste with xdotool automatically:

#!/bin/sh
date "+%Y%m%d%H%M%S" | xclip -selection clipboard
xdotool key ctrl+v

Offline

#10 2021-08-28 18:00:49

manola
Member
Registered: 2021-08-09
Posts: 5

Re: script does not echo into desktop

That is a good one Misko. I want it to use the clipboard as an intermediary but I didn't knew about xclip.

I always try to use the leanest solution. On one side is xfce shortcuts, launcher, xclip, xdotool. And on the other autokey. I think your solution might be more minimal.

Offline

Board footer

Powered by FluxBB