[Extendscript] SaveDlg Default Filename Bugged
Hi there,
I'm having some issues with a custom extendscript that we use in our production house. This script is pretty basic, and is meant to make eps / pdf / ai conversion easier (we have some strict EPS settings that must be followed). This script has worked on AiCC (original release) up through CC 2019, but is now behaving oddly in Illustrator 2020.
When you run the script, a custom "Save As" dialog should show up. The filename should default to the current document's name, with .eps set as the filetype suffix. However, when running this script in Illustrator 2020, the filename field is ALWAYS defaulting to "Untitled.eps".
I've attached the script file for reference, along with two screenshots. One that shows how this script's save dialog looks in Illustrator 2019 (correct), and one that shows how this script's save dialog looks in Illustrator 2020 (incorrect).
It would be great if this was fixed. For reference, I have tested this code on MacOS Mojave 10.14.6 as well as MacOS Catalina 10.15.2. Both OS's result in the same behavior.
-
Kevin A. commented
Looks like this is still broken in Illustrator 2021.
In case anyone else comes across this thread, here's the workaround I've started using for our internal scripts. The gist is that we can use ScriptUI to create a custom input dialog for the filename, then launch a folder selection dialog to set the save location. Not the best since it's two modals folks have to click through, but it's still faster than manually keying in file names.
```
#target illustrator
#targetengine "main"function setFileName(currentDocName) {
var newName = currentDocName.split('.')[0];var fileNameInputWindow = new Window("dialog", "Save as...");
var fileNameForm = fileNameInputWindow.add("group");
fileNameForm.add("statictext", undefined, "Name:");
var fileNameTextField = fileNameForm.add("edittext", undefined, newName);
fileNameTextField.characters = 40;
fileNameTextField.active = true;
var confirmationButtons = fileNameInputWindow.add("group");
confirmationButtons.alignment = "right";
confirmationButtons.add("button", undefined, "Save", { name: "ok" });
confirmationButtons.add("button", undefined, "Cancel");
if (fileNameInputWindow.show() == 1) {
return fileNameTextField.text;
}
}function setSaveLocation() {
var parentDirectory = currentDocPath.toString();
parentDirectory = parentDirectory.substr(0, parentDirectory.lastIndexOf('/')) + "/";
parentDirectory = parentDirectory === '/' ? "~/" : parentDirectory;
var newDestination = Folder.selectDialog('Choose Save Location...', parentDirectory);
return newDestination;
}function createSaveFile(docName, destination, extension) {
var newName = '';
if (docName.indexOf('.') < 0) {
newName = docName + extension;
} else {
var dot = docName.lastIndexOf('.');
newName += docname.substring(0, dot);
newName += extension;
}return new File(destination + '/' + newName);
}function saveTheFile() {
var doc = app.activeDocument;
var extension = '.eps';var newDocName = setFileName(doc.name);
if (!newDocName) { return };var newDocLocation = setFolderLocation(doc.fullName);
if (!newDocLocation) { return };var savePath = createSaveFile(newDocName, newDocLocation, extension);
var saveOptions = new EPSSaveOptions;
saveOptions.compatibility = Compatibility.ILLUSTRATOR14;
doc.saveAs(savePath, saveOptions);
}saveTheFile();
``` -
Kevin A. commented
Hi there,
I'm having some issues with a custom extendscript that we use in our production house. This script is pretty basic, and is meant to make eps / pdf / ai conversion easier (we have some strict EPS settings that must be followed). This script has worked on AiCC (original release) up through CC 2019, but is now behaving oddly in Illustrator 2020.
When you run the script, a custom "Save As" dialog should show up. The filename should default to the current document's name, with .eps set as the filetype suffix. However, when running this script in Illustrator 2020, the filename field is ALWAYS defaulting to "Untitled.eps".
I've attached two screenshots that show the difference in behavior. One that shows how this script's save dialog looks in Illustrator 2019 (correct), and one that shows how this script's save dialog looks in Illustrator 2020 (incorrect).
It would be great if this was fixed. For reference, I have tested this code on MacOS Mojave 10.14.6 as well as MacOS Catalina 10.15.2. Both OS's result in the same behavior.
It appears that this form does not let you attach .jsx files, but I can provide the source file if needed (it seems to be a problem with the saveDlg() method specifically). Here is a basic example to test, though:
```
\#target illustrator
\#targetengine "main"function saveTheFile() {
var tmpFile = new File("~/Desktop/testFile.eps").saveDlg("Choose a save location:");
if (tmpFile == null) return;var saveOpts = new EPSSaveOptions;
saveOpts.compatibility = Compatibility.ILLUSTRATOR14;
app.activeDocument.saveAs(tmpFile, saveOpts);
}saveTheFile();