Translating AppleScript if-clause to its JavaScript equivalent -
i don't know if issue lies me or os x. have applescript:
tell application "caffeine"     if active         turn off     else         turn on     end if end tell i translated this javascript
caffeine = application("caffeine"); if (caffeine.active) {     caffeine.turnoff(); } else {     caffeine.turnon(); } however caffeine.turnon(); never executed, no matter how run it. if caffeine active, turned off, otherwise nothing. applescript equivalent runs. caffeine.turnon(); , caffeine.turnoff(); run fine. can't imagine, javascript osa broken, doesn't work.
caffeine.active might function, when not called truly:
var my_fn = function() {}; if (my_fn) console.log('my_fn truly'); call function:
var caffeine = application("caffeine"); if (caffeine.active()) {     caffeine.turnoff(); } else {     caffeine.turnon(); } a way check it, log value:
console.log(caffeine.active); // function() { .... } // or using typeof console.log(typeof caffeine.active); // "function"