Skip to main content
Inspiring
June 24, 2010
Question

[CS3 - JS - Mac] Problem with encoding

  • June 24, 2010
  • 2 replies
  • 571 views

Hi,

I made a script that perform a lot of actions on ID.

Everytime this script performs an action it writes a line on a global variable and at the end of the script write this var into a text file ( in the Document folder).

Yes, it's a log file...

While I was testing this script through the Toolkit everything went right.

Then I added a menu action inside the script to call the script from the application and something strange happened, in the log file (wich is a text file UTF8 encoding) and also in the alerts ID shows. Both display text from this:

"È necessario effettuare una selezione" (running the script from the toolkit)

to this:

"È necessario effettuare una selezione" (running the script from ID menu)

So I think it's an encoding problem...

I just added this code:

#targetengine "Lele";

var Lele_menu = app.menus.item("Main").submenus.add("Lele");


//     Menu

var main_action = app.scriptMenuActions.add("Update");

var main_event_listener = main_action.eventListeners.add("onInvoke", function(){main();});

var main_menu = Lele_menu.menuItems.add(main_action);


//     Functions
...
What's the point?
Hope you understood.
Thanks!
Lele

This topic has been closed for replies.

2 replies

Harbs.
Legend
June 24, 2010

try adding in: myFile.encoding = "UTF8";

Harbs

Inspiring
June 24, 2010

I had problems with UTF encoding so I use this function to write the log file:

var log_file = new File(file_path);

log_file.encoding = "UTF8";

log_file.lineFeed = "unix";

log_file.open("w");

log_file.write("\uFEFF" + text_var);

log_file.close();

Where text_var is the log string.

When it's written form the ESTK everything is right, when called from the menu it isn't.

It's strange that it also involves alert text innit?

Peter Kahrel
Community Expert
Community Expert
June 24, 2010

What probably happens is that though you enter the È with one keypress, in reality you end up with two characters. Not sure why you get different results from the ESTK and the script palette, but one remedy is to use unicode values for accented characters. È corresponds to \xC8 and \u00C8. So "\u00C8 necessario ..." would do the trick.

Peter

Inspiring
June 24, 2010

Thanks for the tip Peter,

but this thing is really weird... I don't understand why also the alert text has the same problem.

It looks like some application bug.

Lele