File SaveDIALOG
Copy link to clipboard
Copied
I am using the following code to open the FileSaveAs Dialog
Explore related tutorials & articles
Copy link to clipboard
Copied
Try using this little code
try{executeAction( charIDToTypeID('save'), undefined, DialogModes.ALL );}catch(e){}
Copy link to clipboard
Copied
if ( File.fs == "Windows" ) {
saveFile = File.saveDialog( "Pick an XML file to save", "XML Files: *.xml" );
} else {
saveFile = File.saveDialog( "Pick an XML file to save", MacXMLFilter );
}
function MacXMLFilter( f )
{
var xmlExtension = ".xml"; // replace with .txt
var lCaseName = f.name;
lCaseName.toLowerCase();
if ( lCaseName.indexOf( xmlExtension ) == f.name.length - xmlExtension.length )
return true;
else if ( f.type == 'TEXT' )
return true;
else if ( f instanceof Folder )
return true;
else
return false;
}
Replace ".xml" with ".txt"
Copy link to clipboard
Copied
Mr. r-bin on mac doesn't work.
Copy link to clipboard
Copied
Yes, parenthesis missing 🙂
if ( File.fs == "Windows" ) {
saveFile = File.saveDialog( "Pick an XML file to save", "XML Files: *.xml" );
} else {
saveFile = File.saveDialog( "Pick an XML file to save", MacXMLFilter );
}
function MacXMLFilter( f )
{
var xmlExtension = ".xml"; // replace with .txt
var lCaseName = f.name;
lCaseName.toLowerCase();
if ( lCaseName.indexOf( xmlExtension ) == f.name.length - xmlExtension.length )
return true;
else if ( f.type == 'TEXT' )
return true;
else if ( f instanceof Folder )
return true;
else
return false;
}
Copy link to clipboard
Copied
Mr. r-bin
the save as window opens
just that no file extension comes out?
Copy link to clipboard
Copied
Same here, the save as dialog shows but no extension.
I think this is a MAC feature to be honest after further reading.
Copy link to clipboard
Copied
Have you tried this
it works on my mac
try{executeAction( charIDToTypeID('save'), undefined, DialogModes.ALL );}catch(e){}
Copy link to clipboard
Copied
Yes that does work although it does not offer txt file as the Format
Copy link to clipboard
Copied
Ian, hello, I'm no coder, but it seems that Catalina changed some stuff related to the file extensions
Copy link to clipboard
Copied
I added missing closing curly brace to your previous.
Copy link to clipboard
Copied
Any update on this? I'm having this exact same problem...
Copy link to clipboard
Copied
I believe that you'll need to:
(1) Use scriptUI to code your own dialog with other supporting code for unsupported Save As/Save a Copy file formats
(2) Use native operating system UI elements such as prompt() and Folder.selectDialog() and other supporting code for unsupported Save As/Save a Copy file formats
Example here:
Copy link to clipboard
Copied
For now, I ended up doing this:
// Detects the operating system
function detectOS() {
var userDataPath = csInterface.getSystemPath(SystemPath.USER_DATA)
if (userDataPath.substring(0,1) !== '/') {
return 'windows';
} else {
return 'osx';
};
}
// If the operating system is MacOS, and the last 4 characters of the chosen filepath are NOT '.json', add '.json' to the end o the filename as the extension.
if (operatingSystem == 'osx' && filePath.substr(filePath.length - 5) !== '.json') {
filePath += '.json'
};

