0

この質問は奇妙に思えるかもしれません。ただし、世界中でさまざまな名前でリリースされているアプリケーションと対話する必要があります。AppEN、AppGB、AppDE など...

このコマンドを使用できるようにするソリューションを探しています。

tell application process "AppnameGB"

ただし、このアプリケーションのさまざまなバリエーションすべてで動作するはずです。これが可能かどうかはわかりませんが、アプリケーション名で文字列を検索するとうまくいく可能性があります。名前に「Appname」が含まれているアプリケーション プロセスに通知します。

4

2 に答える 2

2

最も簡単なのは、名前の代わりにアプリケーションのバンドル識別子を使用できる場合です。ほとんどの場合、バンドル ID は変更されませんが、名前は変更されます。したがって、そのアプリケーションでこのスクリプトを使用して、バンドル ID が変更されるかどうかを確認します。

tell application "Finder" to set bundleID to id of (choose file)

変更されていないことがわかった場合は、次のようにapplescriptを介してアクセスできます...

tell application "com.bundle.id"
   activate
   -- do something
end tell

あなたの唯一の他の選択肢は、すべてのアプリケーションのリストを取得し、あなたが提案したように名前をチェックしてそれらをループすることです. このようなものは機能しますが、かなり遅いです。

-- use spotlight to find all the apps on the computer
set cmd to "mdfind 'kMDItemContentType == \"com.apple.application-bundle\"'"
set foundApps to paragraphs of (do shell script cmd)

-- search the found apps looking for the one you're interested in
set appPath to missing value
repeat with i from 1 to count of foundApps
    if (item i of foundApps) contains "Appname" then
        set appPath to item i of foundApps
        exit repeat
    end if
end repeat

if appPath is missing value then error "Couldn't find the app!"

-- open the app
set macAppPath to (POSIX file appPath) as text
tell application macAppPath
    activate
    -- do something
end tell
于 2012-12-17T13:14:01.253 に答える
2

プロセスがすでに開いている場合は、次のようなものを使用できます。

tell application "System Events"
    tell (process 1 where name starts with "TextEd")
        properties
        set f to its file
    end tell
end tell
tell application (f as text)
    properties
end tell

ファイルを一覧表示するように Finder に指示するのは非常に遅いです。

tell application "Finder"
    item 1 of (path to applications folder) where name starts with "Text"
end tell

ただし、使用できdo shell scriptます:

set a to do shell script "ls /Applications/ | grep -m1 '^Text.*\\.app$'"
tell application a
    properties
end tell

set a to do shell script "mdfind 'kMDItemContentType==com.apple.application-bundle&&kMDItemFSName==Text*' | head -n1"アプリケーション フォルダの外も検索します。

于 2012-12-17T13:03:14.470 に答える