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

ExtendScript Oddity with File/Folder on Mac OS X

Contributor ,
Feb 05, 2012 Feb 05, 2012

Copy link to clipboard

Copied

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?

TOPICS
Scripting

Views

15.7K

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
New Here ,
Jun 03, 2016 Jun 03, 2016

Copy link to clipboard

Copied

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?

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 Beginner ,
Feb 14, 2020 Feb 14, 2020

Copy link to clipboard

Copied

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.

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
Contributor ,
Jun 12, 2020 Jun 12, 2020

Copy link to clipboard

Copied

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.

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
Guide ,
Jun 14, 2020 Jun 14, 2020

Copy link to clipboard

Copied

Here some AppleScripts that may be useful:

 

app.doScript('tell application "System Events" to get name of startup disk',ScriptLanguage.APPLESCRIPT_LANGUAGE)
app.doScript('get POSIX path of (path to home folder)',ScriptLanguage.APPLESCRIPT_LANGUAGE)
app.doScript('get POSIX path of (path to preferences folder)',ScriptLanguage.APPLESCRIPT_LANGUAGE)
app.doScript('get POSIX path of (path to library folder from user domain)',ScriptLanguage.APPLESCRIPT_LANGUAGE)
app.doScript('get POSIX path of (path to desktop folder)',ScriptLanguage.APPLESCRIPT_LANGUAGE)

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
Contributor ,
Jun 14, 2020 Jun 14, 2020

Copy link to clipboard

Copied

Thank you, but as far as I know that will work for InDesign only.

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
Guide ,
Jun 15, 2020 Jun 15, 2020

Copy link to clipboard

Copied

I used File.execute() from scripts running within the ESTK, but avoiding terminal.app windows requires a complicated construction with an AppleScript helper app, also temporary files for the script and output.

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
Contributor ,
Jun 15, 2020 Jun 15, 2020

Copy link to clipboard

Copied

LATEST

It is still a solution! I actually never used File.execute() command, will remember it, one day might be usefull.
found this way to hide shell script https://superuser.com/a/1354541

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