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: Wed, 15 Nov 2017 19:12:26 -0800 Message-ID: <0a01cd57-4749-9021-e622-91437a602066@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: 7bit X-Trace: blaine.gmane.org 1510801988 956 195.159.176.226 (16 Nov 2017 03:13:08 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 16 Nov 2017 03:13:08 +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 Thu Nov 16 04:13:04 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 1eFAbs-0008Dv-QY for geh-help-gnu-emacs@m.gmane.org; Thu, 16 Nov 2017 04:13:00 +0100 Original-Received: from localhost ([::1]:38753 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eFAc0-0002O0-5z for geh-help-gnu-emacs@m.gmane.org; Wed, 15 Nov 2017 22:13:08 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:36147) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eFAbZ-0002Nv-Cz for help-gnu-emacs@gnu.org; Wed, 15 Nov 2017 22:12:42 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eFAbV-00043f-BZ for help-gnu-emacs@gnu.org; Wed, 15 Nov 2017 22:12:41 -0500 Original-Received: from c.mail.sonic.net ([64.142.111.80]:46646) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eFAbV-00040e-2d for help-gnu-emacs@gnu.org; Wed, 15 Nov 2017 22:12:37 -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 vAG3CRBH014481 (version=TLSv1.2 cipher=DHE-RSA-AES128-SHA bits=128 verify=NOT) for ; Wed, 15 Nov 2017 19:12:31 -0800 In-Reply-To: Content-Language: en-US X-Sonic-CAuth: UmFuZG9tSVZcaRREoUWk9K+vNAl56ZCcRY+836/qt4l9BUA4cMRKRVNiFKkd2z2ysbpzY4Aw8dpULSWfW3Gk7NuVVcVybNWb X-Sonic-ID: C;7JNM+XvK5xGKhYKfRUfeDw== M;wNnz+3vK5xGKhYKfRUfeDw== X-Sonic-Spam-Details: 0.0/5.0 by cerberusd 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:114893 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 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