0

Looking to build a dynamic value which evaluates to the current OS (e.g.: OS X 10.10.4) with the JavaScript API, and am not able to find any mention of the users' current OS as an available value in the JavaScript API.

Is this possible right now, or no?

Colby Ludwig
  • 78
  • 1
  • 7

1 Answers1

0

There is not an actual way to get the current OS. The only thing I can suggest is hacky, but should work in most cases. The idea is to get the User-Agent of the last request you have sent and extract the OS X version from it:

// last HTTP exchange of the current request
var exchange = context.getCurrentRequest().getLastExchange();

// user agent
var ua = exchange.getRequestHeaderByName("User-Agent");

// parse user agent
var matches = ua.match(/OS X\/(\d+(?:\.\d+)*)/);

// full OS name
// OS X/10.10.4
var os = matches[0];

// version string
// 10.10.4
var version = matches[1];

Or as a one-liner:

// 10.10.4
return context.getCurrentRequest().getLastExchange().getRequestHeaderByName("User-Agent").match(/OS X\/(\d+(?:\.\d+)*)/)[1];
Micha Mazaheri
  • 3,481
  • 1
  • 21
  • 26