Well, I’m stumped, here. I’m writing a little utility that needs to know what the frontmost application was before my program starts. I tried this:

```
var thePreviousApp:NSRunningApplication = NSWorkspace.sharedWorkspace().frontmostApplication

override func awakeFromNib()
{
    thePreviousApp = NSWorkspace.sharedWorkspace().frontmostApplication
}

```

It works when I run from Xcode (i.e. it sets thePreviousApp to “Xcode”) but when I run the binary from Finder or from Launchpad it returns the name of my program, not the program that was frontmost before my program started.

For what its worth, I can get the previous app by putting this in the AppDelegate:

```
var thePreviousApp:NSRunningApplication = NSWorkspace.sharedWorkspace().frontmostApplication

 func applicationDidResignActive(notification: NSNotification!)
 {
    thePreviousApp = NSWorkspace.sharedWorkspace().frontmostApplication
 }

```

If I start the program, then hit command-tab to activate the previous program, then hit command tab again to activate my program, thePreviousApp is the correct application.

I’ave also tried getting the array of runningApplications was NSWorkspace, then iterating through them to check which program is “active”. Again, no dice. Same problem.

Any advice would be appreciated.

Thanks,
Tom