Skip to content

Instantly share code, notes, and snippets.

@zakuroishikuro
Last active May 6, 2017 08:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zakuroishikuro/cbb5430413aa5b09cfd9 to your computer and use it in GitHub Desktop.
Save zakuroishikuro/cbb5430413aa5b09cfd9 to your computer and use it in GitHub Desktop.
JXAの「Error: A privilege violation occurred」の回避 ref: http://qiita.com/zakuroishikuro/items/672afaf0f90d3d73c2c0
var finder = Application("Finder");
finder.includeStandardAdditions = true;
finder.doShellScript("date");
//!! Error on line 1: Error: A privilege violation occurred.
var app = Application.currentApplication();
app.includeStandardAdditions = true;
app.doShellScript("date");
//=> "2015年 2月25日 水曜日 17時16分28秒 JST"
var app = Application("AppleScript Utility");
// 確認
app.scriptMenuEnabled();
//=> true / false
// 有効にする
app.scriptMenuEnabled = true;
var app = Application.currentApplication();
app.includeStandardAdditions = true;
var str = Automation.getDisplayString(app);
// これじゃたぶん意味ない。(osascriptで実行してるじゃん)
//msg = app.doShellScript('osascript -l JavaScript -e "Application.currentApplication()" 2>&1 1> /dev/null | cat');
//str += "\n" + msg;
try { // try..catchしとかないとエラー出たら無言でアプレット消える
str += "\n\nproperties: " + Automation.getDisplayString(Object.getOwnPropertyNames(app));
str += "\nname: " + app.name(); //osascriptから.name()とか呼んだらエラー出る
str += "\n\n" + JSON.stringify(app.properties(), null, " ");
} catch(e){
str += "\n\n" + e.toString();
}
app.displayDialog(str);
var app = Application.currentApplication();
app.includeStandardAdditions = true;
var str = Automation.getDisplayString(app);
// これじゃたぶん意味ない。(osascriptで実行してるじゃん)
//msg = app.doShellScript('osascript -l JavaScript -e "Application.currentApplication()" 2>&1 1> /dev/null | cat');
//str += "\n" + msg;
try { // try..catchしとかないとエラー出たら無言でアプレット消える
str += "\n\nproperties: " + Automation.getDisplayString(Object.getOwnPropertyNames(app));
str += "\nname: " + app.name(); //osascriptから.name()とか呼んだらエラー出る
str += "\n\n" + JSON.stringify(app.properties(), null, " ");
} catch(e){
str += "\n\n" + e.toString();
}
app.displayDialog(str);
Application.currentApplication()
properties: ["__private__"]
name: Script Editor
{
"frontmost": true,
"class": "application",
"name": "Script Editor",
"version": "2.7"
}
Application.currentApplication()
properties: ["__private__"]
Error: Message not understood.
display dialog (path to current application)'s POSIX path
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment