Re: How to pre-fill a dialog input box from clipboard?
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 16:03:54 +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=34ClMJOvdFUrgvlSrSQIMpUNdjTtdp4dBSKaI2qCCcw=; b=EZyGYUB6llEyBrhCx7eTaVCqqsK3yAC/KYLcMY3whkh+g6PxnH0oR8b4n7dJFPS1MOLyn+W9T7Skqaoh7effdIqKU/Oz8Mi4USKI4m2A4JfaPrzWvL8ZXpnw8fOwHGyadWg3khPe70hTJr0yXPXnxKeyKFbMKQnxVnY6gomHpv1c1L96HO8JnpqeTkMJsCxakXc+64DRMz7eCrM4mVRqW+GmzanUIVeICfghnJ9NqPHZ3qUVLWoW0SDVVD/FAXfGr11O7THwysHdEaLmYyCK7NQw/uAqzE240I5d+CUv5FnflPMNhpsSz7kW853Ejq5zgC41bGaduBEsnYJESSAkgA==
- Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mIOtp+ak8prduS16MKXpNJbQNjxr51RZ81lBVNE7T5f6ulHQ7XNpS+HD4xZo3fn6fV7F7G5ObR0RBsyjxbanuHdAy9531BtA8MRbaPeNer+se53ImBPQUaR+imsJ7bqVfvijqVV8XBC1e+0nkzMXrsOQbGqF73Nj6njP/uWULrXoto4z6VYqO4g2jr2akaoj8lrhXzjonq0xZE4JUbQvtHxYOcGho4YpSOB/uPRfT93wW5HT2o0ymOvxdYN5oQ2zNVp4Wd4fsMcWIg84JIJ6/PX9NpPyEXi8EcTAWHFkZEgmQ0mvktmAoEuLV6koruA7Nc/Z55uWA9a6dIJFINuzgg==
- Thread-topic: How to pre-fill a dialog input box from clipboard?
I think the delay is coming from sending the clipboard command from within the
tell application Terminal block. (That’s probably why you need the first delay
too)
Also, is Terminal even required? Below I added a “do shell script” to the end
of the script. Try commenting out the terminal block and see if that works for
you.
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 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
--tell application "System Events" to keystroke "v" using command down
--set {the_phrase} to the clipboard
set {the_phrase} to controlsResults
if buttonName contains "English" then
set theScript to "argos-translate --from-lang fr --to-lang en \"" &
the_phrase & "\""
else
set theScript to "argos-translate --from-lang en --to-lang fr \"" &
the_phrase & "\""
end if
--delay 0.5 -- This is needed for the command keys above to work.
tell application "Terminal"
do script "" -- Open a new Terminal window.
activate
tell application "System Events"
keystroke theScript
delay 0.1
keystroke return
end tell
end tell
set translation to do shell script theScript
From: AppleScript Digest <email@hidden>
Reply-To: "email@hidden" <email@hidden>
Date: Thursday, May 26, 2022 at 9:49 PM
To: AppleScript Digest <email@hidden>
Subject: How to pre-fill a dialog input box from clipboard?
EXTERNAL SOURCE
I've written a little script that creates a dialog box to enter text to be
translated into another language using the Argos Translator script on GitHub.
It works well. But then I thought it would be nice to have the dialog box
input field be automatically populated with any text already on the clipboard,
but I can't get it to work.
Here's what I have:
use AppleScript version "2.4"
use scripting additions
use script "Dialog Toolkit Plus" version "1.1.0"
tell application "Terminal"
activate
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 "" 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
--tell application "System Events" to keystroke "v" using command down
--set {the_phrase} to the clipboard
set {the_phrase} to controlsResults
delay 0.5 -- This is needed for the command keys above to work.
do script "" -- Open a new Terminal window.
activate
tell application "System Events"
if buttonName contains "English" then
keystroke "argos-translate --from-lang fr --to-lang en \"" & the_phrase & "\""
else
keystroke "argos-translate --from-lang en --to-lang fr \"" & the_phrase & "\""
end if
delay 0.1
keystroke return
end tell
end tell
Neither pasting into, nor setting the field, work (see the commented out
lines). Is this possible to do?
Thanks,
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