Get Frontmost Window
tell application "System Events" set frontmostApplication to name of the first process whose frontmost is true end tell
DZone Snippets > willcodeforfoo > applescript
12374 users tagging and storing useful source code snippets
Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
tell application "System Events" set frontmostApplication to name of the first process whose frontmost is true end tell
tell application "Mail" to try tell message viewer 1 to set selected messages to {first message of beginning of (get selected mailboxes) whose read status is false} activate on error beep end try