tell application "System Events"
set theFrontApp to (name of processes whose frontmost is true) as text
display dialog theFrontApp & " is formt most"
end tell リスト3自動生成
これをスクリプトメニューから実行すると、あれ?
System Events is front most
と表示されてしまいます。どうやら、スクリプトメニューからスクリプトを実行した場合、最前面のプロセスは System Events に固定されてしまうようです。これでは使い道がありません。
では、スクリプトが実行された段階で最前面のプロセス、つまり System Events を隠してしまってはどうでしょう?
tell application "System Events"
set visible of processes whose frontmost is true to false
set theFrontApp to (name of processes whose frontmost is true) as text
display dialog theFrontApp & " is front most"
end tell リスト4自動生成
スクリプトエディタの実行ボタンから実行すると、スクリプトエディタが隠れた上で、その時点で最前面にあるアプリケーションが最前面と表示されるのですが、スクリプトメニューから実行すると、やはり『System Events is front most』と表示されます。
う〜ん、『不特定の最前面にあるアプリケーションに処理を実行させる』スクリプトは無理なのかなぁ。
(覚え書き (10/30/2004 追記))
最前面のアプリケーションへのパス
path to frontmost application
→alias "HardDisk1:Applications:AppleScript:Script Editor.app:"
最前面のアプリケーション名
tell application "System Events"
name of (path to frontmost application)
end tell
→"Script Editor.app"
最前面のアプリケーションの表示名
tell application "System Events"
displayed name of (path to frontmost application)
end tell
→"スクリプトエディタ"
これらをふまえて…
最前面のプロセスに System Event を送る
tell application "System Events"
set theFrontApp to name of (path to frontmost application)
end tell
tell application theFrontApp to activate
tell application "System Events"
key down {command}
keystroke "v"
key up {command}
end tell