[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Stumped by pasting to another application in linux

From: Kendall Shaw
Subject: Re: Stumped by pasting to another application in linux
Date: Wed, 15 Nov 2017 19:12:26 -0800
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0

On 11/15/2017 11:38 AM, Bill Rising wrote:
Hi all,

I've been getting very vexed by the following.

Goal: Take the clipboard contents and paste them into another application by 
using a shell script called by Emacs, followed by a Return. [This is for 
entering a command in another application.]

Problem: A shell script using automation tools (to simulate typing) which works 
from a Terminal window acts goofy when called by Emacs, because all paste 
actions happen only after the Emacs function has completed, so the Return 
precedes the pasting. [Negating the value of entering the command from Emacs.]

I put steps to illustrate the problem below.

The simplified example uses -xdotool-, but I had the same problem when using 
-xte-. The example pastes into gedit, but the problem exists for other 
applications as well. Finally, I tried both (shell-command) and 
(call-process-shell-command) and tried all possible settings of 
select-enable-clipboard and select-enable-primary, all to no avail. If only I 
could trip the paste before the Return, I would be happy.

FWIW, I've tried such things as shell-scripts calling shell-scripts and emacs 
functions calling emacs functions, but all I can get is having the paste happen 
at the very end. I'm clearly very lost.

Any ideas about how to get the paste to happen when it happens in the script?



Steps to duplicate problem, because the explanation above is likely not 

Here is, paste, save it, make it executable.

---------------------------- cut here ----------------------------
xdotool search --name --onlyvisible "gedit" windowactivate

# select text to replace
xdotool key ctrl+a
# paste in the clipboard
xdotool key ctrl+v
# do stupid stuff before finally hitting Return, so that it's clear
#    that the paste (ctrl-v) gets misplaced
xdotool key space space h u n h
sleep 1
xdotool key BackSpace BackSpace BackSpace BackSpace BackSpace BackSpace
sleep 1
xdotool key Return
---------------------------- cut here ----------------------------

Here is in hunh.el. Copy it, paste it, save it as hunh.el, then load it in Emacs

---------------------------- cut here ----------------------------
(defun hunh ()
   (funcall interprogram-cut-function "Fighting with clipboards is no fun")
   (shell-command "")
---------------------------- cut here ----------------------------

Be sure that you have xdotool.

Assuming you have it, open a single window for gedit.

Type a bunch of garbage in the gedit window so that it can get replaced later.

Run the script from the place you're working

--> Everything will work fine, with the text being replaced, some extra typing 
and deleting, and then a Return.

Start emacs

Within emacs, load hunh.el, then run its one function
   M-x hunh

--> The text in gedit will be replaced with the extra typing and deleting, then 
a Return, and finally the paste of the text.

I see the same thing that you are describing.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]