Accessing environment variables from DAZ Script,& Mac equivalent of %APPDATA% ?

3dcheapskate3dcheapskate Posts: 2,719

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...frown)

 

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

Post edited by 3dcheapskate on

Comments

  • 3dcheapskate3dcheapskate Posts: 2,719

    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.

  • TotteTotte Posts: 13,955

    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)

     

  • 3dcheapskate3dcheapskate Posts: 2,719
    edited April 2020

    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)

        ...    sTmp = os.environ['HOME']    fileaddr =  os.path.join(sTmp,'Library','Application Support','3DCheapskate-Poser-DAZ-SmartPlus','SmartPlusData.txt')    if os.path.exists(fileaddr):        ...

     

    Richard's first link gives me the DAZ script command for getting an environment variable...

    sEnv = System.getenv( "APPDATA" );

    ...and I know that I've got DAZ script somewhere that strings together a full path.

    Post edited by 3dcheapskate on
Sign In or Register to comment.