Getting unique ID of a user's machine

Great Dan!
and thanks for code color working fine - I edited my previous post!

waiting for John or Steve…

I don’t know what use you make of ENV[“ALLUSERSPROFILE”]. That could affect whether there is even an equivalent concept in OS X. But in any case, I think there is no equivalent ENV string.

You might consider making your code Windows specific. John (first reply) posted code sample that showed backticks are not an issue with OSX.

It would point the same place as ENV["ProgramData"] ("C:\ProgramData" by default,) on Windows 6+.

In older Windows versions it was called the “All Users” profile, and pointed at (depending upon if it was a clean install, or upgraded and whether the old OS was Windows or NT):

"C:\Documents and Settings\All Users"
or
"C:\Profiles\All Users"
perhaps
"C:\Users\All Users"

These are not equivalent to the “Public” folders on Windows 6+. They should have restricted permissions, ie only application processes should be writing to these locations. (Older versions Windows 5 and earlier, may not have had such strict restrictions.)

[Not to be confused with the “Default User” profile that is used as a template, when creating a new user account.]


On Mac, it be "HD/Application Support/" wouldn’t it ? as opposed to the "~/Application Support/" ?


ADD: There are OS differences. On Windows, this “shared profile” contains special sub-folders like “Start Menu”, “Desktop”, etc. whose contents appear (display) to all users as if their contents where also in each user’s folders of the same name. I doubt if OSX does things in the same way.

You missed my real point: having found that directory, what content would the script expect to find there and what would it want to use it for? Need to answer those to figure out where OS X keeps the equivalent info (or if anything equivalent even exists).

Those paths are missing a stage: “/Library/Application Support” and “~/Library/Application Support”.

Indeed, it does not!

1 Like

Yes, I know. I’d guess, shared company extension data. Some extension companies wish to actually install their extensions there (which I think just causes more problems than not.)

it works with a conditional path and returns the same as on windose…

but you really should only write/read files when you need to. on a mac you don’t need to…

only two of the ENV entries are useful to you…

ENV.entries.each{|k| p k[0]};nil
"TMPDIR" # same path as OSX $TMPDIR and it is a unique per User folder
"__CF_USER_TEXT_ENCODING"
"HOME" # File.expand_path('~') == ENV['HOME'] # => true
"SHELL"
"Apple_PubSub_Socket_Render"
"SSH_AUTH_SOCK"
"PATH" # path to shell
"LOGNAME"
"DISPLAY"
"XPC_SERVICE_NAME"
"USER"
"XPC_FLAGS"
"IG_ROOT"
"GEM_PATH"
"GEM_HOME"
"SSL_CERT_FILE"
"RLM_DIAGNOSTICS"
"RLM_ROAM"

john

1 Like

The simplest way to find the temp folder is:

temp_dir = Sketchup.temp_dir

available since v2014

2 Likes

Hello,

@slbaumgartner
I answered using private message. Thanks for the reply. I learnt Mac OSX is per user level.

@MSP_Greg
We - unfortunately - are going to make specific code, no doubt but do not know what kind yet. I was pleased to learn no extra window opening on the Mac - thank to John - but have no solution on Windows. wmi is slow through backtick and shows that annoying small black window. We would like bringing an elegant but robust answer. Perhaps a extra exe.

@danRathbun
You’re right looks like OSX does things it’s own way, not Windows like regarding system-level location

@john_drivenupthewall
Of course and fortunately no need of extra file on OSX, only Windows requires. The - bad - script above was just for test purposes. Thanks for the commented ENVironment variable list.

@TIG
It was my first place but SUalive back compatibility down to SketchUp 8 needs ENV use.

about OSX
what is /usr/share/ folder for on the Mac?

Have a good day
WhyDi

it’s now a restricted folder that can only be used by Apple certified application installers/updaters, etc…

you can not modify any files in /System, /bin, /sbin, or /usr (except /usr/local) using code or even as Root…

there is however a /Users/Shared folder that is intended for sharing folders, files, settings between all users but programatic access to it needs to be hardcoded into any shared ‘parent’ application…

SU doesn’t look for files in /Users/Shared even though it would be very useful on shared computers…

john

Ah hah! The equiv. of ENV["Public"] on Windows.

Hello,

Thanks all I now know ‘why’. time to go on ‘what’ before ‘how’
One thing is for sure : due to Windows odd behaviour we need to postpone release date. more work than expected as always!

Although you probably ever know and of course I will make all my best for any of you getting SUalive Full version for free if you like. Just PM me!

no doubt I’m back soon!
WhyDi

I just tried this after a query at SCF…

# first I installed the two gems
 Gem.install 'systemu'
 Gem.install 'macaddr'
# then I required the gem
require 'macaddr'
# then I called the method
Mac.addr
# I left out the return as I don't want it public...

the code for both is easy to follow…

Does it run on a PC?

john

It seems to work although it takes a really long time to install the Gem. If used in an extension there has to be some feedback to the user that a Gem is installing.

Interesting! Install was almost instantaneous on my Mac. Sounds like a busy server or poor internet connection (the Gems are relatively small and pure ruby, nothing to compile).

Yes!

I attempted to code such an interface at one time, and sent Thomas a copy.
It’s been several years, so I had forgotten about it. (I’ll try and see if I can find it.)

I’d be more inclined to reuse the systemu code in a bespoke extension, i.e. not load the gems at all…

john

1 Like

I’ve also just got the following system_profiler output.
At first look UUID is missing but could I rely on this output so that parsing data?
http://tilfin.hatenablog.com/entry/20070927/1191057329
Output always in English?

I think I can deal with
https://developer.apple.com/legacy/library/documentation/Darwin/Reference/ManPages/man8/system_profiler.8.html

yes it’s always in English…

en = `system_profiler SPNetworkDataType`.split("\n").grep /MAC Address/
en[0].inspect # there are 3 on my mac, this is the Ethernet one...
# returns this with the whitespace and mixed case, NB: I changed the content but not the order or case...
"          MAC Address: 00:1e:c2:15:02:36"

john

From your knowledge what’s the best or the right way?
1 - stacking lets say 3 or 4 system_profiler Data_type commands ?
2 - running system_profiler SPNetworkDataType once then retrieving these 3 or 4 data from the return?
I’m rather inclined the second way but…

WhyDi