* Stumped by pasting to another application in linux
@ 2017-11-15 19:38 Bill Rising
2017-11-15 22:06 ` Emanuel Berg
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Bill Rising @ 2017-11-15 19:38 UTC (permalink / raw)
To: Emacs Listserv
[-- Attachment #1: Type: text/plain, Size: 2986 bytes --]
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?
Thanks,
Bill
Steps to duplicate problem, because the explanation above is likely not sufficient.
Here is hunh.sh---copy, paste, save it, make it executable.
---------------------------- cut here ----------------------------
#!/bin/bash
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 ()
(interactive)
(funcall interprogram-cut-function "Fighting with clipboards is no fun")
(shell-command "hunh.sh")
)
---------------------------- 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 hunh.sh from the place you're working
./hunh.sh
--> 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.
[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 3569 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Stumped by pasting to another application in linux
2017-11-15 19:38 Stumped by pasting to another application in linux Bill Rising
@ 2017-11-15 22:06 ` Emanuel Berg
2017-11-16 3:12 ` Kendall Shaw
2017-11-17 3:08 ` Kendall Shaw
2 siblings, 0 replies; 4+ messages in thread
From: Emanuel Berg @ 2017-11-15 22:06 UTC (permalink / raw)
To: help-gnu-emacs
Bill Rising wrote:
> 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. finally the paste of the text.
OK, so what application is it? Sure there isn't
a counterpart in Emacs which you not only can,
but *want* to migrate to, since it is probably
much better anyway and will solve all
integration issues implicitly?
If not, you can use this for X and Linux VTs
(if X is running at the same time):
http://user.it.uu.se/~embe8573/emacs-init/xsel.el
In the [M]ELPAs, there is an almost identical
file but that uses xclip instead xsel.
That makes sense, as xclip is a "command line
interface to X selections" while xsel is
a "command-line tool to access X clipboard" :)
--
underground experts united
http://user.it.uu.se/~embe8573
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Stumped by pasting to another application in linux
2017-11-15 19:38 Stumped by pasting to another application in linux Bill Rising
2017-11-15 22:06 ` Emanuel Berg
@ 2017-11-16 3:12 ` Kendall Shaw
2017-11-17 3:08 ` Kendall Shaw
2 siblings, 0 replies; 4+ messages in thread
From: Kendall Shaw @ 2017-11-16 3:12 UTC (permalink / raw)
To: help-gnu-emacs
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?
>
> Thanks,
>
> Bill
>
> Steps to duplicate problem, because the explanation above is likely not sufficient.
>
> Here is hunh.sh---copy, paste, save it, make it executable.
>
> ---------------------------- cut here ----------------------------
> #!/bin/bash
> 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 ()
> (interactive)
> (funcall interprogram-cut-function "Fighting with clipboards is no fun")
> (shell-command "hunh.sh")
> )
> ---------------------------- 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 hunh.sh from the place you're working
> ./hunh.sh
>
> --> 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.
Kendall
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Stumped by pasting to another application in linux
2017-11-15 19:38 Stumped by pasting to another application in linux Bill Rising
2017-11-15 22:06 ` Emanuel Berg
2017-11-16 3:12 ` Kendall Shaw
@ 2017-11-17 3:08 ` Kendall Shaw
2 siblings, 0 replies; 4+ messages in thread
From: Kendall Shaw @ 2017-11-17 3:08 UTC (permalink / raw)
To: help-gnu-emacs
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?
>
> Thanks,
>
> Bill
>
> Steps to duplicate problem, because the explanation above is likely not sufficient.
>
> Here is hunh.sh---copy, paste, save it, make it executable.
>
> ---------------------------- cut here ----------------------------
> #!/bin/bash
> 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 ()
> (interactive)
> (funcall interprogram-cut-function "Fighting with clipboards is no fun")
> (shell-command "hunh.sh")
> )
> ---------------------------- 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 hunh.sh from the place you're working
> ./hunh.sh
>
> --> 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 would like to know how this is happening. In any case, I thought of a
sort of hackish solution.
Here is revised hunh.sh:
======= cut here ===========
#!/bin/sh
trap go SIGUSR1
go()
{
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
exit 0
}
======= cut here ===========
And here is uh.sh:
======= cut here ===========
#!/bin/sh
pid=`ps -Chunh.sh -opid=`
kill -USR1 $pid
======= cut here ===========
Both hunh.sh and uh.sh are on the system path.
Run hunh.sh outside of emacs. It loops waiting to be interrupted.
Change the defun hunh to use uh.sh instead.
Essentially, this makes it so that emacs is not an ancestor process.
Kendall
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2017-11-17 3:08 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-11-15 19:38 Stumped by pasting to another application in linux Bill Rising
2017-11-15 22:06 ` Emanuel Berg
2017-11-16 3:12 ` Kendall Shaw
2017-11-17 3:08 ` Kendall Shaw
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.