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