Create three windows of specific size & location
  • I am new to FastScripts & AppleScript in general, so please forgive what may be a stupid question.

    Is it possible to create three Safari windows of 3 specific dimensions on two monitors?

    Basically I'd like to be able to invoke a script which will open Google in one window on my first monitor, and two other Safari windows (each 50% of the screen) on my main iMac monitor.

    But I have no idea a) if this is possible or b) where to begin
  • It should be possible. Rather than write the script for you :) Since you say you are learning AppleScript, here's a formula for exploring and learning how to do it:

    1. Open AppleScript Editor.

    2. Open some windows in Safari.

    3. Start playing around with commands for getting the bounds of the windows that are open:


    tell app \"Safari\"
    get bounds of window 1
    end


    4. You'll see something like {0, 22, 1500, 1046} come back. This series of numbers defines the left, top, right, and bottom offsets of the window. You can put whatever values you want in and play around to see how it affects the location and size of a window:


    tell app \"Safari\"
    set bounds of window 1 to {0, 400, 600, 800}
    end


    5. Since you want your 3 windows at a fixed position, I am guessing you'll want to set everything up as you like it and then use AppleScript to "get" the bounds of each window so you save that in your script to set them.

    6. Now you know how to set the size of a window, but how to create it? It's very common in AppleScript to use the "make" command, something like.


    tell app \"Safari\"
    make new document
    end


    7. You will see that this opens a new document window, but there's no URL. Use AppleScript Editor's "Open Dictionary" function to examine Safari's scriptable dictionary, and look for attributes of the "document". You'll find it supports a "URL" property. When anything in AppleScript has a settable property, you can change it:


    tell app \"Safari\"
    set URL of document 1 to \"http://www.apple.com/\"
    end


    8. Pulling that together, here's a simple sequence of script that creates a new window at a particular spot and loads a URL into it:


    tell application \"Safari\"
    make new document
    set URL of document 1 to \"http://www.apple.com/\"
    set bounds of window 1 to {500, 500, 800, 800}
    end tell


    That should get you started ! Good luck,

    Daniel
Start a New Discussion

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!