Skip to main content
Inspiring
February 6, 2012
Question

ExtendScript Oddity with File/Folder on Mac OS X

  • February 6, 2012
  • 5 replies
  • 18494 views

Here's a really odd one, happens on Mac OS X Lion 10.7.3 with InDesign CS5.5.

Enter the following little InDesign Script in ExtendScript Toolkit, and run it targeting InDesign CS5.5:

// Create a path of the form /Users/kris/Desktop or something similar, then resolve the path back to a File object

var fn = File(File("~").fsName + "/Desktop");

alert(fn.fsName + " exists: " + fn.exists);

If all is well, you get a dialog saying something like "/Users/kris/Desktop exists: true".

Nothing weird yet. Leave ExtendScript Toolkit running for a sec.

Now start up a Terminal window, and go to the /Volumes folder. Create a subfolder called Users (so  that the folder /Volumes/Users exists on your computer).

Re-run the script.

Weirdness: I get "/Volumes/Users/kris/Desktop exists: false". Euh?

Anyone seen that before? Don't forget to remove "/Volumes/Users" again!

It is probably related to another weirdness. Run this one-liner:

alert(File("///").fsName);

You'll get "/Volumes" - but you'd expect to get "/", no?

This topic has been closed for replies.

5 replies

Participant
February 15, 2020

Ok this is the 2020 fix for this problem on OSX. 

 

So as discussed in this thread, the problem is if you have a USB or network drive Mounted with a Users folder (which will show in the terminal under /Volumes/Users/) then try to open the file  File('/Users/bob/'), extend script will instead open the mounted folder first "/Volumes/Users/bob" and fail.

 

The other solutions in this post to get the OSX hard drive name does not work in the latest CC2020 and OSX Catalina, the old solution of File("///").parent.displayName now returned a blank string. Ugh, You can manually use File('/Mackintosh HD/Users/bob/') if you know the hard drive is called 'Macintosh HD' but on other computers, this might fail.

 

I spent half a day trying a lot of different things and found a simple fix. add "/../" before the path

 

using var file = File('/../Users/bob/')  works because it will tranverse back a folder

 

If you check the file object path alert(file.fsName) it will return '/Volumes/../Users/bob/' Extend script still adds the Volumes folder but then /../ transverses back to the root /Users folder

 

in fact add in as bay as you like  File('/../../../Users/bob/') also works, as the parent '..' of the root is the root.

 

Hope this helps anyone in the future who is driven mad by this problem.

Ivan Stepanov
Legend
June 12, 2020

Thank you, does it support cases, that @Joris_Coppieters wrapper works with?

  • NewFolder("~/Desktop/TestFolder");
  • NewFolder("/Users/[USERNAME]/Desktop/TestFolder");
  • NewFolder("/Volumes/[ROOTVOLUME]/Users/[USERNAME]/Desktop/TestFolder");
  • NewFolder("/[ROOTVOLUME]/Users/[USERNAME]/Desktop/TestFolder");
  • NewFile("~/Desktop/TestFile.txt");
  • NewFile("/Users/[USERNAME]/Desktop/TestFile.txt");
  • NewFile("/Volumes/[ROOTVOLUME]/Users/[USERNAME]/Desktop/TestFile.txt");
  • NewFile("/[ROOTVOLUME]/Users/[USERNAME]/Desktop/TestFile.txt");

 

I've tested and if I want to get file from actual "Volume/DriveName/Folder" I will get "Volume/../Volume/DriveName/Folder" which will be unusable.

Participant
June 3, 2016

In a really weird twist... this article helped me in my situation!

I was getting a "Directory does not exist: /Volumes/Users/mac/desktop/render/" error every time I used terminal renderer. The problem wound up being that I have a server mount which is also called "Users" and houses user folders for folks in the office. Presumably, the path to my render folder set in AE would work fine, but in terminal presented with two /Volumes/Users paths, it chose the wrong one and errored out looking for the rest of the path. Once I unmounted this server, the terminal renderer completed with no errors. Adobe guys, there seems to be a glitch with how paths are read here, no?

Joris_Coppieters
Participant
February 9, 2012

It seems the Folder.create() function is immune to this hack.

I can successfully reference a folder object on my desktop using the hack function:

          var folder = Folder(newFile("~/Desktop/Test"));

But if you still have a Users folder in your Volumes, calling:

          folder.create();

Will return true but won't create the folder on the desktop.

Where was it created? In the /Volumes/Users directory!

=> /Volumes/Users/[USERNAME]/Desktop/Test

Joris

Harbs.
Legend
February 9, 2012

Hi Joris,

Ugh! I just tried using changePath() to try to move the folder to the correct location afterwards, but it does not seem to work as I'd hoped...

Harbs

Harbs.
Legend
February 9, 2012

I guess using AppleScript to create the folder would be a workaround, but all this stuff is pretty bad...

Jongware
Community Expert
Community Expert
February 6, 2012

Weird.

Is this just idle experimentation?  The Folder Class Folder.desktop (http://jongware.mit.edu/idcs5/pc_Folder.html) points directly to your desktop -- Windows compatible as well (I'm not sure your "~" notation is).

I don't know much about the low-level organization of Unix-style disk mountings, but isn't "/Volumes" more of a virtual construct by the OS than a physical one? Not at work today else I'd try (Dutch railroad made me wait for more than an hour last week 'cause of 1 inch of snow -- huh! "Extreme circumstances"! -- and now I have a severe headcold), but I think using plain "/" on a Windows set would bring you just to the root of the current drive, and I don't think there is a way to get a list of "mounted volumes" under Windows. The Mac solution, providing a higher-than-root-dir entry called Volumes solves this.

As for your "Users" question, well, you might be pushing against the boundaries of what's wise ;-) Folder names such as 'users' (lowercase) have special meanings in any OS, and trying to fiddle with Case Variations ("uSers", "deskTOP") may not only confuse ExtendScript -- which, remember, tries to mediate between Windows and Mac system folders -- but utlimately may bring down your Mac as well.

Inspiring
February 6, 2012

Hi Jongware!

Ignore the "~" stuff or the fact that I am using "/Users" to demonstrate it - it's my way to get the issue demonstrated in two lines.

I just tested some more: if I create any folder in the hard disk's root (e.g. /MyFolder) and put some file (e.g. test.txt) into it, there is no problem. Then, when I create the totally unrelated folder /Volumes/MyFolder, I suddenly get strange behavior, because for some odd reason, the ExtendScript path resolver prefers "/Volumes/MyFolder" instead of "/MyFolder" as a match to the expression "/MyFolder."

The thing is that "/whateveryouwant" gets resolved incorrectly on Mac OS X whenever there is a /Volumes/whateveryouwant folder. It gets resolved correctly if there is no /Volumes/whateveryouwant folder.

In other words, a constant string path gets interpreted differently dependent on the existence or non-existence of a seemingly unrelated folder. Internally, the algorithm that resolves a string path into a File or Folder object is using some incorrect logic, IMHO.

To try it out: create directory "/MyFolder", create a file "/MyFolder/text.txt" (keep in mind, we're not discussing whether that is wise or not - that's another discussion).

Now run

f = File("/MyFolder/test.txt");

alert(f.exists);

You get 'true'. Ok

Now create the directory "/Volumes/MyFolder" and re-run the same script

You get 'false'.

Now, before you say "Don't create any folders in /Volumes, then!" - the problem is that our users do this all the time! E.g. they have a USB drive called 'Users'. They insert it - KABOOM! Suddenly our scripts lose access to /Users/... because inserting that USB drive created the mount point /Volumes/Users. So, no - it's not idle experimentation. It's blood, sweat and tears :-(

Harbs.
Legend
February 6, 2012

Yeah. This seems to me a pretty major bug in ExtendScript (it's not limited to InDesign).

I'd log this bugger, and bug someone at Adobe to get this fixed. I wish I knew who to bug about that...

Harbs

Harbs.
Legend
February 6, 2012

Weird stuff! It happens on Snow Leopard as well...

Harbs