Copy link to clipboard
Copied
Hi guys, I was hoping for a little help with a script to put in my startup folder - I want it to change the language of everything in the document to UK english.
This changes everything in tables to english:
myDoc.stories.everyItem().tables.everyItem().
cells.everyItem().texts.everyItem().
appliedLanguage="English: UK";
I need it to change the language in all paragraph boxes/stories as well. not sure how to make this happen:
However when I put it in a startup script like this
#target indesign
#targetengine "session"
var
myEventListener = app.eventListeners.item("loadstyles");
if (!myEventListener.isValid) {
myEventListener = app.addEventListener( "afterOpen", doJob );
myEventListener.name = "loadstyles";
}
function doJob() {
// Continue on with your code from here
myDoc.stories.everyItem().tables.everyItem().
cells.everyItem().texts.everyItem().
appliedLanguage="English: UK";
}
It doesn't seem to do anything.
any help would be greatly appreciated..... bonus points if you can tell me how to uncheck hyphenation on everything in the document as well
Well, your "myDoc" variable isn't defined anywhere I can look at. It's weird that you don't get a warning at startup with some "myDoc is undefined".
...function doJob(evt) {
// Continue on with your code from here
//Instantiating document and check if type is Document
//Otherwise exits
var myDoc = evt.parent;
if( !myDoc instanceof Document) return;
//Now that myDoc is a valid Document, we can go on…
myDoc.stories.everyItem().tables.everyItem().
cells.everyItem().texts.everyItem(
Copy link to clipboard
Copied
Well, your "myDoc" variable isn't defined anywhere I can look at. It's weird that you don't get a warning at startup with some "myDoc is undefined".
function doJob(evt) {
// Continue on with your code from here
//Instantiating document and check if type is Document
//Otherwise exits
var myDoc = evt.parent;
if( !myDoc instanceof Document) return;
//Now that myDoc is a valid Document, we can go on…
myDoc.stories.everyItem().tables.everyItem().
cells.everyItem().texts.everyItem().
appliedLanguage="English: UK";
//FWIW
/*
var fcgo = app.findChangeGrepOptions.properties,
fgp = app.findGrepPreferences.properties,
cgp = app.changeGrepPreferences.properties;
app.findGrepPreferences =
app.changeGrepPreferences =
app.findChangeGrepOptions = null;
app.findChangeGrepOptions.properties = {
includeHiddenLayers:true,
includeLockedLayersForFind:true,
includeLockedStoriesForFind:true,
includeMasterPages:true,
};
app.findGrepPreferences.properties = { findWhat:".+" };
app.changeGrepPreferences.properties = { appliedLanguage : app.languagesWithVendors.itemByID(80).name};
myDoc.changeGrep();
app.findChangeGrepOptions.properties = fcgo;
app.findGrepPreferences.properties = fgp;
app.changeGrepPreferences.properties = cgp;
*/
}
Copy link to clipboard
Copied
Many thanks Loic...
this changes the language inside tables on startup.... Now I also need it to change the language in all text boxes (or stories if applicable? basically text in the document)
If my document has no tables in it I get this:
An attached script generated the following error:
myDoc.stories.everyItem().tables.everyItem().cells.everyItem() is not a function
I guess I need to check if the document has tables somehow before running this line
Also on every document now I get this:
An attached script generated the following error:
Object does not support the property or method 'stories'
Do you want to disable this even handler?
I just click no to carry on. but it would be good to fix this
Copy link to clipboard
Copied
Now I also need it to change the language in all text boxes
replace your code with the one commented after //FWIW and you should be fine
Copy link to clipboard
Copied
Ah, thanks that works!!
However, I still needed it to remove hyphenation on everything, after some trial and error I stumbled upon a simpler method which does everything I need it to (also changes document defaults which is useful):
#target indesign
#targetengine "session"
var
myEventListener = app.eventListeners.item("loadstyles");
if (!myEventListener.isValid) {
myEventListener = app.addEventListener( "afterOpen", doJob );
myEventListener.name = "loadstyles";
}
function doJob(evt) {
var myDoc = evt.parent;
if( !myDoc instanceof Document) return;
try{
myDoc.stories.everyItem().tables.everyItem().
cells.everyItem().texts.everyItem().
hyphenation = false;
}
catch(e){}
try{
myDoc.stories.everyItem().texts.everyItem().
hyphenation = false;
}
catch(e){}
try{
myDoc.stories.everyItem().tables.everyItem().
cells.everyItem().texts.everyItem().
appliedLanguage = "English: UK";
}
catch(e){}
try{
myDoc.stories.everyItem().texts.everyItem().
appliedLanguage = "English: UK";
}
catch(e){}
with(myDoc.textDefaults){
try{
appliedLanguage = "English: UK";
}
catch(e){}
hyphenation = false;
}
}
I still have one niggly problem though, everytime I use a startup script like this and open a document I seem to get a similar error message, with my script above it says this:
"An attached script generated the following error:
Object does not support the property or method 'textDefaults'
Do you want to disable this even handler?"
And with your script when I was testing it always said this:
"An attached script generated the following error:
myDoc.changeGrep is not a function
Do you want to disable this even handler?"
In either case I just clicked 'No' and carried on with out a problem. Can I check 'don't show this message again' click 'No' and not have to worry about it again? or will it potentially cause problems for me later?
Thanks again!