• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Microsoft Word ... active window problems
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Microsoft Word ... active window problems


  • Subject: Re: Microsoft Word ... active window problems
  • From: Paul Berkowitz <email@hidden>
  • Date: Tue, 22 Nov 2005 16:47:11 -0800
  • Thread-topic: Microsoft Word ... active window problems

Title: Re: Microsoft Word ... active window problems
On 11/22/05 3:43 PM, "David Crowe" <email@hidden> wrote:

According to the Microsoft Word (Office 2004) dictionary Class window has a boolean attribute "active".


This works as expected with the following code:

tell application "Microsoft Word"
       active of every window
end tell
--> {false, true, false, false}

With the Finder, with a boolean, I can do something like this:

tell application "Finder"
       name of first process whose frontmost is true
end tell
--> "Smile"

But, if I try the same in Word I get nothing, e.g.

tell application "Microsoft Word"
       name of first window whose active is true
end tell
--> missing value


What am I doing wrong? Is it me or Bill Gates? I have tried several other variants and all fail in one way or another.

You don't need such contortions in Word (believe it or not!). There's only one window ever that's active - the front window. And there is an application property for the active window, called simply

    active window

(Check the 'application' class to see it for yourself. There are lots of other very useful application properties there too.)

So all you need is

    name of active window

The reason why it didn't work the way you tried it is that in Word (and Excel and PowerPoint), although you can do

    name of every window

to get a list (and the same for any property of 'every [element]') of the name property of all such elements (e.g. windows), and you can also do

    every window whose active is true

(as you did) to get a list of elements satisfying a condition, you cannot "put them together" to get a list of properties of every element meeting a condition. It is a limitation of Word's AppleScript implementation. On the other hand, we're pretty luck to get 'whose' clauses at all (not every application implements them), as it's completely absent from the underlying OLE Automation model on which Word's AppleScript relies. Same for 'every window', for that matter: OLE uses 'collection objects' instead, not a list of objects. It's great that the developers were able to implement both these very powerful AppleScript procedures, and really too bad that they could not combine them. (If you ever need to do it for real, you'd get the list of 'every [element] whose [property] is true', and then use a repeat loop through each window to get its name. Or for 'first [element] whose [property] is true', you wouldn't need a loop at all - just get the property of the single element. But there's a bug here: 'whose' clauses don't seem to work at all with 'active' property of window:

    every window whose active is true
    --> {}

so

    first window whose active is true
    --> missing value

I'll report it, but it's really the lowest of low priorities, since

    active window

gets you just what you want, as does its name.



--
Paul Berkowitz
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Microsoft Word ... active window problems (From: David Crowe <email@hidden>)

  • Prev by Date: Re: Microsoft Word ... active window problems
  • Next by Date: Re: Tiger broke my Excel->PDF Script
  • Previous by thread: Re: Microsoft Word ... active window problems
  • Next by thread: Re: Microsoft Word ... active window problems
  • Index(es):
    • Date
    • Thread