views:

37

answers:

1

Hi,

how can I activate an application and make it open the "standard" window as if I would have clicked on the dock icon with applescript?

E.g. I am in iTunes, close the window with command-w open another application and then I click on the iTunes dock icon and iTunes becomes the frontmost application and opens up it's "standard" iTunes window.

When I want to simulate that with applescript I type:

tell application iTunes to activate

What happens then is, that iTunes becomes the frontmost application, but the "standard" window (in that case the iTunes window) isn't being opened.

Does anyone know about a way to open the "standard" window with a general approach for any application?

Thanks b00tsy

A: 

There is no true, single way to show a "standard" window. It is up to the developer of each application to decide how a window is to be created and shown. For example, here is iTunes and Microsoft Word 2008...

tell application "iTunes"
   activate
   set theBrowser to browser window 1
   set visible of theBrowser to true
end tell

tell application "Microsoft Word"
   set newDocument to make new document
end tell

In iTunes, there are three "standard" windows—browser, EQ, and playlist—and browser and EQ always exist. But in Microsoft Word, however, we have to make a new document, which is as close to a "standard" as it gets. Most applications will work the same way Word does, but it isn't a guarantee and you will have to look at the Dictionary for a given application to see how it handles windows (although iTunes does have a window class to throw everyone off, but that's Applescript for ya...).

One more thing to note...in most cases, once a window is closed, the only way to reopen it is to open the file that populated the window you just created or simply create a new one. iTunes is rare in its implementation.

Philip Regan
well I was afraid that it would be like that...
b00tsy
So I guess the application developer chooses whithin his/her app what to do when the app becomes unhidden again, and implements that behavior in a certain method which will be called then...
b00tsy
Exactly. Applescript's wonkiness comes more from individual developers' implementation and a lack of guidance from Apple than anything else.
Philip Regan