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

Packaging script working fine on local drive, but not on network drive

Community Beginner ,
Jul 29, 2020 Jul 29, 2020

Copy link to clipboard

Copied

Hi everyone. I've been trying to make a script to help generate a Document fonts folder in the same dirrectory as the .indd file.

 

The script does a package on the desktop in a temporary folder named with the date and time, to prevent any error of an existing folder with the same name. Then it checks if a Document font folder is present in the directory of the .indd file. If there is, it renames the folder by adding the current date and time (to prevent deleting anything). The script then waits for 3 seconds to prevent any problem caused by a delay in renaming on the NAS. Then the script creates a new Document fonts folder in the source directory, and copies every font present in the packaged Document font folder on the Desktop to it. Finally, the temporary package folder created on the desktop is emptied and deleted and the user is prompted that the script has done it's job.

 

The script works fine on a local drive, but we are all working on a NAS and the script fails to produce a package when the fource file is located on the NAS.  I can't figure out what's causing it to fail.

 

We are all working on macs and I have not taken in consideration a Windows environement in this script. We are connecting to the NAS trough AFP protocol. The machine this was tested on is using MacOs Mojave 10.14.6, and InDesign 15.0.1

 

I apologize for the messy script, I don't usually dive in this deep in scripting. I have experience in modifying existing script to adapt them to my needs. This script is kind of a Frankenstein's monster of multiple scripts I copied parts of.

 

So, here's the script:

var scriptName = "Collect Document fonts",
doc;

PreCheck();

//===================================== FUNCTIONS ======================================

function Main() {


var today = new Date();
var monthNum = today.getMonth()+1;
if(monthNum < 10){
var month = '0' + monthNum;
}else{
var month = monthNum;
}
var date = today.getFullYear()+'-'+month+'-'+today.getDate();
var hour = today.getHours();
var minute = today.getMinutes();
if(minute < 10){
var time = hour + 'h0' + minute;
}else{
var time = hour + 'h' + minute;
}
var dateTime = date + "_" + time;


function wait(ms){
var start = new Date().getTime();
var end = start;
while(end < start + ms) {
end = new Date().getTime();
}
}


var doc = app.activeDocument; 
var source = Folder(doc.filePath);
var desktopPath = "~/Desktop/package temporaire " + dateTime;
var fontPath = (desktopPath + "/Document fonts");

fontsFolder = new Folder(desktopPath);
if (!fontsFolder.exists) fontsFolder.create();


doc.packageForPrint(to = Folder(desktopPath), true, false, false, false, false, false, false);

var vieux = Folder(source + "/Document fonts");

if (vieux.exists) {
vieux.rename ("Document fonts (" + dateTime +")");
}

wait(3000);

var files = Folder(fontPath).getFiles();
var files_a = Folder(desktopPath).getFiles();
var destinationFolder = new Folder(source + "/Document fonts");
if (!destinationFolder.exists) destinationFolder.create();
for (var i = files.length; i >= 0; i--) {
var file = File(files[i]);
file.copy(destinationFolder.fsName + "/" + file.name)
file.remove();
}
for (var i = files_a.length; i >= 0; i--) {
var file_a = File(files_a[i]);
file_a.remove();

}
var lastFolder = Folder(desktopPath);
lastFolder.remove();


alert("Done!", scriptName);
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------
function PreCheck() {
if (app.documents.length == 0) ErrorExit("Please open a document and try again.", true);
doc = app.activeDocument;
if (doc.converted) ErrorExit("The current document has been modified by being converted from older version of InDesign. Please save the document and try again.", true);
if (!doc.saved) ErrorExit("The current document has not been saved since it was created. Please save the document and try again.", true);
Main();
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------
function ErrorExit(error, icon) {
alert(error, scriptName, icon);
exit();
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------

 

TOPICS
Scripting

Views

456

Translate

Translate

Report

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

correct answers 1 Correct answer

Advisor , Aug 05, 2020 Aug 05, 2020

Hello fr_brown,

 

The issue is you're losing the font resource forks for the fonts without an extention. This is happening in the copy method in your script as it's not copying the hidden .ds_store file that contains the resource forks. you can read more about the .ds_store file and resource forks in the link below.

https://lowendmac.com/2006/resource-forks-and-ds_store-files-on-non-mac-volumes/

 

I edited your sctript by adding a move method in place of the copy that will work on MacOs. I left the c

...

Votes

Translate

Translate
Community Expert ,
Jul 29, 2020 Jul 29, 2020

Copy link to clipboard

Copied

Sometimes fsName can give me trouble with servers. Perhaps someone else can explain the reason why, but try changing this line: 

file.copy(destinationFolder.fsName + "/" + file.name)

To:

file.copy(destinationFolder.absoluteURI + "/" + file.name)

 This thread may be relevant: https://community.adobe.com/t5/indesign/extendscript-oddity-with-file-folder-on-mac-os-x/td-p/388781...

Votes

Translate

Translate

Report

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
Advisor ,
Jul 29, 2020 Jul 29, 2020

Copy link to clipboard

Copied

Hello fr_brown,

 

Chek with you system administrator to ensure the correct permissions are setup to be able to rename the Documents fonts folder.  I tested you script on three different severs and it worked as expected on one but not the other two, that is what leads me to think it's a permission issue. On the two servers it seemed to work except for renaming the Documents fonts folder.

 

FYI: In the package For Print portion of your script you have the "ignorePreflightErrors" set to false. that will cancel the packaging silently when errors exist (A good example would be if your InDesign document  uses Adobe Fonts,  there would be preflight errors for Copyright-License issues). if you set it to true it will ignore preflight errors and continue with the packaging.

 

  you can get more info for the packageForPrint here:

https://www.indesignjs.de/extendscriptAPI/indesign-latest/#Document.html#d1e49241__d1e54464

 

 

Hope this helps!

 

Regards

Mike

 

Votes

Translate

Translate

Report

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 ,
Jul 30, 2020 Jul 30, 2020

Copy link to clipboard

Copied

Thanks, that was it! The package interupted itself because of the "ignorePreflightErrors" set to false. Now it works great! Thank you!

Votes

Translate

Translate

Report

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 ,
Jul 30, 2020 Jul 30, 2020

Copy link to clipboard

Copied

So, would you edit your script comment to show these 2 edit adjustments for final use?

Mike Witherell

Votes

Translate

Translate

Report

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 ,
Aug 05, 2020 Aug 05, 2020

Copy link to clipboard

Copied

I will, but I just dicovered a new problem with this script. 

Votes

Translate

Translate

Report

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 ,
Aug 05, 2020 Aug 05, 2020

Copy link to clipboard

Copied

I have an other weird bug with this one. Whenever the script copies a font file without an extention at the end of the file name, it copies a 0b file. The name is correct, and even the file icon seems ok, but the font file is empty. Manualy packaging the file seems to work fine however.

Votes

Translate

Translate

Report

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
Advisor ,
Aug 05, 2020 Aug 05, 2020

Copy link to clipboard

Copied

Hello fr_brown,

 

The issue is you're losing the font resource forks for the fonts without an extention. This is happening in the copy method in your script as it's not copying the hidden .ds_store file that contains the resource forks. you can read more about the .ds_store file and resource forks in the link below.

https://lowendmac.com/2006/resource-forks-and-ds_store-files-on-non-mac-volumes/

 

I edited your sctript by adding a move method in place of the copy that will work on MacOs. I left the code intact just commenting out what was used for the copy.

var scriptName = "Collect Document fonts",
doc;

PreCheck();

//===================================== FUNCTIONS ======================================

function Main() {


var today = new Date();
var monthNum = today.getMonth()+1;
if(monthNum < 10){
var month = '0' + monthNum;
}else{
var month = monthNum;
}
var date = today.getFullYear()+'-'+month+'-'+today.getDate();
var hour = today.getHours();
var minute = today.getMinutes();
if(minute < 10){
var time = hour + 'h0' + minute;
}else{
var time = hour + 'h' + minute;
}
var dateTime = date + "_" + time;


function wait(ms){
var start = new Date().getTime();
var end = start;
while(end < start + ms) {
end = new Date().getTime();
}
}


var doc = app.activeDocument; 
var source = Folder(doc.filePath);
var desktopPath = "~/Desktop/package temporaire " + dateTime;
// var fontPath = (desktopPath + "/Document fonts");
var myPackedFonts = Folder(desktopPath  + "/Document fonts");


fontsFolder = new Folder(desktopPath);
if (!fontsFolder.exists) fontsFolder.create();


doc.packageForPrint(to = Folder(desktopPath), true, false, false, false, false, true, false);

var vieux = Folder(source + "/Document fonts");

if (vieux.exists) {
vieux.rename ("Document fonts (" + dateTime +")");
}

wait(3000);

// var files = Folder(fontPath).getFiles();
var files_a = Folder(desktopPath).getFiles();
// var destinationFolder = new Folder(source + "/Document fonts");
// if (!destinationFolder.exists) destinationFolder.create();
// for (var i = files.length; i >= 0; i--) {
// var file = File(files[i]);
// file.copy(destinationFolder.fsName + "/" + file.name)
// file.remove();
// }

var myFontsAppleScript = 
'tell application "Finder"\r' +
'move POSIX file "' + myPackedFonts.fsName + '"  to POSIX file "' + source.fsName + '" with replacing\r' +
'end tell\r'
app.doScript(myFontsAppleScript, ScriptLanguage.applescriptLanguage);


for (var i = files_a.length; i >= 0; i--) {
var file_a = File(files_a[i]);
file_a.remove();

}
var lastFolder = Folder(desktopPath);
lastFolder.remove();


alert("Done!", scriptName);
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------
function PreCheck() {
if (app.documents.length == 0) ErrorExit("Please open a document and try again.", true);
doc = app.activeDocument;
if (doc.converted) ErrorExit("The current document has been modified by being converted from older version of InDesign. Please save the document and try again.", true);
if (!doc.saved) ErrorExit("The current document has not been saved since it was created. Please save the document and try again.", true);
Main();
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------
function ErrorExit(error, icon) {
alert(error, scriptName, icon);
exit();
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------

 

Hope this helps!

Regards,

Mike

 

Votes

Translate

Translate

Report

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 ,
Aug 06, 2020 Aug 06, 2020

Copy link to clipboard

Copied

LATEST

Yes!! Thank you! 

Votes

Translate

Translate

Report

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