Copy link to clipboard
Copied
Hello. I have made my script. It works fine on windows. When I decided to run it on a macbook, InDesign crashed immediately. I spent some time trying to find the cause.
I have two drop-down lists in my script. One shows all the fonts available in the system, and the other shows all its styles (regular, bold, italic, etc.). I don't know why, but on windows everything works fine, but on macbook m1 on macOS sequoia it doesn't want to work.
var GroupFont = panelTextTab.add("group");
GroupFont.orientation = "row";
GroupFont.add("statictext", undefined, "Font:");
// Getting an array of Font objects
var fontObjects = app.fonts.everyItem().getElements();
var uniqueFontNames = []; // Array for unique font names
// Collecting unique font families
for (var i = 0; i < fontObjects.length; i++) {
var fontFamily = fontObjects[i].fontFamily;
// Check if the font already exists in the array
var isFound = false;
for (var j = 0; j < uniqueFontNames.length; j++) {
if (uniqueFontNames[j] === fontFamily) {
isFound = true;
break;
}
}
if (!isFound) {
uniqueFontNames.push(fontFamily);
}
}
// Sort the array of fonts
uniqueFontNames.sort();
var defaultFontIndex = -1;
// Search for the DejaVu Sans index in the list of unique fonts
for (var i = 0; i < uniqueFontNames.length; i++) {
if (uniqueFontNames[i].indexOf("DejaVu Sans") !== -1) {
defaultFontIndex = i;
break;
}
}
var fontDropdown = GroupFont.add("dropdownlist", undefined, uniqueFontNames);
if (defaultFontIndex !== -1) {
fontDropdown.selection = defaultFontIndex;
} else {
fontDropdown.selection = 0;
alert("Шрифт 'DejaVu Sans' не знайдено в системі. Встановіть його та спробуйте ще раз.");
}
var GroupFontBold = panelTextTab.add("group");
GroupFontBold.orientation = "row";
GroupFontBold.add("statictext", undefined, "Style:");
var FontBoldDropdown = GroupFontBold.add("dropdownlist", undefined, []);
// Function to update the outline depending on the selected font
function updateFontStyles(selectedFont) {
var styles = [];
// Collect all outlines for the selected font family
for (var i = 0; i < fontObjects.length; i++) {
if (fontObjects[i].fontFamily === selectedFont) {
styles.push(fontObjects[i].fontStyleName);
}
}
// Sorting the styles
styles.sort();
// Clear the list
FontBoldDropdown.removeAll();
// Add new elements
for (var j = 0; j < styles.length; j++) {
FontBoldDropdown.add("item", styles[j]);
}
// Set the first element by default
if (styles.length > 0) {
FontBoldDropdown.selection = 0;
}
return styles; // Return an array of styles
}
// Initial filling of the outline for the default font
updateFontStyles(fontDropdown.selection.text);
fontDropdown.onChange = function() {
updateFontStyles(fontDropdown.selection.text);
if (previewCheckbox.value === true) {
updatePreview(previewCheckbox.value);
}
};
FontBoldDropdown.onChange = function() {
if (previewCheckbox.value === true) {
updatePreview(previewCheckbox.value);
}
};
No matter how hard I tried, I can't get the list of fonts and their styles to appear in two separate drop-down lists. Once I managed to get the list of all fonts, but they were with all styles at once, like this:
var GroupFont = panelTextTab.add("group");
GroupFont.orientation = "row";
GroupFont.add("statictext", undefined, "Шрифт:");
var fontObjects = app.fonts.everyItem().getElements();
var fontNames = [];
var defaultFontIndex = -1;
for (var i = 0; i < fontObjects.length; i++) {
fontNames.push(fontObjects[i].name);
if (fontObjects[i].name.indexOf("DejaVu Sans") !== -1) {
defaultFontIndex = i;
}
}
var selectedFontValue;
if (defaultFontIndex !== -1) {
selectedFontValue = fontObjects[defaultFontIndex].name; //Отримуємо точну назву шрифта
}
var fontDropdown = GroupFont.add("dropdownlist", undefined, fontNames);
if (defaultFontIndex !== -1) {
fontDropdown.selection = defaultFontIndex;
} else {
fontDropdown.selection = 0;
alert("Шрифт ʼDejaVu Sans' не знайдено в системі. Встановіть його та спробуйте ще раз.");
}
Maybe someone knows how to implement this on a Mac?
Okay, I think I've found a solution. I added the following check.
if (/[^a-zA-Z0-9\s]/.test(fontFamily)) {
continue;
}
But I'm not sure how stable it is?
Copy link to clipboard
Copied
What crashes? Whole InDesign or just script?
Do you have any error messages - script is crashing?
Try adding alerts() - with a line number or something - every few lines, so even if inDesing is crashing - you should get to the place where is the problem.
Copy link to clipboard
Copied
AdobeInDesign crashes. When I run the script, the application crashes immediately.
Copy link to clipboard
Copied
There are no errors, nothing. The program just closes and produces a ‘report’ that needs to be sent to Apple
Copy link to clipboard
Copied
There are no errors, nothing. The program just closes and produces a ‘report’ that needs to be sent to Apple
By @Mykyta22
Then add alerts in your code to track where is the problem.
Most likely - you have too many / corrupted / duplicated fonts on the Mac.
Copy link to clipboard
Copied
There was a recent discussion with the same kind of script. If this is not about homework, maybe borrow some code from there.
Anyway a script should not crash InDesign. Share the crash log (pastebin?) and provide a link here.
As you're dealing with fonts anyway, a bad font could be a reason. Disable user fonts by temporarily moving them somewhere else, then retry.
Copy link to clipboard
Copied
Okay, I did what you said. However, the problem is with the font. But how do I find it? I have 2000+ fonts on my system :\.
Copy link to clipboard
Copied
Okay, I did what you said. However, the problem is with the font. But how do I find it? I have 2000+ fonts on my system :\.
By @Mykyta22
You should change the way you work...
Do you always, in every document - need 2000+ fonts?
It's best to keep fonts used in the document - in the subfolder, next to your INDD document - Document Fonts.
Copy link to clipboard
Copied
Yes, that's one of the purposes of my script. I need to get a list of all system fonts
Copy link to clipboard
Copied
Yes, that's one of the purposes of my script. I need to get a list of all system fonts
By @Mykyta22
You don't have to install all fonts in the system to make a catalog of available fonts.
Copy link to clipboard
Copied
Okay, so what should we do?
Copy link to clipboard
Copied
Okay, so what should we do?
By @Mykyta22
Depends - do you have to do this on Mac?
If you really have - then maybe try in batches - each letter of the alphabet separately.
This would be kind of "divide and conquer" approach - and will let you find the problematic font - or file.
Copy link to clipboard
Copied
Okay, I think I've found a solution. I added the following check.
if (/[^a-zA-Z0-9\s]/.test(fontFamily)) {
continue;
}
But I'm not sure how stable it is?