I am using AppleScript in VBA and add a example to get the UUID from a Mac.
UUID seems to be new in Leopard (Mac OS X 10.5).
What can you use on older Macs or is there a beter wat to get a unique indentifier
-- http://www.afp548.com/article.php?story=leopard_byhost_changes
-- first get hardware UUID
set UUID to do shell script "ioreg -rd1 -c IOPlatformExpertDevice | grep -i 'UUID' | cut -c27-62 | awk {'print tolower()'}"
-- determine machineID
if text 1 thru 24 of UUID is "00000000-0000-1000-8000-" then -- PPC or early Intel
set machineID to text 25 thru end of UUID
else -- newer Intel
set machineID to UUID
end if
Unfortunately, although this may work on older machines (eg. my G5 running Leopard), it doesn’t return anything on older systems (the same G5 running Tiger).
But the query’s a little ambiguous.
Edit: By “doesn’t return anything”, I actually mean “returns an empty Unicode text”. :rolleyes:
Another idea which seems to work is to read the UUID from the name of one of the files in ~/Library/Preferences/ByHost/:
set UUID to (do shell script "ls -t ~/Library/Preferences/ByHost | sed -En '1 s/^.+[.]([^.]+)[.]plist.*$/\\1/p'")
This returns the full UUID in Snow Leopard (Intel) and the shorter version without the “00000000-0000-1000-8000-” in both Leopard and Tiger (PPC). The Leopard and Tiger results are identical on my G5.
The reason the “ls” command has the -t parameter to sort by modification date is that some preference files on my Tiger partition have a different UUID in their names. To judge from their modification dates, they must have been copied over from my old PowerBook when I originally set up the G5. This suggests that the above code would work in Jaguar and Panther too.
Edit: Deleted an unnecessary second address from the “sed” command.
A subtle alternative to having “sed” only edit and print the first line is to have it quit explicitly after editing and printing the first line! I don’t know if there’s any theoretical advantage either way.
set UUID to (do shell script "ls -t ~/Library/Preferences/ByHost | sed -E 's/^.+[.]([^.]+)[.]plist.*$/\\1/ ; q'")
Great, I only have one Mac to test because I am a Windows user most of the time.
But this looks great, will change the code on my site this week and if i get feedback i will post it here.