Read or detect device or workspace

Hi
Is there a way to read or detect the device and/or operating system you’re using (more specific then just using navigator) or reading the active workspace name (as a workaround) through the api, and possibly dataview?
I would like to parse/show information differently depending on the device that loads the vault.

What’s wrong with navigator? It has that information. You want something easier to interpret?

It doesn’t distinguish safely or strictly enough between operating system and/or a specific devices. At least not from how I’m used to using it.

I already found a solution in the Obsidian API in Platform to ask for a specific type of operating system, f.e.: dv.app.plugins.plugins['templater-obsidian'].templater.current_functions_object.Obsidian.Platform.isMacOS

And by using a specific workspace per device which I can read out with:
dv.app.internalPlugins.plugins['workspaces'].instance.activeWorkspace)

If there’s an easier way then this, please enlighten me.

What outcome are you trying to achieve?

I want to show different information in template(r) and/or a dataviewjs based upon the specific device/os I’m using at that moment. You can’t get that from a userAgent.

What platforms are you trying to differentiate?

Any. I want to know when I’m using my iPhone, my iPad, my other iPad, possibly an Android-device, my macOS-laptop, maybe a Windows-device. As far as I know, you can’t get the name of the device out of the userAgent.
But it’s ok, I already have my solution that works.

As long as the userAgent string is not identical, you can distinguish between the devices. Have you compared the userAgents of your apple mobile devices and found them to be identical?

Why would I go to all the trouble of looking for a way to get a specific device name out of the navigator or userAgent if I can just solve it more specifically for my use case with what I already have?

If it can be done quicker or more efficient then with the one or two lines I already posted, please show me, by example.

Here’s a simple plugin that will add obsidian.Platform and activeWorkspace to the global scope: https://github.com/james-tindal/obsidian-plugin-helenagwyn

Once installed, you will only need to type Platform.isMacOS and activeWorkspace inside your DataViews

const obsidian = require('obsidian')

class Plugin extends obsidian.Plugin {
  onload() {
    globalThis.Platform = obsidian.Platform
    globalThis.activeWorkspace = app.internalPlugins.plugins.workspaces.instance.activeWorkspace
  }
}

module.exports = Plugin
1 Like