LoginSignup
2
2

More than 5 years have passed since last update.

AppleScriptObjC上でAppleScriptを動かす

Last updated at Posted at 2014-08-26

いろいろと試行錯誤してみたのですが、自分はこれに落ち着きました。
(XcodeでCocoa-AppleScript Applicationを作る場合)

Resources内に格納したASDialog.scptにパラメータを渡して、runしています。
(load〜runでは、AppleScriptObjC側で読み込んでしまうのが原因か、うまくいかないケースが有りましたので直接runしています。)
パラメータや戻り値はstringやtextではなくUnicode textで統一。

----------【AppleScriptファイル内】

on run as_prm
    activate
    display dialog (item 1 of as_prm) as Unicode text
    display dialog (item 2 of as_prm) as Unicode text

    return "完了" as Unicode text
end run


----------【AppleScriptObjCファイル内】

property NSBundle : class "NSBundle"

(*スクリプトファイルのパス取得*)
set as_path to (NSBundle's mainBundle()'s resourcePath()) as Unicode text & "/ASDialog.scpt"

(*パラメータを渡してrun 戻り値あり*)
set as_prm to {"ダイアログ1回目" as Unicode text, "ダイアログ2回目" as Unicode text}
set as_result to run script as_path with parameters as_prm

log as_result
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2