Script Help
I have two scripts that are just not working 100% of the time - namely I think on files that are converted.
Is there a better way to implement these scripts?
First Script
Check Embed - this should check if the file has all the links embedded when the file is saved - but it is not working all the time
#targetengine "session"
// Attach a listener to the beforeSave event
app.addEventListener("beforeSave", function (event) {
var doc = app.activeDocument;
// Get all the links in the document
var links = doc.links;
var unembeddedLinks = [];
// Loop through each link and check if it's embedded
for (var i = 0; i < links.length; i++) {
if (links[i].status != LinkStatus.LINK_EMBEDDED) {
unembeddedLinks.push(links[i]);
}
}
// If there are any unembedded links, prompt the user
if (unembeddedLinks.length > 0) {
// Create a message string with the number of unembedded links
var message = "There are " + unembeddedLinks.length + " unembedded links. Please ensure they are embedded before saving.";
// Display an alert dialog box to the user
alert(message);
}
});
Second Script
This is in the Startup Scripts folder - and it should check on opening a file if the slug is set to a minimum 130mm.
But it doesn't work on all files and I've noticed on files that are being converted.
#targetengine "session"
app.addEventListener("afterOpen", checkSlugBounds, false);
function checkSlugBounds(e) {
//set the script’s units to millimeters
app.scriptPreferences.measurementUnit = MeasurementUnits.MILLIMETERS;
//checks if the event’s parent is a Layout Window—the document is fully open
if (e.parent.constructor.name == "LayoutWindow") {
//the document is the layout window’s parent
var doc = e.parent.parent
var slugBounds = doc.documentPreferences.slugInsideOrLeftOffset;
if (slugBounds < 130) {
alert("The left slug area is less than 130mm.");
}
}
//reset units
app.scriptPreferences.measurementUnit = AutoEnum.AUTO_VALUE;
};
