Accessing environment variables from DAZ Script,& Mac equivalent of %APPDATA% ?
Just started looking at one of my old PoserPython/DA Script thingies, because I now want to start writing to a datafile (previously I only ever read it).
Assuming the user had both DAZ Studio and Poser installed the datafile should be in one of the Poser runtimes, which the user has as a mapped runtime in DAZ Studio. This wasn't a problem when just reading the file. However, if I want to write the file I start running into UAC/permissions problems.
So I've decided to try putting my datafile some place like this (PoserPython code snippet, because I'm doing the Poser version first):
... sTmp = os.environ['APPDATA'] fileaddr = os.path.join(sTmp,'Roaming','3DCheapskate-Poser-DAZ-SmartPlus','SmartPlusData.txt') if os.path.exists(fileaddr): ...
This (should*) return a fileaddr something like...
C:\Users\[username]\AppData\Roaming\3DCheapskate-Poser-DAZ-SmartPlus\SmartPlusData.txt
(I decided not to put under \Roaming\Poser\ or \Roaming\DAZ 3D\ since it's not specific to either.And I like my folder names tobe self-exlanatory-ish)
I have two non-PoserPython related questions regarding this.
First Question (DAZ Script question):
How do I do this in DAZ Script ? (It's been a looonnnggg time...)
Second Question (MacOS question):
I assume that environment variable APPDATA doesn't exist in Mac-land. So what Mac-ish environment variable would be the equivalent/most appropriate ?
*I haven't actually tried it yet
Comments
http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/api_reference/object_index/system_dz#a_1a4a55d8de3fc35cc5c47772199553d09e
I don't know the Mac name, though, if it is different. If this is a working file, rather than a file that persists betweens essions, don't forget http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/api_reference/object_index/app_dz#a_1a6eb0f147d79ede5e791fcbbefa86785a
Thanks Richard. This particular file needs to exist outside the scope of DAZ Studio, since it's also used by Poser. So that's the main reason I'm looking for an OS-based location rather a DAZ Studio/Poser-specific location.
Still hoping that there's somebody with Mac knowledge here.
On macOS, Applications store things in ~/Library/Application Support/<your base folder and subpaths>
There is a ~/Library/Application Support/DAZ 3D folder there already, but you can create your own, but I don't know how to do that from a DS Script (except by really using the fill path) as I don't think there are any bridges to the macOS FileManager functions except for basic file functionality.
Id you want the thing to be on a system level and not on a per user level, then It's /Library (without ~), as ~means "from this users home directory in unix-path)
Thanks Totte,
So working on the basis that the Mac environment variable for the user's home directory is HOME, as mentioned here, the snippet of PoserPython from the OP would become this for Mac (just to get it down on paper... you know what I mean)
Richard's first link gives me the DAZ script command for getting an environment variable...
...and I know that I've got DAZ script somewhere that strings together a full path.