Welcome Dialog

Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.


File SaveDIALOG

Participant ,
Mar 09, 2020 Mar 09, 2020

Copy link to clipboard

Copied

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
 
TOPICS
Actions and scripting

Views

1.7K

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Mar 10, 2020 Mar 10, 2020

Copy link to clipboard

Copied

Try using this little code

 

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

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Mar 10, 2020 Mar 10, 2020

Copy link to clipboard

Copied

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"
 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Mar 10, 2020 Mar 10, 2020

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Mar 10, 2020 Mar 10, 2020

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;
}

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Mar 11, 2020 Mar 11, 2020

Copy link to clipboard

Copied

Mr. r-bin
the save as window opens
just that no file extension comes out?

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Mar 12, 2020 Mar 12, 2020

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.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Mar 12, 2020 Mar 12, 2020

Copy link to clipboard

Copied

Have you tried this

it works on my mac

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

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Mar 12, 2020 Mar 12, 2020

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Mar 12, 2020 Mar 12, 2020

Copy link to clipboard

Copied

Ian, hello, I'm no coder, but it seems that Catalina changed some stuff related to the file extensions

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Aug 20, 2021 Aug 20, 2021

Copy link to clipboard

Copied

LATEST

I added missing closing curly brace to your previous.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 18, 2021 Aug 18, 2021

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Aug 18, 2021 Aug 18, 2021

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:

 

Saving/File extension issue in Photoshop 21.1.0

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 18, 2021 Aug 18, 2021

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'
};

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines