0

私はこれをしたいと思います:

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が実行時にコンパイルされているように見えますか?

4

1 に答える 1

2

あなたは「からの用語を使用する」が何をするかを誤解しています。これは、アプリケーションを使用してコンピューター上でスクリプトをコンパイルし、ユーザーのコンピューター上でスクリプトを再コンパイルしないようにするための方法です。つまり、そのコード行を使用してコンピューターでコンパイルすると、そのコード行はユーザーのコンピューターでは何も実行されないため、ユーザーはスクリプトのコンパイルに使用したアプリケーションを必要としません。まさにあなたが探しているもの。スクリプトを「アプリケーション」として保存して、ユーザーのコンピューターで再コンパイルする必要がないようにしてください。

これは、実際にコードを次のように見せたいものです。

-- here you determine what the user's browser is
set usersBrowser to "whatever"

using terms from application "Google Chrome"
    tell application usersBrowser
        -- here you do something in the user's browser
        -- you have to make sure that whatever command you use is applicable to both google chrome and whatever browser the user is using i.e. the command must work in both browsers
    end tell
end using terms from
于 2011-01-06T05:41:43.883 に答える