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

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

2.2K

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
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){} 

Votes

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
People's Champ ,
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"
 

Votes

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.

Votes

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
People's Champ ,
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;
}

Votes

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?

Votes

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.

Votes

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){}

Votes

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

Votes

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
Community Expert ,
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

Votes

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

Copy link to clipboard

Copied

LATEST

I added missing closing curly brace to your previous.

Votes

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...

Votes

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
Community Expert ,
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

Votes

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

Votes

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