Skip to main content
John Hawkinson
Inspiring
February 21, 2010
Question

Selectable text from an alert dialog?

  • February 21, 2010
  • 5 replies
  • 10698 views

Javascript InDesign CS3 on a Mac, if that matters.

I took a quick look through the ScriptUI docs and couldn't find a widget for this, but maybe I missed it.

I'd like to display some alert text from a script and have the text in the alert dialog be cut-and-pasteable by the user. Is there an easy way to do this?

I'd really rather not have the text be editable-in-the-dialog by the user (looks ugly), and I'm absolutely happy with the quick-and-dirty interface of alert() -- that is, just passing a long string with internal newlines, and not having to spend much time mucking around with ScriptUI and dialog properties and layouts and layout managers, etc., etc.

Anyhow, is there a good way to do this? (I suppose I could pop up a dialog using AppleScript, but that really seems like the wrong answer...)

Thanks.

This topic has been closed for replies.

5 replies

Inspiring
February 22, 2010

Shonkyin wrote:

app.select(tf.texts)
app.copy();
Oh! I misunderstood you completely! Very clever, yes. Somehow I'd prefer to avoid that, because it's non-intuitive for my users, but it's certainly a good trick.

I know that you finished your new ealert but here is code without inserting and removing text frame.

var hello = 'Hello World!'

result  = confirm (hello + '\r\r\r Copy result...')

if (result == 1)

{

var myAppleScript = "tell application \"Finder\"\rset the clipboard to \"" + hello +"\"\rend tell";

app.doScript(myAppleScript, ScriptLanguage.applescriptLanguage);

}

Shonky

Harbs.
Legend
February 22, 2010

For that matter, you can skip the confirm altogether!

Just run that AS with the text you feed to the standard alert!

Harbs

Inspiring
February 22, 2010

confirm is just becuase user have choice of copy result or not.

Shonky

John Hawkinson
Inspiring
February 22, 2010

Harbs, the readonly property of EditText is what I was looking for, I hadn't found that. That makes EditText acceptable, thanks! (I'm still struggling to get this right, but I'll post my reslult in a bit).

Shonky, confirm() doesn't seem to work under OSX for this. Perhaps it's like Ctrl-C in alert()  -- Windows only?

Inspiring
February 22, 2010
confirm() working on OSX. I am also using OSX.
Use below code:
var hello = 'Hello World'
result  = confirm (hello + '\r\r\r Copy result...')
if (result == 1)
{
   var tf = app.activeDocument.textFrames.add (
      {
      geometricBounds: [0,0,100,100],
      contents: hello}
      );
app.select(tf.texts)
app.copy();
tf.remove()
}
Shonky
Inspiring
February 22, 2010

Hi,

You can also use confirm(). See attached screen shot.

copy your text on click Yes and continued your script, if click on No then continued without copy text.

Shonky

Jongware
Community Expert
Community Expert
February 21, 2010

That's already in InDesign! Press Ctrl/Cmd+C when an alert is on screen, and you can paste its text where you want.

Harbs.
Legend
February 21, 2010

Jong,

Is that a Windows thing? I just tried that and I couldn't get it to work...

Harbs

Peter Kahrel
Community Expert
Community Expert
February 21, 2010

It works on Windows -- didn't know that either. But you get everything: dialog title followed by a dashed line followed by the alert text, followed by another dashed line, folloed by "OK". So your prompt-trick is probably neater.

Peter

Harbs.
Legend
February 21, 2010

An easy hack is to use prompt() instead of alert()

Harbs