AppleScriptでAdobe系のアプリケーションをコントロールする際、
何気に問題になる日本語ファイルパスの対応法メモ。
on aiFileOpen(f)
(*最初にPosix Pathに変換*)
set f to POSIX path of f
(*シングルコーテーションをエスケープ*)
set AppleScript's text item delimiters to {"'"}
set f to text items of f
set AppleScript's text item delimiters to {"\\'"}
set f to f as Unicode text
set AppleScript's text item delimiters to {""}
(*JavaScriptでencodeURIエスケープして開く*)
tell application id "com.adobe.illustrator"
do javascript "app.open(new File(encodeURI('" & f & "')));"
end tell
end aiFileOpen
aiFileOpen(choose file of type {"ai"})