🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: adobe.scripting.indesign
Article #15355

Re: Entering unicode (JS)

#15355
From: Dave_Saunders
Date: Sat, 29 Nov 2003 13:58
75 lines
2972 bytes
This doesn't work

myText = "\\u" + "0254";
app.selection[0].contents = myText;

This works...

myText = "app.selection[0].contents = \"\\u" + "0254\"";
app.doScript(myText);

... but it's pretty bloody. Passing a text reference into a doScript is extremely messy, so this was made a lot easier by using the current selection. Reminiscent of using PageMaker's scripting language.

I was so sure this would work...

app.selection[0].contents = "\r";
myText = eval("\\u" + "0254");
app.selection[0].contents = myText;

...but eval is overly aggressive and tries to evaluate the resultant unicode character.

But this doesn't go far enough; you get the same as the first try:

myText = ("\\u" + "0254").toString();
app.selection[0].contents = myText;

I thought I was getting somewhere with this:

myText = eval(new String("\\u" + "0254"));
app.selection[0].contents = myText;

Now I'm starting to swear

myText = eval(new String("\\u" + "0254"));
app.selection[0].contents = myText.toString();

I thought maybe I was using eval in the wrong place, but no.

myText = "\\u" + "0254";
app.selection[0].contents = eval(myText);

This didn't work, either. There aren't many combinations left:

myText = eval(new String("\\u" + "0254"));
app.selection[0].contents = eval(myText);

Another failure:

myText = eval(new String("\\u" + "0254"));
app.selection[0].contents = eval((myText).toString());

and this doesn't work. It insists on trying to treat the result of the eval as the name of a variable.

myText = eval(new String("\\u" + "0254"));
app.selection[0].contents = "" + eval((myText).toString());

According to the JavaScript reference at DevEdge, String(myText) should return the same as myText.toString(), and this try seems to bear this out:

myText = eval(new String("\\u" + "0254"));
app.selection[0].contents = String(myText);

But things are different with this try...

myText = eval(new String("\\u" + "0254"));
app.selection[0].contents = String(eval(myText));

... this is the first time that the attempt to use eval didn't result in an error. Still got the wrong result though.

myText = eval(new String("\\u" + "0254"));
app.selection[0].contents = String("" + eval(myText));

I give up!

At least I found one solution, albeit inelegant.

Dave
Technical Details
Message-ID: <2ccea61e.0@webx.la2eafNXanI>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!eusc.inter.net!newsfeed01.sul.t-online.de!t-online.de!webx
References: <2ccea61e.-1@webx.la2eafNXanI>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f939a,cc26865e5febf839
X-Google-Attributes: gidf939a,public
X-Google-ArrivalTime: 2003-11-29 06:07:30 PST
From: Dave_Saunders@adobeforums.com
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!eusc.inter.net!newsfeed01.sul.t-online.de!t-online.de!webx
Newsgroups: adobe.scripting.indesign
Subject: Re: Entering unicode (JS)
Message-ID: <2ccea61e.0@webx.la2eafNXanI>
Date: Sat, 29 Nov 2003 05:58:04 -0800
References: <2ccea61e.-1@webx.la2eafNXanI>
Lines: 82
MIME-Version: 1.0
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit