• 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: Jenni via AppleScript-Users <email@hidden>
  • Date: Fri, 27 May 2022 09:47:58 -0700

        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: "Stockly, Ed 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>)

  • 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