• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: How to pre-fill a dialog input box from clipboard?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to pre-fill a dialog input box from clipboard?


  • Subject: Re: How to pre-fill a dialog input box from clipboard?
  • From: "Stockly, Ed via AppleScript-Users" <email@hidden>
  • Date: Fri, 27 May 2022 17:01:07 +0000
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=latimes.com; dmarc=pass action=none header.from=latimes.com; dkim=pass header.d=latimes.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=suNkgrFW5IHqRasPwxrLdJMZB92QsCrQwX0HTomVdT0=; b=BNecZ4m3YauGIoOLiKRnxj9bXnUy4hgXwNlKpfyL71OsJVegq9evreFaDYyHTwFZfvnpQHYoyWlIFel/1eaAdYfv6USol9gvGupbg6ARt23vMEUz6/opILGRodCky3y5rzMFDUqNNTTyKOQBag7FbxA3M8UqFCPorMh0Dw7YK7YQXtfEtf3FdHzTlT6G1FVYNsytOI4+2OiP7uaUnMeW47bK1JpYzA8IYjHdMlg9aJ8mevxjexRVzQ2vTzaauTNPGBfgzeaVO0Myy5k2JRGhfyxdmk9GOJXC6lSHruyFNmJQqYmPpM7eojMlbn0qcYM9uhuoPyvH/iNCnAxT5e7llw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gznCOXERE7Ddeic2R9uQ8ejX/nj2J0KbNDagqC4cjnr2joCxl49YMYbaYyLp3DdXepjA2Q7acbjQWVS8oPWApBGkfdZZWvyR4dzi8/UymLtZQ1/hrThVzwsfcTvPErnBhnM3xH8RF9WAmpMM1muF0Z9thdgenLAmHa6KzKahT+mhRvVtb6jA+YkSu3VYKQsYVLOM/gcmyCUePrOl1QM1E6hwda5fFxbIkHzxxArvL7RYHYuPEJBTMYCj7s5VNygZHdjx8gT5pIkKhDA9HNX+t3LPxBLxEipeJeGC4hb2Y5dSnE4seLIuhgfnTtsDncKLfVNfOXBOKcSXX/b6KFb7Lg==
  • Thread-topic: How to pre-fill a dialog input box from clipboard?

I found the same solution as you. It works for me without the first delay.
Perhaps it’s better if the tell system events is not inside the tell
application terminal block and/or the commands inside the system events block
are sent to the Terminal process.





use AppleScript version "2.4" -- Yosemite (10.10) or later

use scripting additions

use script "Dialog Toolkit Plus" version "1.1.2"

set theClipboard to the clipboard

set oldClipBoard to theClipboard

set accViewWidth to 650

set {theButtons, minWidth} to create buttons {"Cancel", "to English [⌘E]", "to
French [⌘F]"} button keys {"", "e", "f"} cancel button 1



if minWidth > accViewWidth then set accViewWidth to minWidth



set {the_phrase, theTop} to create field theClipboard placeholder text "Enter
your text here" bottom 0 field width accViewWidth extra height 60 with accepts
linebreak and tab



set {boldLabel, theTop} to create label "Enter the phrase you want to
translate, then click the destination language:" & return & return & "(Or, use
the command key shortcuts.)" bottom theTop + 20 max width accViewWidth control
size regular size



set {buttonName, controlsResults} to display enhanced window "Argos Translate"
acc view width accViewWidth acc view height theTop acc view controls
{the_phrase, boldLabel} buttons theButtons active field the_phrase initial
position {660, 330} with align cancel button



set {the_phrase} to controlsResults



set theClipboard to the_phrase

if buttonName contains "English" then

            set theScript to "argos-translate --from-lang fr --to-lang en "

else

            set theScript to "argos-translate --from-lang en --to-lang fr "

end if

--delay 0.5



tell application "Terminal"

            do script "" -- Open a new Terminal window.

            activate

end tell

            tell application "System Events"

                        tell process "Terminal"

                                    keystroke theScript

                                    delay 0.1

                                    keystroke "v" using command down

                                    delay 0.1

                                    keystroke return

                        end tell

            end tell

end tell

set the clipboard to oldClipBoard -- restores after change (optional)




From: AppleScript Digest <email@hidden>
Reply-To: "email@hidden" <email@hidden>
Date: Friday, May 27, 2022 at 9:48 AM
To: AppleScript Digest <email@hidden>
Subject: Re: How to pre-fill a dialog input box from clipboard?


EXTERNAL SOURCE
I found a solution to the keystroke problem.  Separating the command into
multiple lines and pasting the_phrase from the clipboard works.


(That’s probably why you need the first delay too)
Turns out the delay is still required.  Whether it's inside a tell block or
not, the command keys won't trigger the buttons properly without a slight delay.

In case anyone's interested, here's a working version:

use AppleScript version "2.4"
use scripting additions
use script "Dialog Toolkit Plus" version "1.1.0"

set accViewWidth to 650
set {theButtons, minWidth} to create buttons {"Cancel", "to English [⌘E]", "to
French [⌘F]"} button keys {"", "e", "f"} cancel button 1

if minWidth > accViewWidth then set accViewWidth to minWidth -- make sure
buttons fit

set {theField, theTop} to create field (the clipboard) placeholder text "Enter
your text here" bottom 0 field width accViewWidth extra height 60 with accepts
linebreak and tab

set {boldLabel, theTop} to create label "Enter the phrase you want to
translate, then click the destination language:" & return & return & "(Or, use
the command key shortcuts.)" bottom theTop + 20 max width accViewWidth control
size regular size

set {buttonName, controlsResults} to display enhanced window "Argos Translate"
acc view width accViewWidth acc view height theTop acc view controls {theField,
boldLabel} buttons theButtons active field theField initial position {660, 330}
with align cancel button

set {the_phrase} to controlsResults
delay 0.5 -- This is needed for the command keys above to work.
set the clipboard to the_phrase

tell application "Terminal"
activate
do script "" -- Opens a new Terminal window.

tell application "System Events"
if buttonName contains "English" then
keystroke "argos-translate --from-lang fr --to-lang en \""
keystroke "v" using command down
keystroke "\""
else
keystroke "argos-translate --from-lang en --to-lang fr \"" & the_phrase & "\""
end if
delay 0.1
keystroke return
end tell

end tell


One less thing to use Google for!  : )

Thanks to all who responded,
Marc

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Re: How to pre-fill a dialog input box from clipboard?
      • From: Jenni via AppleScript-Users <email@hidden>
References: 
 >How to pre-fill a dialog input box from clipboard? (From: Jenni via AppleScript-Users <email@hidden>)
 >Re: How to pre-fill a dialog input box from clipboard? (From: "Stockly, Ed via AppleScript-Users" <email@hidden>)
 >Re: How to pre-fill a dialog input box from clipboard? (From: Jenni via AppleScript-Users <email@hidden>)

  • Prev by Date: Re: How to pre-fill a dialog input box from clipboard?
  • Next by Date: Re: How to pre-fill a dialog input box from clipboard?
  • Previous by thread: Re: How to pre-fill a dialog input box from clipboard?
  • Next by thread: Re: How to pre-fill a dialog input box from clipboard?
  • Index(es):
    • Date
    • Thread