Identify Platform/Operating System

Platform

[x] iOS
[x] Android

Obsidian Mobile version: v1.0.5 on iOS and Android
Obsidian version: v0.12.19 on Mac and Windows


I’m building JavaScripts to customize my Obsidian use across multiple operating systems and platforms and I need to be able to identify which system I’m working with in the scripts. I’m able to use data from the ‘Navigator’ class on Mac and Windows through either the console.log or a function return:

console.log(navigator);
return navigator.userAgent;

I can’t figure out how to differentiate between iOS (iPhone and iPad) and Android platforms. Is there something similar that I can use to positively identify my mobile platform?

Thanks,
Katchi

On desktop (Mac & Windows), I’m able to call specific parameters of the Navigator class. Doing so returns “MacIntel” on my Mac, and “Win32” on my PC - I haven’t played on Linux yet, but i’m guessing that will return something particular to whichever flavor I’m using. I’m getting the parameters from the console:

…and parsing through them to pull out something that denotes the various operating systems with this script:

function hostname() {
  console.log(navigator);
  return navigator.platform;
}
module.exports = hostname;

This works great for the desktop systems, but I can’t figure out what parameters I can call to identify mobile systems.

After spending way to much time looking for a solution to this, I wound up settling for only identifying desktop/laptop operating systems. As for the mobile platforms, I’ll just plan to not perform some functions on them - either that or I will write scripts that I know will work perfectly on desktop, and just do a Hail Mary for mobile…
In case anybody else is looking for something similar, I’m running the following javascript via Templater to ID the OSs (the iOS channel doesn’t actually do anything, but I’m keeping it for the time being):

/**
 * hostname does not require an argument.
 * hostname returns the operating system that Obsidian is running on.
 */

function hostname() {
  var userAgent = window.navigator.userAgent,
      platform = window.navigator.platform,
      macosPlatforms = ['Macintosh', 'MacIntel', 'MacPPC', 'Mac68K'],
      windowsPlatforms = ['Win32', 'Win64', 'Windows', 'WinCE'],
      iosPlatforms = ['iPhone', 'iPad', 'iPod'],
      os = null;
  if (macosPlatforms.indexOf(platform) !== -1) {
    os = 'Mac OS';
  } else if (userAgent.indexOf(iosPlatforms)) {
    os = 'iOS';
  } else if (windowsPlatforms.indexOf(platform) !== -1) {
    os = 'Windows';
  } else if (/Android/.test(userAgent)) {
    os = 'Android';
  } else if (!os && /Linux/.test(platform)) {
    os = 'Linux';
  }

  return os;
}

module.exports = hostname;

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.