OSX のサンドボックスで動いてると。。。
AppleScriptやAutomatorで、動作が「期待通り」にならない。サンドボックスの中でアクセス可能なフォルダが制限される。。。
本当に由々しき問題だと思う。アプリ側の実装バグなのか、サンドボックスに由来するものかちょっと調べるには。アプリがsandboxing されているか調べる必要があった。
アクティビティ・モニタでサンドボックスされているか確認できる
AppleScriptやAutomatorで、動作が「期待通り」にならない。サンドボックスの中でアクセス可能なフォルダが制限される。。。
本当に由々しき問題だと思う。アプリ側の実装バグなのか、サンドボックスに由来するものかちょっと調べるには。アプリがsandboxing されているか調べる必要があった。
スクショの場所がわからない。。。。
調べたら、通常のMinecraftの位置ではなく、インスタンスごとに保存される模様。
$PATH_TO_AtLancher/$INSTANCE_NAME/screenshots/
/Applications/ATLauncher.app/Contents/Resources/Java/Instances/BevosTechPack/screenshots
とりあえず、ショートカットでも作っておけば便利なんでしょうか。
https://www.reddit.com/r/ATLauncher/comments/32y6zn/screenshots/
ファイルを保存するという基本的なところをUI Elementsではなく、Standard Suiteで行うことにした。
tell application ("TextEdit") activate make new document set text of document 1 to "test from apple script" save document 1 in POSIX file ("/Users/takuya/Desktop/sample.txt") end tell
同じことをJavascript for Automation で
var app = Application("TextEdit") app . activate() var doc = app.Document() doc.text = "test" app.documents.push(doc) app.documents[0].save({ in : Path("/Users/takuya/Desktop/sample2.txt") })
こんなもん。簡単でした。
関数の引数の渡し方
JavaScriptで書くときには、ちょっとくせがる。
引数なしの時
doc.save() //
引数があるとき
doc.save({ as : 'Text' }) //
引数は、不定個数ではなく、「一つ」で渡す。その一つはJSONであり、引数の名前が、キー名になる。
引数を複数入れるとき
doc.save({ as : 'Text' in: Path("/Path/to/Write") }) //
オブジェクトで複数いれます。ファイル・パスはPath()オブジェクトを使ってUNIXパス文字列を扱います。
JavaScriptでもAppleScriptでもドキュメントさえ押さえれば、簡単に自動化処理を作ることができる。
まぁ、PPT→PPTXでもインだけど、PDFにしちゃう方がポータビリティがいいんですよね。
どうせ、PPTXを編集することなんてないんだし。
PDFの方が、Evernoteに放り込んだり、検索可能にしたり、Explorer/Finderのプレビューでパパッと見られて色々便利なんだよね。
開いているファイルを、PDFに変換して保存する
var app = Application("Keynote") var doc = app.Document() //doc.text = "test" //app.documents.push(doc) app.documents[0].save({ in : Path("/Users/takuya/Desktop/sample2.key") }) console.log(app.documents[0].name()) app.documents.at(0).export app.documents.at(0).export({ as : "PDF", to : Path("/Users/takuya/Desktop/sample2.pdf") })
これで、pptx を keynotes 形式に変換したり、keynotes 形式をPDFに変換したりできる。
楽チンですが・・・MicrosoftのOfficeで変換したときと若干異なるんですよね。
同じように やったけど動かないんだ。
var app = Application("Microsoft PowerPoint") var doc = app.presentations.at(0) console.log(doc.name()) doc.save({ as : "PDF", in : "/Users/takuya/Desktop/sample2.pdf" })
AppleScript だと辛うじてうごく
set out to POSIX file "/Users/takuya/Desktop/test.pdf" tell application "Microsoft PowerPoint" save active presentation in out as save as PDF end tell
ダイアログが出てくるのだが、動いてるとは思えない。
ある日、ひらめいた。Sandbox 化が原因だったんじゃ?
ファイルができてるではないか
ということで、Automator・ApplescriptでPowerpointで変換したら、次のパスに作られる。
~/Library/Containers/com.microsoft.Powerpoint/Data.pdf
After studying the Document "App Sandbox in Depth" it seems just consequent for me what Microsoft did with Office 2016 and AppleScript. Regarding this document sandboxed apps can just write automatically (triggered by AppleScript) within the path ~/Library/Containers/com.microsoft.excel/. So doing something like this tell application "Microsoft Excel" tell active sheet save in path to temporary items from user domain as PDF file format end tell end tell should work. Files can afterwards be found in ~/Library/Containers/com.microsoft.excel/Data/Library/Caches/TemporaryItems/
ほかにも
http://eyeballonly.com/blog/2014/02/20/macosx-sandbox/
http://piyocast.com/as/archives/category/applescriptobjc/nshomedirectory/
などで、散見された。
https://developer.apple.com/library/mac/qa/qa1888/_index.html
Sandboxで、アクセス可能なディレクトリにDesktopがない。アプリ側でパーミッションを要求する感じ。でも動いてないんだよなぁ
しかしながら「テキストエディット」のような、Apple謹製のAppは、Sandboxされているが、Desktopへファイル保存が可能である。
ということは、Microsoftのプログラム側にバグがある。マイクロソフトがPowerPointのプログラムでSandboxを正しく扱えていないということしか考えられない。