LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-05-2009, 04:43 AM   #1
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
script output to x-window?


I'm looking for a way to send the output from a script or shell command into the currently-focused x-window; specifically so that I can "type" something automatically.

For example, I'd like to run a script from a hotkey while focused in the firefox text dialog I'm using now, and have the output print here.

So far, I've found I can use xdotool or xvkbd to "type" some text into x, like this:
Code:
#!/bin/bash

text_string="Foo to the bar to the bat"
 
xdotool type "$text_string"

#or

xvkbd -text "$text_string"

#xdotool seems to handle odd characters better than xvkbd.
When the script is run through a hotkey, either command will print the text into any X application, just like I want.

The problem is that both of them are very slow, especially when the text string is longer than just a sentence or two. They both print each character separately, which can take forever if the string is many paragraphs long.

Is there command that will do the same kind of thing, but print the text all at once, as if you were pasting it from the clipboard something? I've looked around but I haven't found any function like that.
 
Old 07-05-2009, 09:35 AM   #2
rjlee
Senior Member
 
Registered: Jul 2004
Distribution: Ubuntu 7.04
Posts: 1,994

Rep: Reputation: 76
You could look for software keyboard wedges or macro recorders. Why not just populate the clibpoard and then send a paste character?

Both Gnome and KDE follow http://standards.freedesktop.org/cli...boards-0.1.txt (also see http://www.xfree86.org/current/xclipboard.1.html)
 
Old 07-05-2009, 11:38 AM   #3
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Original Poster
Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
Yes, I know about how the clipboard and selection work. What I hope is to find some function or program that lets me send the output from the script/shell directly into the text area of another program, so that I hopefully won't need to go through them.

I'd already looked at xclipboard, and it doesn't seem to be able to do what I want. It only moves the data in the clipboard to and from a save buffer. It doesn't do any actual pasting, at least not as far as I can determine.

Most macro programs suffer from the same problem as in my first post. They "type" the text one character at a time. Besides, there are only a handful of macro recorders I know of for Linux; xmacroplay, which is too limited to use here, cnee, which has the above problem (I can't find any way to speed it up), and JW_Rrecord_Playback, which seems to be gui-only. Unless you know of another one that can "paste" selections all at once and can be used in a script, I don't think this is an option.

I've found the following workaround (which kind of does what you suggested). It copies the text to the x-selection and then uses xdotool to "press the button" and paste it. But again, I'd rather have something that works directly if I could find it.

Code:
#!/bin/bash

text_string="Foo to the bar to the bat"

echo "$text_string"|xsel -i 

xdotool click 2
 
Old 07-05-2009, 11:45 AM   #4
H_TeXMeX_H
LQ Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301
Personally, I think you may be trying to solve the problem in the wrong way. I've never had to do such a thing as paste output into a GUI program, there was always a simpler easier CLI way. Are you sure this is what you want ? Because I think it's gonna be messy and unreliable.
 
Old 07-05-2009, 12:00 PM   #5
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Original Poster
Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
Yes, this is what I need, because I'm trying to create an all-purpose launcher where, among other options, I can select and paste predefined text clips into any program. Kind of a permanent clipboard set, as it were.

Some of the better clipboard extenders on windows provide this function, but I haven't seen any good implementations of it on Linux.

Perhaps there are better ways to go about it program-wise, but at the moment I only know how to do shell-scripting. Maybe eventually in the future I'll know enough about some other language to implement it more efficiently.
 
Old 07-05-2009, 02:28 PM   #6
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,781

Rep: Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081
Quote:
Originally Posted by David the H. View Post
The problem is that both of them are very slow, especially when the text string is longer than just a sentence or two. They both print each character separately, which can take forever if the string is many paragraphs long.
xdotool has a --delay option, did you try lowering it?
Quote:
Originally Posted by http://www.semicomplete.com/projects/xdotool/xdotool
--delay milliseconds - Delay between keystrokes. Default is 12ms.
 
Old 07-06-2009, 04:20 AM   #7
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
My solution is a text file, email address phone number etc.
I open it on my desktop and copy and paste middle button.
simples!

i don't think you'll have much luck.
window managers apps, they can all grab the keyboard.

i don't think may app programmers will have predicted a future
when you come along and place an input procedure for your app
unless they are Philip K. Dick
 
Old 07-06-2009, 11:42 AM   #8
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Original Poster
Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
That's interesting. The Debian version of xdotool does not have a delay option. It's not listed in the man page and gives an "unknown command" error if I try to use it. I certainly would've been using it if it were there. Maybe it's a new function that hasn't made it here yet.

bigearsbilly, As I mentioned, I'm trying to replicate something I miss from my old Windows days. Cut and paste can get quite tedious, and what you do requires opening up a separate window to do it. Besides, this is just the first step. If I can get the basic stuff working satisfactorily I may go on to bigger and better, like a popup that allows me to edit the current contents of the clipboard before pasting.

Maybe there's something I can use, maybe not. But that's why I'm asking. There might have been something I missed. I don't see it as an unusual request. Why shouldn't there be tools for controlling output to x-window text areas? There are programs like xdotool and xdialog and macro recorders and such, why not something that handles text more directly? It can't be too difficult to do.

In any case, at the very least my xsel workaround will do for the time being.
 
Old 07-06-2009, 01:52 PM   #9
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,781

Rep: Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081
Quote:
Originally Posted by David the H. View Post
Why shouldn't there be tools for controlling output to x-window text areas? There are programs like xdotool and xdialog and macro recorders and such, why not something that handles text more directly? It can't be too difficult to do.
Unfortunately there is no such thing as an X window text area. There are only GTK text areas, QT text areas, XAW text areas, FLTK text areas, etc...

Quote:
The Debian version of xdotool does not have a delay option.
Yes, and the Debian version says:
Code:
       type something to type
           Types a series of letters. In order, as fast as possible.
So I guess there's no hope of making it faster.
 
Old 07-07-2009, 12:53 PM   #10
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Original Poster
Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
Ok, so my terminology is a bit off.

QT, GTK and such all run on x-windows, and take their text input from x, as opposed to the direct keyboard input used in terminal windows (I admit my understanding of how it all works is rather vague). Applications like xdotool, xvkbd, xmacro and such don't care if the program is QT or GTK or whatever, they simply tell x to simulate the regular keyboard input. Various programs and libraries written languages like C can also manipulate text input and output, I suppose by calling xlib or something. So if you can do all that, why can't you have a simple cli tool that uses x to send blocks of text straight from a shell to another program as well?

I was really only hoping that there might be something like a more advanced cli wrapper for xlib or something that I didn't know about, or maybe a way to call up another language like perl or python to do it (if they have that ability). Having to work through a one-character-at-a-time keyboard simulation just seems like an inefficient way to go about it.

Well, in any case, it looks like there's nothing available that does what I want, so I'm just going to have to live with what I have now. At least the "selection paste" solution I found gets around the speed problem.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Correct output from script appears only when script is run interactively kaplan71 Linux - Software 2 01-15-2009 11:47 AM
How to place the output of a script in a separate terminal window SBN Linux - General 2 12-27-2008 06:38 AM
Trying to launch a new term window while executing a bash script in that window sfmadmax Linux - Newbie 5 12-09-2007 01:34 PM
X Output to Terminal Window? PantherX Linux - Software 2 10-12-2006 12:09 PM
Redirect script output to log window in wxPython wapcaplet Programming 1 07-04-2004 08:59 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:42 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration