Copy link to clipboard
Copied
I have a script that we use to approve artwork. Each AI file has a text frame called "Approvals". When we run the script, we put in the PO# that the art is approved for and it pastes a name/date/approval info stamp on the artboard.
Question is, how can I set an entry point to go to the last character of the text frame, force a carriage return, and start on the next line for each time the script is ran? That way, it doesn't delete previous approvals each time we add one.
Please help if you can - here is the script:
#target illustrator
function main() {
if (app.documents.length == 0) {
alert("Please have an 'Illustrator' document before running this script.");
return;
}
var docRef = app.activeDocument;
with (docRef) {
var ponumber = prompt("What PO's are you approving?", "Type PO here");
var thisDate = getTodaysDate();
var docName = name;
var userName = 'Tim Johnson'; // Change each users name here
// if (saved == false) save();
var filePath = path;
try {
var frameA = textFrames.getByName('Approvals');
frameA.contents = thisDate + ' - ' + userName + ' approved for production for the following orders: ' + ponumber;
} catch (e) {
alert('Cannot find the Approvals text box')
}
}
}
main();
function getTodaysDate() {
var today = new Date();
var dd = today.getDate();
if (dd < 10) {dd ='0' + dd};
var mm = today.getMonth() + 1;
if (mm < 10) {mm ='0' + mm};
var yyyy = today.getFullYear();
var thisDate = mm + '.' + dd + '.' + yyyy;
return thisDate;
}
Copy link to clipboard
Copied
Changing your try catch part to…
try { var frameA = textFrames.getByName('Approvals'); var preApp = frameA.contents; frameA.contents = preApp + thisDate + ' - ' + userName + ' approved for production for the following orders: ' + ponumber + '\r'; } catch (e) { alert('Cannot find the Approvals text box') }
Store the previous contents into a variable then concat the lot back… The '\r' should give you a new line after each run to add to…
Copy link to clipboard
Copied
This is perfect. Thank you very much!!
Find more inspiration, events, and resources on the new Adobe Community
Explore Now