Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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

Community Beginner ,
Feb 16, 2016 Feb 16, 2016

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

4.6K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Beginner , Apr 02, 2016 Apr 02, 2016

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

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

Translate
Participant ,
Feb 16, 2016 Feb 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 16, 2016 Feb 16, 2016

Thank you !

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 02, 2016 Apr 02, 2016

This actually doesn't works, I have an error : "RefferenceError : csInterface does not have a constructor". Any idea on how to fix that ?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 02, 2016 Apr 02, 2016

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

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Apr 18, 2016 Apr 18, 2016
LATEST

The info is in navigator.userAgent

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines