Last active
May 6, 2017 08:16
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var finder = Application("Finder"); | |
finder.includeStandardAdditions = true; | |
finder.doShellScript("date"); | |
//!! Error on line 1: Error: A privilege violation occurred. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var app = Application.currentApplication(); | |
app.includeStandardAdditions = true; | |
app.doShellScript("date"); | |
//=> "2015年 2月25日 水曜日 17時16分28秒 JST" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var app = Application("AppleScript Utility"); | |
// 確認 | |
app.scriptMenuEnabled(); | |
//=> true / false | |
// 有効にする | |
app.scriptMenuEnabled = true; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Application.currentApplication() | |
properties: ["__private__"] | |
name: Script Editor | |
{ | |
"frontmost": true, | |
"class": "application", | |
"name": "Script Editor", | |
"version": "2.7" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Application.currentApplication() | |
properties: ["__private__"] | |
Error: Message not understood. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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