• 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
How to pre-fill a dialog input box from clipboard?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Subject: How to pre-fill a dialog input box from clipboard?
  • From: Jenni via AppleScript-Users <email@hidden>
  • Date: Thu, 26 May 2022 21:48:53 -0700

        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

  • Follow-Ups:
    • 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: Axel Lüttgens via AppleScript-Users <email@hidden>
    • Re: How to pre-fill a dialog input box from clipboard?
      • From: Takaaki Naganoya via AppleScript-Users <email@hidden>
  • Prev by Date: Re: Waiting for the disk to Eject
  • Next by Date: Re: How to pre-fill a dialog input box from clipboard?
  • Previous by thread: Re: Waiting for the disk to Eject
  • Next by thread: Re: How to pre-fill a dialog input box from clipboard?
  • Index(es):
    • Date
    • Thread