Skip to content

Instantly share code, notes, and snippets.

@zakuroishikuro
Last active July 1, 2016 02:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zakuroishikuro/974369ea2d6f41ef7927 to your computer and use it in GitHub Desktop.
Save zakuroishikuro/974369ea2d6f41ef7927 to your computer and use it in GitHub Desktop.
Google先生も知らないJXAのプライベートメソッド ref: http://qiita.com/zakuroishikuro/items/a7def965f49a2ab55be4
var app = Application("Finder");
var win = app.windows[0];
Automation.getDisplayString(win)
//=> "Application(\"Finder\").windows.at(0)"
>> Automation.log(win)
//[object ObjectSpecifier]
//=> undefined
var term = Application("Terminal");
reveal(term);
var term = Application("Terminal");
reveal(term);
reveal(ObjC);
var qt = Application("QuickTime Player");
qt.activate();
qt.quit();
qt.launch();
// アプリケーションを取得
var qt = Application("QuickTime Player");
// この時点で起動してなかったら起動される
qt.activate(); //フォーカスを移す
qt.quit(); //終了
qt.launch(); //起動
str = "hello"
// launch new TextEdit window
editor = Application("TextEdit");
doc = editor.Document().make();
// set text
doc.text = str;
//=> "hello"
doc.text.set(str); //same above
//=> true
doc.setProperty("text", str); //same above
//=> true
// get text
doc.text();
//=> "hello"
doc.text.get(); //same above
//=> "hello"
doc.getProperty("text").get(); //same above
//=> "hello"
// set text
doc["text"] = "hi"
// "hello"
// get text
doc["text"]()
// "hi"
var app = Application("Finder");
var win = app.windows[0];
Automation.getDisplayString(win)
//=> "Application(\"Finder\").windows.at(0)"
>> Automation.log(win)
//[object ObjectSpecifier]
//=> undefined
var finder = Application("Finder");
ObjectSpecifier.hasInstance(finder);
//=> true
ObjectSpecifier.hasInstance("foo");
//=> false
ObjectSpecifier.classOf(finder);
//=> "application";
ObjectSpecifier.classOf("foo");
//=> undefined
var itunes = Application("iTunes");
itunes.properties()
/*=> {
"class": "application",
"name": "iTunes",
"playerState": "stopped",
"version": "12.1",
"frontmost": false,
"soundVolume": 100,
"mute": false,
"visualsEnabled": false,
"fullScreen": false,
"visualSize": "large",
"eqEnabled": false,
"fixedIndexing": false,
"playerPosition": null,
"converting": false,
"currentStreamTitle": null,
"currentStreamURL": null,
"airplayEnabled": false,
"currentAirPlayDevices": [
null
],
"iadIdentifier": null
}*/
var finder = Application("Finder");
Object.keys(finder); //=> []
Object.getOwnPropertyNames(finder) //=> ["__private__"]
finder.hasOwnProperty("a"); //=> true
finder.hasOwnProperty("ab"); //=> true
finder.hasOwnProperty("abc"); //=> true //なわけないじゃん
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment