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

Create folder in root directory using extendscript

Participant ,
May 17, 2022 May 17, 2022

Copy link to clipboard

Copied

Hi All,

 

I am able to create the folder in desktop.

var f = new Folder("~/Desktop/new_fodler");  
f.create();

 

But I couldn't create the folder in /Users/ directory.

var f = new Folder("/Users/new_fodler");
f.create();

 

Could anyone help me on troubleshooting this. Is this required any permissions with the code?

 

Thanks. 

TOPICS
Scripting

Views

223

Likes

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 Expert ,
May 17, 2022 May 17, 2022

Copy link to clipboard

Copied

Hi @AD4003 , the parent of the desktop should be the user folder, so try this:

 

var f = new Folder(Folder.desktop.parent + "/new_folder")
f.create();

 

Likes

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
Participant ,
May 17, 2022 May 17, 2022

Copy link to clipboard

Copied

Hi rob day

Thanks for your reply. But, I want to create a folder under "/Users" directory not in "/Users/<username>".

Likes

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 Expert ,
May 17, 2022 May 17, 2022

Copy link to clipboard

Copied

LATEST

I can make a folder in the System/Users directory on OSX Mojave by adding a parent, but I have to give the Users folder Read/Write permissions or the folder will not be created

 

//create a new folder in the System/Users folder
var f = new Folder(Folder.desktop.parent.parent + "/new_folder")
f.create();

 

Screen Shot 66.png

 

 

Also here is the Folder API page which includes shortcuts to common folders—you can back out of these folders using .parent, but you do need permission:

 

https://www.indesignjs.de/extendscriptAPI/indesign-latest/#Folder.html

 

 

Some examples:

 

$.writeln("User Desktop: " + Folder.desktop)
//~/Desktop

$.writeln("System Application Support Folder: " + Folder.appData.fsName)
//System Application Folder: /Library/Application Support

$.writeln("User Application Support Folder: " + Folder.userData.fsName)
//User Application Support Folder: ~/Library/Application Support

$.writeln("Target Application Folder: " + Folder.appPackage.fsName)
//Applications/Adobe InDesign 2020/Adobe%20InDesign 2020.app

$.writeln("Documents Folder: " + Folder.myDocuments)
//Documents Folder: ~/Documents

$.writeln("Application Startup Folder: " + Folder.startup.fsName)
//Application Startup Folder: /Applications/Adobe InDesign 2020/Adobe InDesign 2020.app/Contents/MacOS

$.writeln("System Folder: " + Folder.system)
//System Folder: /System

$.writeln("Temp Folder: " + Folder.temp)
//Temp Folder: /private/var/folders/w2/s1lk7d6d3m95v4pq7m4flscw0000gn/T/TemporaryItems

$.writeln("Trash Folder: " + Folder.trash)
//Trash Folder: ~/.Trash


var dt = Folder.desktop
$.writeln("Full Destop Path: " + dt.relativeURI)
//Full Destop Path: /Users/fishercat/Desktop

var uas = Folder.userData
$.writeln("Full Destop Path: " + uas.parent)

var CC = File(Folder.desktop.parent.parent + "/Creative Cloud Files")
$.writeln("CCF Folder: " + CC);

 

 

 

 

 

Likes

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
Participant ,
May 17, 2022 May 17, 2022

Copy link to clipboard

Copied

Otherwise, It would be helpful to achieve this in Windows OS directory.

var f = new Folder("C:\\new_folder");
f.create();

Please advise.

Likes

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
Participant ,
May 17, 2022 May 17, 2022

Copy link to clipboard

Copied

Sorry, Ignore above case. It is working fine in Windows. I need this for Mac OS only.

Likes

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
LEGEND ,
May 17, 2022 May 17, 2022

Copy link to clipboard

Copied

Folders under /Users are created when a new user is added. At no other time. MacOS will protect against other changes. What is it you want to store, we may be able to help you find a suitable place.

Likes

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 Expert ,
May 17, 2022 May 17, 2022

Copy link to clipboard

Copied

@Test Screen Name is correct. /Users is not an appropriate place to create a folder! Are you trying to have your script create a new MacOS user account? I doubt that is possible.

 

Or are you looking for a place to keep files that are accessible to all users of the machine? If so, make your folder in /Users/Shared/

 

This worked for me:

 

var f = new Folder("/Users/Shared/new_folder");
f.create();

 

- Mark

 

EDIT: Here is some info on the /Users/Shared/ folder. Anything you put here should have permissions automatically set to be accessible to all users.

Likes

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 Expert ,
May 17, 2022 May 17, 2022

Copy link to clipboard

Copied

Hi together,

currently I cannot test this on MacOS, but I remember that there was a discussion ten years ago:

https://community.adobe.com/t5/indesign-discussions/extendscript-oddity-with-file-folder-on-mac-os-x...

 

I'm quoting Joris_Coppieters from that discussion:

 

// BEGIN QUOTE:

 

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

 

// END QUOTE

 

 

Don't know if this is still relevant…

Well, could be.

 

Joris presented the following solution in 2012:

https://community.adobe.com/t5/indesign-discussions/extendscript-oddity-with-file-folder-on-mac-os-x...

 

Others commented as well eight years later in 2020 with different ideas to solve the issue.

O2-Creative:

https://community.adobe.com/t5/indesign-discussions/extendscript-oddity-with-file-folder-on-mac-os-x...

 

Dirk Becker:

https://community.adobe.com/t5/indesign-discussions/extendscript-oddity-with-file-folder-on-mac-os-x...

 

 

Regards,
Uwe Laubender
( Adobe Community Professional )

Likes

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