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" 

Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo