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

applescriptautomatormacos

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.

Best Answer

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/