LoginSignup
4
3

More than 5 years have passed since last update.

デザイン自動化メモ(スクリプト実行中のOSを判定する)

Last updated at Posted at 2018-07-22

スクリプト実行中のOSを文字列変数に格納する方法

スクリプトをmacとWindowsの両方で使うとき、os毎に処理を書き換えるところがあります。
そのときに使うおまじないです。

function isMac() {

   if ($.os.toLowerCase().indexOf('mac') >= 0 ) {
       return true;
   }

   return false;
}

function isWindows() {

   if ($.os.toLowerCase().indexOf('mac') < 0 ) {
       return true;
   }

   return false;
}

function main() {

      if (isMac() == true) {

          // macの時の処理を入れる

          alert("Macです");
      }

      if (isWindows() == true) {

          // windowsの時の処理を入れる
          alert("Windowsです");
      }
 }

main();
4
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
3