Skip to main content
Legend
October 4, 2023
Answered

Volume name from File class ( Document saved )

  • October 4, 2023
  • 4 replies
  • 1807 views

Hi,

 

I have an InDesign document that has been saved. I would like to know the volume name that the document is saved on.

 

File and Folder class are not offering much.

 

Thank you.

 

P.

This topic has been closed for replies.
Correct answer rob day

Maybe this?

 

var sv = Folder("~/Desktop/").parent.parent.parent.displayName
var fp = app.activeDocument.filePath.toString()

if (fp[0] == "~") {
	alert("Document Volume: " + sv)
} else {
    alert("Document Volume: " +fp.split("/")[1])
}  

4 replies

Peter Kahrel
Community Expert
Community Expert
October 4, 2023

It's not safe because (over here) it always returns null, whether the file is on the desktop or anywhere else. That's because of the addition of displayName. That may be a bug, no idea.

 

The only way I could get it to work is with this mongrel:

 

var p = app.activeDocument.fullName.parent;
var temp = app.activeDocument.fullName;

while ( p ) {
  temp = p;
  p = p.parent;
}

alert ( temp.fullName.replace('\/','') );

 

 

PickoryAuthor
Legend
October 4, 2023

Thanks for looking.

 

Are you running Windows? I am on Mac CC 2019.

rob day
Community Expert
rob dayCommunity ExpertCorrect answer
Community Expert
October 4, 2023

Maybe this?

 

var sv = Folder("~/Desktop/").parent.parent.parent.displayName
var fp = app.activeDocument.filePath.toString()

if (fp[0] == "~") {
	alert("Document Volume: " + sv)
} else {
    alert("Document Volume: " +fp.split("/")[1])
}  
Peter Kahrel
Community Expert
Community Expert
October 4, 2023

You have this problem only with files on your desktop. To get the drive/volume name you'ld do

Folder("~/Desktop/").parent.parent.parent

P.

PickoryAuthor
Legend
October 4, 2023

Thank all. 

Peter, that did the trick.

 

Folder("~/Desktop/").parent.parent.parent.displayName

 

PickoryAuthor
Legend
October 4, 2023

I wonder, is this safe?

 

var p = app.activeDocument.fullName.parent;

var volName = "";

while ( p )

{

volName =  ( p.displayName )

p = p.parent;

}

alert ( volName );

rob day
Community Expert
Community Expert
October 4, 2023

Hi @Pickory , You can easily do it with AppleScript, but the ExtendScript file path doesn’t seem to resolve the full absolute path

Inspiring
October 4, 2023

I think file.fullname will return the file path  

PickoryAuthor
Legend
October 4, 2023

Thank you for your reply. 

It does not work for me 😞

 

//=======

alert ( app.activeDocument.fullName + "\r" +

app.activeDocument.fullName.displayName + "\r" +

app.activeDocument.fullName.fsName + "\r" +

app.activeDocument.fullName.fullName + "\r" +

app.activeDocument.fullName.path + "\r" +

app.activeDocument.fullName.relativeURI + "\r")

 

//======