Search code examples
javascriptjsxphotoshop-script

Photoshop Script Renaming Files On Mac Not Working


I need to rename files using Photoshop Script and the code works fine on Windows but doesn't work on Macintosh. The code runs without error but the files name stays the same on Mac OS. It changes the file name on Windows.

Hostscript Code:

function RenameTest(){
  var fpath = Folder.myDocuments + '/test.rtf'; 
  var nfile = File(fpath); 
  var nfile_newname = Folder.myDocuments + '/test.ini'; 
  nfile.rename(nfile_newname);
}

Main.js Code:

csInterface.evalScript('RenameTest()');

Thanks for any help!


Solution

  • I found the solution if anyone needs it.

    This code works in Windows but not on Mac:

    function RenameTest(){
      var fpath = Folder.myDocuments + '/test.rtf'; 
      var nfile = File(fpath); 
      var nfile_newname = Folder.myDocuments + '/test.ini'; 
      nfile.rename(nfile_newname);
    }
    

    This works on both Windows and Mac:

    function RenameTest(){
      var fpath = Folder.myDocuments + '/test.rtf'; 
      var nfile = File(fpath); 
      var nfile_newname = 'test.ini'; 
      nfile.rename(nfile_newname);
    }
    

    The nfile.rename must only be the file name and extension. Don't add the path.