Skip to main content
Participant
May 3, 2023
Answered

Script not working inDesign v17 2022 & v18 2023

  • May 3, 2023
  • 2 replies
  • 818 views

Hi everyone,

I have a script that is setup in Indesign V16 (2021) - have saved it as a PDF to link here for you to see it. - it's a .jsx file normally, have also tested with a .js file too

It's located in the following path on MacOS: Users/[username]/Library/Preferences/Adobe InDesign/[version]/[language]/Scripts

In a created folder called Startup Scripts

 

The script works perfectly in v16 2021, it creates a txt file when someone opens a indesign file with the name of the user.

 

I've installed V17 2022 & v18 2023 of Indesign the same script in the updated path for the new versions but it doesnt' seem to do anythign now, no txt file opened, not seeing any error when opening the document or anything?

 

Does anyone have any ideas why, 

Thanks

This topic has been closed for replies.
Correct answer Laubender

Hi @Martin25172117wegi ,

if there is an error you'll get no error message because your try/catch statements will lead to nothing.

So currently you cannot know what's going wrong.

 

Hm. Could it be that you open InDesign documents from a previous version of InDesign? Then you'll open them as unsaved, converted documents that have no file paths yet and doc.fullName in the code will fail.

 

Regards,
Uwe Laubender
( Adobe Community Expert )

2 replies

LaubenderCommunity ExpertCorrect answer
Community Expert
May 3, 2023

Hi @Martin25172117wegi ,

if there is an error you'll get no error message because your try/catch statements will lead to nothing.

So currently you cannot know what's going wrong.

 

Hm. Could it be that you open InDesign documents from a previous version of InDesign? Then you'll open them as unsaved, converted documents that have no file paths yet and doc.fullName in the code will fail.

 

Regards,
Uwe Laubender
( Adobe Community Expert )

Participant
May 3, 2023

Uwe, thank you so much, seems so obvious now, but yes, it was converting the file and hadn't been resaved.

Having go through that stsage, closing & reopening the newly saved indesign file and bingo the script was working as before.

 

Thank you so much

Participant
May 3, 2023
Here's the txt from script if pdf isn't any good
 
#targetengine "preventMultipleOpens"
 
var eventListenerOpen = app.addEventListener("afterOpen", createTxtFile);
var eventListenerClose = app.addEventListener("beforeClose", deleteTxtFile);
var userName = (app.userName != "Unknown User Name") ? app.userName : "unknown user";
 
function customAlert(message, delaySeconds, title) {
 
    title = title || 'Alert';
    var alertWindow = new Window('palette', title);
    var control_text = alertWindow.add('edittext', [0, 0, 400, 100], message, {multiline: false});
   
    if(delaySeconds == 0){
        var control_close = alertWindow.add('button', undefined, 'Close');       
        control_close.onClick = function(){
            if(alertWindow){
alertWindow.hide();
app.activeDocument.close();
            }
        };
    }
 
    alertWindow.show();
    alertWindow.update();
 
    if(delaySeconds > 0){
        $.sleep(delaySeconds * 1000);
        alertWindow.hide();
        alertWindow = null;
    }
}
 
function createTxtFile(event) {
try {
var doc = event.parent;
var txtFilePath = decodeURI(doc.fullName.absoluteURI.replace(/indd$/i, "txt"));
if (txtFilePath != null) {
var txtFile = new File(txtFilePath);
txtFile.encoding = "UTF-8";
 
if (!txtFile.exists) {
txtFile.open("w");
txtFile.write(userName);
txtFile.close();
}
else {
txtFile.open("r"); 
var userNameSaved = txtFile.read();
txtFile.close();
 
if (userNameSaved != userName) {
customAlert('This Document is already opened by ' + userNameSaved, 0, 'Warning!');
}
}
}
}
catch(err) {}
}
 
function deleteTxtFile(event) {
try {
var doc = event.parent;
var txtFilePath = decodeURI(doc.fullName.absoluteURI.replace(/indd$/i, "txt"));
 
if (txtFilePath != null) {
var txtFile = new File(txtFilePath);
 
if (txtFile.exists) {
txtFile.open("r"); 
var userNameSaved = txtFile.read();
txtFile.close();
 
if (userNameSaved == userName) {
txtFile.remove();
}
}
}
}
catch(err) {}
}

 

Robert at ID-Tasker
Legend
May 3, 2023

On some versions of the Mac OS you need to give extra permissions to the folder(s) ? 

 

Participant
May 3, 2023

Thanks for your suggestion sorted with Uwe suggestion below