How do I apply a script to any open app?

After reading [urhttp://www.macosxhints.com/article.php?story=20010407171430814&query=window+transparency]this tip[/url] on macosxhints.com, I tested this trick by putting together a little script that changes the alpha of the frontmost iCal window. What I want to know is, how do I make the script so that it applies the alpha change to the frontmost window of the active app, regardless of which app. Currently, iCal is hardcoded into the script, cuz I don’t know how to get the active app via AS. Here’s the script:


[This script was automatically tagged for color coded syntax by Convert Script to Markup Code]

Any help here?
thanks!

The easiest way to get the frontmost app is to ask System Events:

tell application "System Events"
   set frontApp to first application process whose frontmost is true
   tell application frontApp to set alphaValue of front window to theValue
end tell

You should probably wrap it all in a try/end try block to catch errors with non-Cocoa applications and apps that don’t support AppleScript/window commands.