Create UUID using Cocoa method

I currently use uuidgen at the command line to generate UUIDs, but in an effort to learn how to use Cocoa methods more in my AppleScript…

The Cocoa is

#include <CoreFoundation/CoreFoundation.h>
 
int main()
{
   CFUUIDRef theUUID = CFUUIDCreate(NULL);
    CFStringRef string = CFUUIDCreateString(NULL, theUUID);
    CFRelease(theUUID);
}

I can see that we have two references, and that we first create a new UUID object, then create a string from that

However, no combinations of:

use scripting additions
use framework "Foundation"
set uuidgen to current application's CFUUIDCreate

or anything else will work. It’s as if it knows not CFUUIDCreate

Hi,

since 10.8 there is a NSUUID Foundation class

current application's NSUUID's UUID()'s UUIDString()

[INSERT-CURSE-WORD-OF-CHOICE]

Stefan, Many Thanks! :slight_smile: