Mac equivalent of ENV['APPDATA']

I need to create a directory to store some data. On Windows I can use ENV['APPDATA'] to find a suitable place. Does anyone know what the Mac equivalent command is?

why not ENV['TMPDIR']?

it’s risky storing in the app contents…

if more permanent storages is needed, storing in your extensions folder is much more reliable…

or use ‘Sketchup.write_defaults’…

john

I need to store big files, vray mesh files and so on in a persistent way. I’m curious about your objections to the app directory. That seems like the most logical place to me.

on a mac when you distribute an app, all the folders need to be ‘signed’…

every version of macOS has been getting stricter with signing validity…

the end game is likely to be ‘no modifications allowed’ to app content and this already happens on non admin accounts…

i.e. most institutional installs…

the extensions folder is in ‘User land’ so there are no restriction to size or access, even from other programs…

it also means ‘fully’ uninstalling SU will also purge all the redundant files…

if you want to disregard the users desire for an automatic purge, then writing to a ~Documents/<your sub folder with name that includes SketchUp and Vray> is the best option as most uninstalers will grep using the app name …

if you want it ‘hidden’ just prepend a dot to the folder name…

# I personally don't believe Fileutils overhead is worth it
# for so little,so I use system calls...
path = File.join(File.expand_path('~/Documents'), '.hidden_SketchUp_Vray_repo')
`mkdir "#{path}"` # to make
`open "#{path}"` # in Finder.app
`rm "#{path}"` # to destroy

john

1 Like

On windows ENV[‘APPADATA’] refers to user specific application data C:\Users\USERNAME\AppData\Roaming, this is the domain where user specific Sketchup stuff is placed including extensions. I gather that the corresponding directory on Mac is /Users/USERNAME/Library/Application Support/. What I’m asking for is a way to retrieve this path in the same manner as on a windows machine.

Since Mac is unix based ~/Library/Application Support/ might work but I don’t dare to rely on that…

So, is ENV["APPDATA"] John. It is in the user’s path.

It resolves to …
"#{ENV["USERPROFILE"]}/AppData/Roaming/"
which in my case is …
"C:/Users/Dan/AppData/Roaming"


On Mac (I think) the equivalent would be …
"~/Library/Application Support/"
where the “~” in Ruby will resolve to the user’s home directory … Ie …
ENV["HOME"]
… ie, in the User path.


CAUL only needs to decide whether to create his data folder in a version independent way.
If not, then he can indeed put his files in a subfolder of his extension folder.

If he wants it version independent, then it goes somewhere in the AppData user path.
If he wants to treat himself like any other application software entity, he can create a company folder at the same level that others do. (Ie, directly in the AppData/ApplicationSupport folder.)
If he wants to associate directly with SketchUp, but still version independent. Then his company folder could be created as a subfolder of "#{ENV["APPDATA"]}/SketchUp". (He needs to keep in mind this needs to be done for each user account on a computer as this is still within each user’s separate path.)


If he wants both user and version independent, then this is where permissions issues have problems because the ENV["ProgramData"] (Win) / “HD/Application Support” (Mac) paths need admin privileges.

There are other topic threads where weve discussed this ad nauseam.

1 Like

You could do …

ver = Sketchup.version.to_i
plugins = Sketchup.find_support_file("Plugins")
appdata = plugins.sub("/SketchUp 20#{ver}/SketchUp/Plugins",'')

sorry, I didn’t even vaguely guess the APP_DATA is really USER_DATA…

what’s in a name…

simplest path to SU ‘user’ resources folder on a mac…

# in unix everuhings a file...
File.dirname(ENV['GEM_PATH'])
# => /Users/<name>/Library/Application Support/SketchUp 2019/SketchUp

john

Is there a constant on Mac which gives the path just to /Users/USERNAME/Library/Application Support/ ?

No, never has been…

we’ve always had to manipulate a known path i.e. `Sketchup.find_support_file()’ and back out…

these are all the ENV.keys…

["SSL_CERT_FILE", "RLM_DIAGNOSTICS", "TMPDIR", "__CF_USER_TEXT_ENCODING", "SHELL", "_", "HOME", "SSH_AUTH_SOCK", "Apple_PubSub_Socket_Render", "GEM_HOME", "RLM_ROAM", "SHLVL", "IG_ROOT", "PATH", "DISPLAY", "LOGNAME", "XPC_SERVICE_NAME", "GEM_PATH", "USER", "XPC_FLAGS", "PWD"]

only ‘two’ lead to User/*/Lib/ path,

ENV["GEM_HOME"] == ENV["GEM_PATH"]
# => true

so it’s really only one…

john

Ok, thanks, that was a good answer. It’s going to be something like File.join(ENV['HOME'], 'Library/Application Support') then.

don’t you need to know the SU version?

personally, I would tend to subtract, rather than join…

ENV['GEM_PATH'].split('SketchUp')[0]
# =>  /Users/johns_iMac/Library/Application Support/

but, you can call me old fashioned…

john

Is there a reason not to go to ‘~/Library/Application Support’?

Caul has said didn’t want to rely on that and from ruby you would need…

File.expand_path('~/Library/Application Support')

but, I think, extension generated folders should only go into a SketchUp version level directory, not the root ~/Library/Application Support directory…

john

I was replying to his example of File.join(ENV[‘HOME’], ‘Library/Application Support’). Just using ‘~/Library/Application Support’ would be the same place. How you then get into the right version of SketchUp, and the Plugins folder, is its own problem.

Again … not if he will be saving data in a version independent location.

I said it above, … and in the previous topic thread on the same subject.

It is often desirable for both developers and users to save data / settings in a version independent location (ie, a vendor folder structure,) because SketchUp installers still do not migrate settings to newer versions (although this has been one of the longest running peeves about the yearly update cycle.)

So the long term solution has been to do an “end around” the problem and use a location that does not need migration. This means creating appdata / app support “vendor folder” and subfolders for the products / plugins.

ok, but there is a user independent ‘Shared’ folder for that purpose on a mac…

any app or extension can create sub directories…

on mine GraphicConverter.app has made it…

graphic_converter = '/Users/Shared/Library/Application Support/GraphicConverter/'
another_app_creates = '/Users/Shared/Library/Preferences/'

the gotcha is that SU’s ENV["PWD"] causes File.exists? to return false making it tricky to access…

shared = '/Users/Shared/Library/Application Support/SketchUp/JcB_Dev'

%x[mkdir "#{shared}"]

$LOAD_PATH << shared

# drop in some ruby and
load 'sqrt(targets).rb'

john

@CAUL Another thing you cando because ENV["APPDATA"] will be undefined (nil) on Macs, is …

if Sketchup.platform == :platform_osx && !ENV["APPDATA"]
  ENV["APPDATA"]= File.expand_path('~/Library/Application Support')
end

Then, you use ENV["APPDATA"] interchangeably in your directory maintenance methods.

John, drink another cup of coffee (or tea.)

We are talking here (SketchUp) VERSION independent NOT USER independent !

You are muddling the conversation.

pot kettle black…

john