Can't get front/active window

I’ve been trying to get the selected record from DNtp but the normal methods for getting the active window aren’t working for me.

The window is always the first one I opened starting DNtp; the selection if of course for that window.

Have I missed something?


tell application id "DNtp"
	-- set mWin to the front window
	set mWin to window 1
	log "Front window is: " & name of mWin as string
	set mSel to the selection of mWin
end tell

Check the Applescript dictionary. :smiley: Look for “selection” and you’ll see it’s a property of: the application, a search window, or a viewer window.

Note that selection returns a list, even a list of one.

PS: there are no “normal methods” (though there may be common ones). Applescript is implemented as each developer sees fit (and many don’t even allow for a selection property).

You may also want to look at content record.

This looks at a single selected record only. (This will fail with “missing value” if the selection is a group.)


tell application ID "DNtp"
   set theRecord to the content record
   (*do something*) 
end tell

This can look at multiple selected records - including groups or a combination of groups and documents.


tell application ID "DNtp"
   set theRecords to the selection as list
   repeat with thisRecord in theRecords
      (*do something*)
    end repeat
 end tell

Sorry, it was fine. I was using Script Debugger’s explorer feature and I think it interfered with the execution of DNtp’s library code.

So, the window selection code worked but there is no need for it (thought it was necessary due to SD.) Selection works fine.

Thanks for the help though :smiley: