Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OSX Yosemite - JavaScript for Automation Accessing Enums

I'm starting to try converting some of my AppleScripts into JavaScript in OS X Yosemite, but I don't understand how I'm supposed to access enums from applications. For example - the status of Adium.

In AppleScript:

tell application "Adium"
    if status type of global status is offline then
        log "offline"
    end if
end tell

In JavaScript I do not know how to access the "offline" enum:

if(Application('Adium').globalStatus.statusType == ?????) {
    console.log("offline");
}

I've tried simple things like "offline" without success. All these are errors:

Application('Adium').StatusType("offline"); // error
Application('Adium').StatusType.offline;     // undefined
Application('Adium').StatusType.make({name:"offline"}); // error

Anyone gotten something like this working?

like image 883
Jordan Reed Avatar asked Oct 20 '22 03:10

Jordan Reed


1 Answers

While I have been unable to do the enum comparison, I have been able to make this work. In JavaScript for automation, calling just the property returns the ObjectSpecifier for the Apple object. In this case the statusType is a class of "AdiumRichText".

If you put () after the property it calls the getter method which returns a NSString (String) that works fine. So here is the code:

if(Application('Adium').globalStatus().statusType() == "offline") {
    console.log("offline");
}
like image 55
Jordan Reed Avatar answered Oct 23 '22 01:10

Jordan Reed