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

1 Like

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 can do 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