Create folder in root directory using extendscript
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.
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();
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>".
Copy link to clipboard
Copied
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();
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);
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.
Copy link to clipboard
Copied
Sorry, Ignore above case. It is working fine in Windows. I need this for Mac OS only.
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.
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.
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:
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:
Others commented as well eight years later in 2020 with different ideas to solve the issue.
O2-Creative:
Dirk Becker:
Regards,
Uwe Laubender
( Adobe Community Professional )

