私はこれをしたいと思います:
tell application "Finder" to set appName to (application file id "com.google.Chrome") as text
using terms from application appName
tell application appName to get URL of active tab of first window
end using terms from
「from用語の使用」には文字列定数としてアプリケーション名が必要なため、これは機能しません。この行を置き換えると:
using terms from application appName
これで
using terms from application "Google Chrome"
できます。ただし、「GoogleChrome」という名前のアプリケーションを持つターゲットマシンに依存したくありません。バンドル識別子を使用する方が安全なようです。これを行うためのより良い方法はありますか?
編集
@ regulus6633のアドバイスに従って、私は次のことを試しました。
NSAppleScript* script = [[NSAppleScript alloc] initWithSource:
@"tell application \"Finder\" to set appName to (application file id \"com.google.Chrome\") as text"
@"\nusing terms from application \"Google Chrome\""
@"\ntell application appName to get URL of active tab of first window"
@"\nend using terms from"];
これは問題なく動作しますが、「Google Chrome」の名前が「Chrome」に変更された別のコンピューターで同じ(コンパイル済み)アプリを実行すると、「GoogleChrome」の場所を尋ねるポップアップダイアログが表示されます。NSAppleScriptが実行時にコンパイルされているように見えますか?