Skip to main content
kevinm87730361
Inspiring
February 16, 2016
Answered

How to check if the user is on Mac or Windows ?

  • February 16, 2016
  • 2 replies
  • 4766 views

Hi everyone, in the JavaScript Tools Guide CC (http://download.macromedia.com/pub/developer/aftereffects/scripting/JavaScript-Tools-Guide-CC.pdf), on Chapter 3 : File System Access page 49 it says for the filter of function openDialog :

Optional. A filter that limits the types of files displayed in the dialog:

- In Windows, a filter expression, such as "JavaScript:*.jsx;All files:*.*"

- In Mac OS, a filter function that takes a File instance and returns true if the file

should be included in the display, false if it should not.

So how can I make the difference between widows and mac in my script ?

This is for the moment what I have. It works for windows but I don't know if it works for mac.

var filterFiles = function(file){

     // IF WINDOWS

      return "*.jsx;*.jsxinc";

     // IF MAX

      if (file.constructor.name == "Folder") { return true; }

      writeLn(file.name);

      if (file.name.slice(-4) == ".jsx" || file.name.slice(-7) == ".jsxinc") { return true; }

      return false;

    };

var files = File.openDialog("Choose a script", filter=this.filterFiles, multiSelect=this.multiSelect);

Thanks for your help

This topic has been closed for replies.
Correct answer kevinm87730361

I found this on Duik repository‌ and it works fine.

os = $.os.toLowerCase().indexOf('mac') >= 0 ? "MAC": "WINDOWS";

2 replies

TLCMediaDesign
Inspiring
April 18, 2016

The info is in navigator.userAgent

dnyaneshlb
Known Participant
February 16, 2016

Its simple.

var os = new csInterface().getOSInformation();

This will give you OS information. Then,

if(os)

{  

  os = os.indexOf("Mac") == 0 ? "MAC": "WINDOWS";

}

This is in javascript. You can pass it on to extendscript and use. I believe there are some APIs available in jsx also.

kevinm87730361
Inspiring
February 16, 2016

Thank you !