In OSX, can I launch, position and scale an application using applescript/automator?

5,800

This, while possible, may be a bit too fiddly to do with a script. Here is a partial sample script that restores firefox and itunes windows (adapted from the script found here.)

property numFFWindows : 0
property FFPos : {}
property FFSize : {}
property iTunesPos : {}
property iTunesSize : {}

display dialog "Set Window Position or Save Window Position?" buttons {"Restore", "Save"} default button "Restore"
set theResult to result

tell application "System Events"
    if (button returned of theResult is "Restore") then
        -- Restore Settings
        if (numFFWindows > 0) then
            tell process "Firefox"
                repeat with i from 1 to numFFWindows
                    set position of window i to (item i of FFPos)
                    set size of window i to (item i of FFSize)
                end repeat
            end tell
        end if
        if (iTunesPos is not {0, 0}) then
            tell process "iTunes"
                set position of window 1 to iTunesPos
                set size of window 1 to iTunesSize
            end tell
        end if
    else
        -- Save Settings
        tell process "Firefox"
            set numFFWindows to count windows
            set FFPos to {}
            set FFSize to {}
            repeat with i from 1 to numFFWindows
                set end of FFPos to (position of window i)
                set end of FFSize to (size of window i)
            end repeat
        end tell
        tell process "iTunes"
            set iTunesPos to position of window 1
            set iTunesSize to size of window 1
        end tell
    end if
end tell

I suggest you to look at this utility for more flexibility:

http://cordlessdog.com/stay/

Share:
5,800

Related videos on Youtube

Mild Fuzz
Author by

Mild Fuzz

Updated on September 17, 2022

Comments

  • Mild Fuzz
    Mild Fuzz over 1 year

    I am looking to automate the launching of my workspace. I use several applications, carefully positioned across two monitors, and I would like to be able to launch my prefered layouts with a single click

    I know how to launch several apps with an automator script, now I just need to be able to place the apps where they belong on the screen.

    Many thanks.

    • brevno
      brevno about 13 years
      It's going to be more difficult because you use two monitors... Also, do you need to reposition multiple windows of the same application? Scripts like this don't tend to have a very long life span though. It could be more useful to break it down into actions for launching each application, and for setting bounds for windows.
    • Mild Fuzz
      Mild Fuzz about 13 years
      No, I just need to open textmate, terminal, a finder window and firefox, firefox takes up all of one monitor, with the others sharing the larger display.
  • HikeMike
    HikeMike about 13 years
    Is it deliberately incomplete? dtw/dth (desktop width/height I think) are undefined.
  • brevno
    brevno about 13 years
    @Daniel They're on the second line of the script. :) And let's add it here, so it won't seem like I edited the post to add the dtw and dth — I just bumped into this while reading DF archives: Daring Fireball: Getting the Size of Your Display With AppleScript, the Lazy Way. It shows how bounds of window of desktop fails with multiple monitors.
  • HikeMike
    HikeMike about 13 years
    OK -- These lines looked just like the rest when I read it the first time. Nice find.