Copy link to clipboard
Copied
JavaScript running in Photoshop CS6 under OS X 10.7.5 returns the wrong result for app.activeDocument.path when the file is located on the boot drive. The result is undefined and an error message incorrectly states that the document has not been saved yet. If the file is located on a remote volume, the correct path is returned.
To reproduce this problem, create a new file in Photoshop CS6 on a Mac. Save the file to the desktop. With the file still open, run the following script in ExtendScript Toolkit.
// start script
var thePath = app.activeDocument.path;
alert(thePath);
// end script
Running the same script with a file located on a server volume open in Photoshop correctly returns "/path/to/file.psd" instead of undefined and no error occurs.
This appears to be a bug in Photoshop CS6's JavaScript implementation. This problem did not exist in Photoshop CS3.
A similar issue prevents Photoshop CS6 from saving files to the boot drive using activeDocument.saveAs.
Has anyone else experienced this problem? If so, have you discovered an alternate method to determine the file path or save a file on the boot drive?
Copy link to clipboard
Copied
Hi,
What is the name of your boot drive?
regards,
steve
Copy link to clipboard
Copied
Odysseus.
I have also experienced the same problem with another machine.
Copy link to clipboard
Copied
I am haivng the same issue with Extendscript CS5 and Photoshop CS5. I have not been able to test a remote volume, but I receive the same error on the boot drive. I open a file that is already saved on disk in Photoshop CS5 and then run a script which tries to access the activeDocument.path property. The script breaks on that line and the error message is "The document has not yet been saved". The is clearly an error, because of course the document has been saved, I loaded it from a file on disk (and no changes have been made to it before trying to access the path property)!
Were you able to find a solution or a workaround?
Thanks!
Copy link to clipboard
Copied
Don't know if this will help much but at least you can use it to check a document's filepath without throwing an error. And maybe tell if the problem is with the Photoshop DOM.
function hasFilePath(){// returns true/false
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
return executeActionGet(ref).hasKey(stringIDToTypeID('fileReference'));
};
function getFilePath(){// returns path as a string if exists, undefined if not
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var desc = executeActionGet(ref);
if(desc.hasKey(stringIDToTypeID('fileReference'))) return decodeURI(desc.getPath(stringIDToTypeID('fileReference')));
};
Copy link to clipboard
Copied
Thanks Michael! Those functions look quite useful. I was using the path property as a place to save out PNGs from the PSD in the same location as the PSD, but because the path property was not working, I chose to hardcode a location where to save the files.
Copy link to clipboard
Copied
Thank you. This does give me the document's filepath. Unfortunately, there is still clearly a bug somewhere that prevents the use of activeDocument.path.
I resolved the issue with activeDocument.saveAs by specifying the full path of the save location using:
/Volumes/Users/chip/Documents/...
instead of:
/Users/chip/Documents/...
The latter format did work in JavaScript with Photoshop CS3, as well as every other scripting language I know of that uses POSIX-style paths.
Copy link to clipboard
Copied
You can get the full path like this:
#target photoshop
var thePath = app.activeDocument.fullName;
alert(thePath);