Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Selectable text from an alert dialog?

LEGEND ,
Feb 21, 2010 Feb 21, 2010

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.

TOPICS
Scripting
9.6K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 21, 2010 Feb 21, 2010

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

Harbs

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 21, 2010 Feb 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 21, 2010 Feb 21, 2010

Jong,

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

Harbs

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 21, 2010 Feb 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 21, 2010 Feb 21, 2010

So, prompt() uses editable text...that's pretty ugly. But more importantly, it doesn't work for multiline items of text.

(There's a certain irony here -- if it's short enough to work with prompt(), it was probably short enough that you didn't need to cut-and-paste it.)

Ctrl-C and Command-C do not appear to work in alert() dialog boxes under OSX.

Other ideas?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 21, 2010 Feb 21, 2010

It does work with multi-line text -- you just can't see it all...

Try this:

prompt('Hi','this is some really long text.\r we have quite a few lines here.\r let us see how this works if we want to copy and paste!');

Like I said it's a bit of a hack...

A Script UI EditText is probably more what you want.

Set the multiline and readonly properties to true, and that should be exactly what you are after...

(It's a bit more work though...)

Harbs

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Feb 21, 2010 Feb 21, 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 21, 2010 Feb 21, 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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Feb 21, 2010 Feb 21, 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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 21, 2010 Feb 21, 2010

OK, here is what I ended up with:

var long1="Eliquipit dolorem nummolo reetumsandit niam quis,\n"+
"nullums andiat lore. feugait am quis nullaor ad tat ilisim,\n"+
"acillan dionsed dunt augueraessim in ulputpa tumsandreet,\n"+
"illamet nullandre min eu faccum venim velese venibh,\n"+
"eraessisit ad ming ex etum nosto dionsectet, conseniam,\n"+
"irit praesto. consed estrud ex ea faci tatet in veni,\n"+
"ad tatumsa ndipsummodo ea facing esto dolenis ea acipsummy.";

function ealert(message, title, errorIcon) {
  var d = new Window('dialog', title);
  var msg = message.split("\n");

var icon = ScriptUI.newImage(
"/Applications/Adobe InDesign CS3/Adobe InDesign CS3.app/"+
"Contents/Frameworks/adobe_registration.framework/Versions/A/Resources/warning_icon.png"
);

  var f = d.graphics.font;

  d.top     = d.add("group"); d.top.orientation="row";
  d.left     = d.top.add("group", undefined);
  d.ico     = d.left.add('image', undefined, icon);
  d.right     = d.top.add("group", undefined); d.right.orientation="column";
  d.bold = d.right.add('statictext', undefined, msg[0]);
  d.bold.graphics.font = ScriptUI.newFont(f.name,ScriptUI.FontStyle.BOLD,f.size);
  d.rom     = d.right.add('edittext', undefined, msg.slice(1).join("\n"),
    {readonly:true, borderless: true, multiline: true, scrollable: false,
       });
  d.rom.graphics.font = ScriptUI.newFont(f.name,f.style,f.size-2);
  d.rom.alignment="fill";
  d.ok     = d.add("button", undefined, "OK", { name: "ok"});
  d.ok.alignment = "right";
 
  d.show();
}



ealert(long1, "myTitle");
alert(long1, "myTitle");

It's not quite what I wanted, but it's close. Compare the alert() output:

alert.png

to my script's ealert() output:

ealert.png

So that leaves me wondering:

1. How can I get InDesign's normal alert icon? I have the sense that if I knew what to refer to it as, I could use it. Does it have some kind of $ID/somethingorother name?

2. How can I get rid of the scrollbar and set the text background to grey? I get an error trying to set d.rom.graphics.backgroundColor.

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 22, 2010 Feb 22, 2010

You might want to (optionally) add: d.rom.active = true;

Harbs

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 22, 2010 Feb 22, 2010

I'm not sure why you care to replicate the alert dialog exactly, but you can try:

1) Do a screen capture to copy the alert icon (or recreate it yourself in Photoshop), and include it as a source. There's a trick that you can store the image in binary form within the script, and write that to file (if you care).

2) Play around with ScriptUIGraphics to color in the background and the scroll bar. (Way more effort than it's worth if you ask me...)

Harbs

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 22, 2010 Feb 22, 2010

Harbs. wrote:

You might want to (optionally) add: d.rom.active = true;

This doesn't seem to change anything. What am I missing?

I'm not sure why you care to replicate the alert dialog exactly, but you can try:

1) Do a screen capture to copy the alert icon (or recreate it yourself in Photoshop), and include it as a source. There's a trick that you can store the image in binary form within the script, and write that to file (if you care).

2) Play around with ScriptUIGraphics to color in the background and the scroll bar. (Way more effort than it's worth if you ask me...)

Well, I figured if it was worth taking any time to do it, might as well do it "right."

With respect to the icon, the ScriptUI documentation indicates that there are standard built-in resources for icons, and gives examples of what they are named in PhotoShop. But what are they in InDesign? (p.68 of javascript-tools_guide_cs3.pdf):

The scripting environment can define icon resources, which are available to scripts by name. To specify an
icon resource, set a control’s image property to the resource’s JavaScript name, or refer to the resource by
name when creating the control. For example, to create a button with an application-defined icon
resource:

myWin.upBtn = myWin.add ("iconbutton", undefined, "SourceFolderIcon");
Photoshop CS3, for example, defines these icon resources:
Step1Icon
Step2Icon
Step3Icon
Step4Icon
SourceFolderIcon
DestinationFolderIcon

I did play around with ScriptUIGraphics...like I said, I get an error:

d.rom.graphics.backgroundColor = d.rom.graphics.newBrush(d.rom.graphics.BrushType.SOLID_COLOR, [1,0,0,0])
Error: Cannot set backgroundColor property for this element type

I can't even figure out the syntax for setting the foregroundColor:

d.rom.graphics.newPen(d.rom.graphics.PenType.SOLID_COLOR, [1,0,0,1])
Error: Bad argument list

Oh, look! ColorPicker.jsx tells us there's a magic 3rd argument to newPen:

swatchGfx.newPen (swatchGfx.PenType.SOLID_COLOR, this.rgbValue, kSwatchBorderWidth);

Totally undocumented!

Changing the foregroundColor works, but isn't helpful. It was already black, as it should be. I'd like to get rid of the white background...

Shonky: thanks...nothing like the choice between the dubious language choice (embedding Applescript in Javascript) or the reluctance to modify the document's DOM (adding a textFrame). I need to take the religion out of scripting!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 22, 2010 Feb 22, 2010

This doesn't seem to change anything. What am I missing?

It selects the text, so it's just a matter or Command-C...

Harbs

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Feb 25, 2010 Feb 25, 2010

Harbs. wrote:

I'm not sure why you care to replicate the alert dialog exactly, but you can try:

1) Do a screen capture to copy the alert icon (or recreate it yourself in Photoshop), and include it as a source. There's a trick that you can store the image in binary form within the script, and write that to file (if you care).

2) Play around with ScriptUIGraphics to color in the background and the scroll bar. (Way more effort than it's worth if you ask me...)

Harbs

Hi Harbs,

Can you please show some sample code for converting image to binary and restoring to image using Indesign Javascript.

Thanks,

Shonky

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 22, 2010 Feb 22, 2010

Also, If you want to replicate the position of the icon, you should set the alignment to "top".


Harbs

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Sep 13, 2011 Sep 13, 2011

John Hawkinson wrote:

2. How can I get rid of the scrollbar and set the text background to grey?

Hi John,

If you set scrolling to false, the scrollbar disappears.

{readonly: true, borderless: true, multiline: true, scrolling: false});

Best regards,

AJ

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 13, 2011 Sep 13, 2011

This thread is almost 18 months old.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Sep 13, 2011 Sep 13, 2011

As I was searching the forum for something else regarding scrollbars, I found this thread - no solution for me, but I could add a simple answer on how to remove the scrollbar.

The age of the thread doesn't matter to anyone else but you. Even if you don't care any longer (you didn't have to answer at all, to show that), there might be other people looking to solve the same thing, and this forum is for sharing knowledge. I know I would have been happy to find out, had I been looking for this exact thing.

Please read and respect the "Forum etiquette and and best practices": http://forums.adobe.com/thread/414764

Best regards,

Andreas Jansson

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 25, 2015 Jun 25, 2015
LATEST

I for one found the whole thread and your amendment useful. Nearly four years later . .  .

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Feb 22, 2010 Feb 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 22, 2010 Feb 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Feb 22, 2010 Feb 22, 2010

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

Shonky

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines