Differences in JavaScript between ExtendScript (Adobe) and Switch

Post Reply
tbiagiotti
Newbie
Posts: 1
Joined: Fri Mar 01, 2013 7:23 pm

Differences in JavaScript between ExtendScript (Adobe) and Switch

Post by tbiagiotti »

I have this script working wonderfully in ExtendScript, and I am very new at trying to code for Switch. Could somebody help me in the translation between the two? Thanks in advance for your help.



It fixes an issue we have with JLYT files for HP Indigo.



Here is the ExtendScript version...





myFolder = new Folder("/Volumes/AUTOMAN/0_Print_Automation/JLYTs/1_In");

folderContents = myFolder.getFiles("*.jlt");

fileCount = folderContents.length;



for (i=0; i<fileCount; i++) {



someFile = File(folderContents);

someFile.encoding = "BINARY";

someFile.open('r');

var foo = someFile.read();

someFile.close();



var find = "/Fl /Cyclic" + String.fromCharCode(10) + "/Ft";

var regex = new RegExp(find, "g");



chgText = foo.replace(regex,"/Fl /Empty " + String.fromCharCode(10) + "/Ft");



someFile.open('w');

someFile.write(chgText);

someFile.close();



destFolder = new Folder("/Volumes/AUTOMAN/0_Print_Automation/JLYTs/2_Press");



destFile = destFolder + "/" + someFile.name;

someFile.copy (destFile);



someFile.remove();



}

dkelly
TOP CONTRIBUTOR
Posts: 628
Joined: Mon Nov 29, 2010 8:45 pm
Location: Alpharetta GA USA
Contact:

Differences in JavaScript between ExtendScript (Adobe) and Switch

Post by dkelly »

var myFolder = new Dir("/Users/dkelly/Desktop/1_In"); ///Volumes/AUTOMAN/0_Print_Automation/JLYTs/1_In");

var folderContents = myFolder.entryList("*.jlt", Dir.Files, Dir.Name);

var fileCount = folderContents.length;

for (var i=0; i<fileCount; i++) {

var fileName = myFolder.path + "/" + folderContents;

var foo = File.readByteArray(fileName);

var find = "/Fl /Cyclic" + String.fromCharCode(10) + "/Ft";

var regex = new RegExp(find, "g");

var chgText = foo.toString("UTF-8").replace(regex,"/Fl /Empty " + String.fromCharCode(10) + "/Ft");

foo = new ByteArray(chgText, "UTF-8");

File.writeByteArray(fileName, foo);

}





Dwight Kelly

Apago, Inc.
Post Reply