Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

File SaveDIALOG

Contributor ,
Mar 09, 2020 Mar 09, 2020

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
2.9K
Translate
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
Advocate ,
Mar 10, 2020 Mar 10, 2020

Try using this little code

 

try{executeAction( charIDToTypeID('save'), undefined, DialogModes.ALL );}catch(e){} 
Translate
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
People's Champ ,
Mar 10, 2020 Mar 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"
 
Translate
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

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

Translate
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
People's Champ ,
Mar 10, 2020 Mar 10, 2020

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

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

Translate
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
Contributor ,
Mar 12, 2020 Mar 12, 2020

Same here, the save as dialog shows but no extension.

I think  this is a MAC feature to be honest after further reading.

Translate
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

Have you tried this

it works on my mac

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

Translate
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
Contributor ,
Mar 12, 2020 Mar 12, 2020

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

Translate
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
Community Expert ,
Mar 12, 2020 Mar 12, 2020

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

Translate
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
LEGEND ,
Aug 20, 2021 Aug 20, 2021
LATEST

I added missing closing curly brace to your previous.

Translate
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

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

Translate
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
Community Expert ,
Aug 18, 2021 Aug 18, 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

Translate
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

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