From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Kendall Shaw Newsgroups: gmane.emacs.help Subject: Re: Stumped by pasting to another application in linux Date: Thu, 16 Nov 2017 19:08:30 -0800 Message-ID: <0702c5aa-6876-2dc5-5a0a-0fd0e88ab8dc@kendallshaw.com> References: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1510888153 30983 195.159.176.226 (17 Nov 2017 03:09:13 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 17 Nov 2017 03:09:13 +0000 (UTC) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Nov 17 04:09:06 2017 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eFX1Y-0007D5-DY for geh-help-gnu-emacs@m.gmane.org; Fri, 17 Nov 2017 04:09:00 +0100 Original-Received: from localhost ([::1]:43710 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eFX1f-0007qN-Ks for geh-help-gnu-emacs@m.gmane.org; Thu, 16 Nov 2017 22:09:07 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:44021) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eFX1D-0007q7-Rr for help-gnu-emacs@gnu.org; Thu, 16 Nov 2017 22:08:40 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eFX19-0008Su-QX for help-gnu-emacs@gnu.org; Thu, 16 Nov 2017 22:08:39 -0500 Original-Received: from c.mail.sonic.net ([64.142.111.80]:46432) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eFX19-0008SA-HM for help-gnu-emacs@gnu.org; Thu, 16 Nov 2017 22:08:35 -0500 Original-Received: from [192.168.1.73] (108-64-77-57.lightspeed.sntcca.sbcglobal.net [108.64.77.57]) (authenticated bits=0) by c.mail.sonic.net (8.15.1/8.15.1) with ESMTPSA id vAH38UMU028299 (version=TLSv1.2 cipher=DHE-RSA-AES128-SHA bits=128 verify=NOT) for ; Thu, 16 Nov 2017 19:08:30 -0800 In-Reply-To: Content-Language: en-US X-Sonic-CAuth: UmFuZG9tSVbhiUl8Y2QMD/0vgTntR4mDIaYKU6gySGNGMrA8CzzaKm08662yhU5AOGvqQT1HLJM7TEed7GjkiDYePm7rvKmy X-Sonic-ID: C;sqyxlkTL5xGN5oKfRUfeDw== M;aGrtlkTL5xGN5oKfRUfeDw== X-Sonic-Spam-Details: 0.0/5.0 by cerberusd X-MIME-Autoconverted: from 8bit to quoted-printable by c.mail.sonic.net id vAH38UMU028299 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 64.142.111.80 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:114924 Archived-At: 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 applicati= on by using a shell script called by Emacs, followed by a Return. [This i= s for entering a command in another application.] > > Problem: A shell script using automation tools (to simulate typing) whi= ch 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 comm= and 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 ot= her 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 tri= p 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 s= cript? > > 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 f= un") > (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 deleti= ng, 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=20 sort of hackish solution. Here is revised hunh.sh: =3D=3D=3D=3D=3D=3D=3D cut here =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D #!/bin/sh trap go SIGUSR1 go() { =A0 xdotool search --name --onlyvisible "gedit" windowactivate =A0 # select text to replace =A0 xdotool key ctrl+a =A0 # paste in the clipboard =A0 xdotool key ctrl+v =A0 # do stupid stuff before finally hitting Return, so that it's clear =A0 #=A0=A0=A0 that the paste (ctrl-v) gets misplaced =A0 xdotool key space space h u n h =A0 sleep 1 =A0 xdotool key BackSpace BackSpace BackSpace BackSpace BackSpace BackSp= ace =A0 sleep 1 =A0 xdotool key Return =A0 exit 0 } =3D=3D=3D=3D=3D=3D=3D cut here =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D And here is uh.sh: =3D=3D=3D=3D=3D=3D=3D cut here =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D #!/bin/sh pid=3D`ps -Chunh.sh -opid=3D` kill -USR1 $pid =3D=3D=3D=3D=3D=3D=3D cut here =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Both hunh.sh and uh.sh are on the system path. Run hunh.sh outside of emacs. It=A0 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