I'm trying to different events depending on what application is currently the `"open"` application - The one which is foremost of the screen. I have managed to save the name of the application using a variable. Using this code.

```
tell application "System Events" 

    item 1 of (get name of processes whose frontmost is true)
    set openWindow to (get name of processes whose frontmost is true)
    do shell script "echo " & openWindow & " > /Users/name/temp/currentWindow.txt"

end tell

```

I then tried to use this code do different events for each open application

```
tell application "System Events"

  if openWindow = "AppleScript Editor" then
    display dialog "my variable: " & openWindow
  end if

end tell

```

However this code does not apper to do anything, I don't have any error messages or anything however the code doesn't display the dialog box. If I place the code for the dialog box in the first section of code it will display the name of the open application. 

Any ideas on how to get this to work, it would be very helpful