Skip to main content
Inspiring
March 9, 2020
Question

File SaveDIALOG

  • March 9, 2020
  • 3 replies
  • 2810 views

I am using the following code to open the FileSaveAs Dialog

 

var file = File.saveDialog('Save info', 'Info:*.txt');
On a Mac there is no File Extension added unlike in Windows. Is there a way to force an extension or this just the way it works on MAC
 
Ian
 
This topic has been closed for replies.

3 replies

Inspiring
August 19, 2021

Any update on this? I'm having this exact same problem...

Stephen Marsh
Community Expert
Community Expert
August 19, 2021

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:

 

Saving/File extension issue in Photoshop 21.1.0

Inspiring
August 19, 2021

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'
};
Legend
March 10, 2020
Code snippet from Image Processor.jsx
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;
}
Remake for your
Replace ".xml" with ".txt"
 
Geppetto Luis
Legend
March 10, 2020

Mr. r-bin on mac doesn't work.

IanBarberAuthor
Inspiring
March 12, 2020

Have you tried this

it works on my mac

try{executeAction( charIDToTypeID('save'), undefined, DialogModes.ALL );}catch(e){}


Yes that does work although it does not offer txt file as the Format

Geppetto Luis
Legend
March 10, 2020

Try using this little code

 

try{executeAction( charIDToTypeID('save'), undefined, DialogModes.ALL );}catch(e){}