Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Arrange Safari and Opera windows via AppleScript Web Browsers
I wrote two AppleScripts that arrange windows in Safari and Opera. The scripts don't just tile horizontally or vertically, but order browser windows in the most optimal way. The scripts automatically detect the screen resolution, and the number of open browser windows; they can arrange up to 12 separate windows. The Opera script, due to an Opera bug (perhaps?) has to be run twice.

Here's the Safari AppleScript:
################# Arrange_logically_Safari_windows:

-- Script by Julian (looiopnr/zec0ect/ristQws/pasurimi) 22.04.10
-- Purpose: Arrange logically Safari windows
-- Will detect automatically the screen resolution and the number of open Safari windows
-- Will arrange up to 12 windows.


tell application "Safari"
  set open_windows to (every window where visible is true)
  set n to count of open_windows
  
  tell application "Finder"
    set scr_size to bounds of window of desktop
    set scr_width to item 3 of scr_size
    set scr_height to item 4 of scr_size
  end tell
  
  set Compensation_A to 11
  set Compensation_B to 14
  set Compensation_C to 7
  
  if n = 1 then
    tell application "Safari"
      activate
      tell window 1
        set bounds to {0, 0, scr_width, scr_height}
      end tell
    end tell
  end if
  
  if n = 2 then
    tell application "Safari"
      activate
      tell window 1
        set bounds to {0, 0, scr_width / 2, scr_height}
      end tell
      activate
      tell window 2
        set bounds to {scr_width / 2, 0, scr_width, scr_height}
      end tell
    end tell
  end if
  
  if n = 3 then
    tell application "Safari"
      activate
      tell window 1
        set bounds to {0, 0, scr_width / 2, scr_height}
      end tell
      activate
      tell window 2
        set bounds to {((scr_width / 4) * 2), 0, scr_width, (scr_height / 2) - Compensation_A}
      end tell
      activate
      tell window 3
        set bounds to {((scr_width / 4) * 2), (scr_height / 2) + Compensation_A, scr_width, scr_height}
      end tell
    end tell
  end if
  
  if n = 4 then
    tell application "Safari"
      activate
      tell window 1
        set bounds to {0, 0, ((scr_width / 4) * 2), (scr_height / 2) - Compensation_A}
      end tell
      activate
      tell window 2
        set bounds to {((scr_width / 4) * 2), 0, scr_width, (scr_height / 2) - Compensation_A}
      end tell
      activate
      tell window 3
        set bounds to {0, (scr_height / 2) + Compensation_A, ((scr_width / 4) * 2), scr_height}
      end tell
      activate
      tell window 4
        set bounds to {((scr_width / 4) * 2), (scr_height / 2) + Compensation_A, scr_width, scr_height}
      end tell
    end tell
  end if
  
  if n = 5 then
    tell application "Safari"
      activate
      tell window 1
        set bounds to {0, 0, ((scr_width / 4) * 2), (scr_height / 2) - Compensation_A}
      end tell
      activate
      tell window 2
        set bounds to {0, (scr_height / 2) + Compensation_A, ((scr_width / 4) * 2), scr_height}
      end tell
      activate
      tell window 3
        set bounds to {((scr_width / 4) * 2), 0, scr_width, (scr_height / 3) - Compensation_C}
      end tell
      activate
      tell window 4
        set bounds to {((scr_width / 4) * 2), (scr_height / 3) + Compensation_B, scr_width, ((scr_height / 3) * 2) + Compensation_C}
      end tell
      activate
      tell window 5
        set bounds to {((scr_width / 4) * 2), ((scr_height / 3) * 2) + Compensation_C, scr_width, scr_height}
      end tell
    end tell
  end if
  
  if n = 6 then
    tell application "Safari"
      activate
      tell window 1
        set bounds to {0, 0, ((scr_width / 4) * 2), (scr_height / 3) - Compensation_C}
      end tell
      activate
      tell window 3
        set bounds to {0, (scr_height / 3) + Compensation_B, ((scr_width / 4) * 2), ((scr_height / 3) * 2) + Compensation_C}
      end tell
      activate
      tell window 5
        set bounds to {0, ((scr_height / 3) * 2) + Compensation_C, ((scr_width / 4) * 2), scr_height}
      end tell
      activate
      tell window 2
        set bounds to {((scr_width / 4) * 2), 0, scr_width, (scr_height / 3) - Compensation_C}
      end tell
      activate
      tell window 4
        set bounds to {((scr_width / 4) * 2), (scr_height / 3) + Compensation_B, scr_width, ((scr_height / 3) * 2) + Compensation_C}
      end tell
      activate
      tell window 6
        set bounds to {((scr_width / 4) * 2), ((scr_height / 3) * 2) + Compensation_C, scr_width, scr_height}
      end tell
    end tell
  end if
  
  if n = 7 then
    tell application "Safari"
      activate
      activate
      tell window 1
        set bounds to {0, 0, (scr_width / 3), (scr_height / 2) - Compensation_A}
      end tell
      activate
      tell window 2
        set bounds to {(scr_width / 3), 0, ((scr_width / 3) * 2), (scr_height / 2) - Compensation_A}
      end tell
      activate
      tell window 3
        set bounds to {0, (scr_height / 2) + Compensation_A, (scr_width / 3), scr_height}
      end tell
      activate
      tell window 4
        set bounds to {(scr_width / 3), (scr_height / 2) + Compensation_A, ((scr_width / 3) * 2), scr_height}
      end tell
      activate
      tell window 5
        set bounds to {((scr_width / 3) * 2), 0, scr_width, (scr_height / 3) - Compensation_C}
      end tell
      activate
      tell window 6
        set bounds to {((scr_width / 3) * 2), (scr_height / 3) + Compensation_B, scr_width, ((scr_height / 3) * 2) + Compensation_C}
      end tell
      activate
      tell window 7
        set bounds to {((scr_width / 3) * 2), ((scr_height / 3) * 2) + Compensation_C, scr_width, scr_height}
      end tell
    end tell
  end if
  
  if n = 8 then
    tell application "Safari"
      activate
      activate
      tell window 1
        set bounds to {0, 0, (scr_width / 3), (scr_height / 2) - Compensation_A}
      end tell
      activate
      tell window 2
        set bounds to {0, (scr_height / 2) + Compensation_A, (scr_width / 3), scr_height}
      end tell
      activate
      tell window 3
        set bounds to {(scr_width / 3), 0, ((scr_width / 3) * 2), (scr_height / 3) - Compensation_C}
      end tell
      activate
      tell window 4
        set bounds to {(scr_width / 3), (scr_height / 3) + Compensation_B, ((scr_width / 3) * 2), ((scr_height / 3) * 2) + Compensation_C}
      end tell
      activate
      tell window 5
        set bounds to {(scr_width / 3), ((scr_height / 3) * 2) + Compensation_C, ((scr_width / 3) * 2), scr_height}
      end tell
      activate
      tell window 6
        set bounds to {((scr_width / 3) * 2), 0, scr_width, (scr_height / 3) - Compensation_C}
      end tell
      activate
      tell window 7
        set bounds to {((scr_width / 3) * 2), (scr_height / 3) + Compensation_B, scr_width, ((scr_height / 3) * 2) + Compensation_C}
      end tell
      activate
      tell window 8
        set bounds to {((scr_width / 3) * 2), ((scr_height / 3) * 2) + Compensation_C, scr_width, scr_height}
      end tell
    end tell
  end if
  
  if n = 9 then
    tell application "Safari"
      activate
      activate
      tell window 1
        set bounds to {0, 0, (scr_width / 3), (scr_height / 3) - Compensation_C}
      end tell
      activate
      tell window 2
        set bounds to {0, (scr_height / 3) + Compensation_B, (scr_width / 3), ((scr_height / 3) * 2) + Compensation_C}
      end tell
      activate
      tell window 3
        set bounds to {0, ((scr_height / 3) * 2) + Compensation_C, (scr_width / 3), scr_height}
      end tell
      activate
      tell window 4
        set bounds to {(scr_width / 3), 0, ((scr_width / 3) * 2), (scr_height / 3) - Compensation_C}
      end tell
      activate
      tell window 5
        set bounds to {(scr_width / 3), (scr_height / 3) + Compensation_B, ((scr_width / 3) * 2), ((scr_height / 3) * 2) + Compensation_C}
      end tell
      activate
      tell window 6
        set bounds to {(scr_width / 3), ((scr_height / 3) * 2) + Compensation_C, ((scr_width / 3) * 2), scr_height}
      end tell
      activate
      tell window 7
        set bounds to {((scr_width / 3) * 2), 0, scr_width, (scr_height / 3) - Compensation_C}
      end tell
      activate
      tell window 8
        set bounds to {((scr_width / 3) * 2), (scr_height / 3) + Compensation_B, scr_width, ((scr_height / 3) * 2) + Compensation_C}
      end tell
      activate
      tell window 9
        set bounds to {((scr_width / 3) * 2), ((scr_height / 3) * 2) + Compensation_C, scr_width, scr_height}
      end tell
    end tell
  end if
  
  if n = 10 then
    tell application "Safari"
      activate
      activate
      tell window 1
        set bounds to {0, 0, (scr_width / 4), (scr_height / 2) - Compensation_A}
      end tell
      activate
      tell window 2
        set bounds to {(scr_width / 4), 0, ((scr_width / 4) * 2), (scr_height / 2) - Compensation_A}
      end tell
      activate
      tell window 3
        set bounds to {0, (scr_height / 2) + Compensation_A, (scr_width / 4), scr_height}
      end tell
      activate
      tell window 4
        set bounds to {(scr_width / 4), (scr_height / 2) + Compensation_A, ((scr_width / 4) * 2), scr_height}
      end tell
      activate
      tell window 5
        set bounds to {((scr_width / 4) * 2), 0, ((scr_width / 4) * 3), (scr_height / 3) - Compensation_C}
      end tell
      activate
      tell window 6
        set bounds to {((scr_width / 4) * 2), (scr_height / 3) + Compensation_B, ((scr_width / 4) * 3), ((scr_height / 3) * 2) + Compensation_C}
      end tell
      activate
      tell window 7
        set bounds to {((scr_width / 4) * 2), ((scr_height / 3) * 2) + Compensation_C, ((scr_width / 4) * 3), scr_height}
      end tell
      activate
      tell window 8
        set bounds to {((scr_width / 4) * 3), 0, scr_width, (scr_height / 3) - Compensation_C}
      end tell
      activate
      tell window 9
        set bounds to {((scr_width / 4) * 3), (scr_height / 3) + Compensation_B, scr_width, ((scr_height / 3) * 2) + Compensation_C}
      end tell
      activate
      tell window 10
        set bounds to {((scr_width / 4) * 3), ((scr_height / 3) * 2) + Compensation_C, scr_width, scr_height}
      end tell
    end tell
  end if
  
  if n = 11 then
    tell application "Safari"
      activate
      activate
      tell window 1
        set bounds to {0, 0, ((scr_width / 4) * 2), (scr_height / 3) - Compensation_C}
      end tell
      activate
      tell window 2
        set bounds to {0, (scr_height / 3) + Compensation_B, (scr_width / 4), ((scr_height / 3) * 2) + Compensation_C}
      end tell
      activate
      tell window 3
        set bounds to {0, ((scr_height / 3) * 2) + Compensation_C, (scr_width / 4), scr_height}
      end tell
      activate
      tell window 4
        set bounds to {(scr_width / 4), (scr_height / 3) + Compensation_B, ((scr_width / 4) * 2), ((scr_height / 3) * 2) + Compensation_C}
      end tell
      activate
      tell window 5
        set bounds to {(scr_width / 4), ((scr_height / 3) * 2) + Compensation_C, ((scr_width / 4) * 2), scr_height}
      end tell
      activate
      tell window 6
        set bounds to {((scr_width / 4) * 2), 0, ((scr_width / 4) * 3), (scr_height / 3) - Compensation_C}
      end tell
      activate
      tell window 7
        set bounds to {((scr_width / 4) * 2), (scr_height / 3) + Compensation_B, ((scr_width / 4) * 3), ((scr_height / 3) * 2) + Compensation_C}
      end tell
      activate
      tell window 8
        set bounds to {((scr_width / 4) * 2), ((scr_height / 3) * 2) + Compensation_C, ((scr_width / 4) * 3), scr_height}
      end tell
      activate
      tell window 9
        set bounds to {((scr_width / 4) * 3), 0, scr_width, (scr_height / 3) - Compensation_C}
      end tell
      activate
      tell window 10
        set bounds to {((scr_width / 4) * 3), (scr_height / 3) + Compensation_B, scr_width, ((scr_height / 3) * 2) + Compensation_C}
      end tell
      activate
      tell window 11
        set bounds to {((scr_width / 4) * 3), ((scr_height / 3) * 2) + Compensation_C, scr_width, scr_height}
      end tell
    end tell
  end if
  
  if n = 12 then
    tell application "Safari"
      activate
      activate
      tell window 1
        set bounds to {0, 0, (scr_width / 4), (scr_height / 3) - Compensation_C}
      end tell
      activate
      tell window 2
        set bounds to {0, (scr_height / 3) + Compensation_B, (scr_width / 4), ((scr_height / 3) * 2) + Compensation_C}
      end tell
      activate
      tell window 3
        set bounds to {0, ((scr_height / 3) * 2) + Compensation_C, (scr_width / 4), scr_height}
      end tell
      activate
      tell window 4
        set bounds to {(scr_width / 4), 0, ((scr_width / 4) * 2), (scr_height / 3) - Compensation_C}
      end tell
      activate
      tell window 5
        set bounds to {(scr_width / 4), (scr_height / 3) + Compensation_B, ((scr_width / 4) * 2), ((scr_height / 3) * 2) + Compensation_C}
      end tell
      activate
      tell window 6
        set bounds to {(scr_width / 4), ((scr_height / 3) * 2) + Compensation_C, ((scr_width / 4) * 2), scr_height}
      end tell
      activate
      tell window 7
        set bounds to {((scr_width / 4) * 2), 0, ((scr_width / 4) * 3), (scr_height / 3) - Compensation_C}
      end tell
      activate
      tell window 8
        set bounds to {((scr_width / 4) * 2), (scr_height / 3) + Compensation_B, ((scr_width / 4) * 3), ((scr_height / 3) * 2) + Compensation_C}
      end tell
      activate
      tell window 9
        set bounds to {((scr_width / 4) * 2), ((scr_height / 3) * 2) + Compensation_C, ((scr_width / 4) * 3), scr_height}
      end tell
      activate
      tell window 10
        set bounds to {((scr_width / 4) * 3), 0, scr_width, (scr_height / 3) - Compensation_C}
      end tell
      activate
      tell window 11
        set bounds to {((scr_width / 4) * 3), (scr_height / 3) + Compensation_B, scr_width, ((scr_height / 3) * 2) + Compensation_C}
      end tell
      activate
      tell window 12
        set bounds to {((scr_width / 4) * 3), ((scr_height / 3) * 2) + Compensation_C, scr_width, scr_height}
      end tell
    end tell
  end if
  
end tell
And for Opera:
### Arrange_logically_Opera_windows:

-- Script by Julian (looiopnr/zec0ect/ristQws/pasurimi) 22.04.10
-- Purpose: Arrange logically Opera windows
-- Will detect automatically the screen resolution and the number of open Opera windows
-- Will arrange logically up to 12 windows.
-- Due to a Opera bug(?) you have to run it twice.

tell application "Opera"
  set open_windows to (every window)
  set n to count of open_windows
  
  tell application "Finder"
    set scr_size to bounds of window of desktop
    set scr_width to item 3 of scr_size
    set scr_height to item 4 of scr_size
  end tell
  
  set Compensation_A to 33
  set Compensation_B to 32
  set Compensation_C to 34
  set Compensation_D to 5
  set Compensation_E to 27
  
  if n = 1 then
    tell application "Opera"
      activate
      tell window 1
        set bounds to {0, 0, scr_width, scr_height}
      end tell
    end tell
  end if
  
  if n = 2 then
    tell application "Opera"
      activate
      tell window 1
        set bounds to {0, 0, scr_width / 2, scr_height}
      end tell
      activate
      tell window 2
        set bounds to {scr_width / 2, 0, scr_width, scr_height}
      end tell
    end tell
  end if
  
  if n = 3 then
    tell application "Opera"
      activate
      tell window 1
        set bounds to {0, 0, scr_width / 2, scr_height}
      end tell
      activate
      tell window 2
        set bounds to {((scr_width / 4) * 2), 0, scr_width, (scr_height / 2) - Compensation_A}
      end tell
      activate
      tell window 3
        set bounds to {((scr_width / 4) * 2), (scr_height / 2) + Compensation_A, scr_width, scr_height}
      end tell
    end tell
  end if
  
  if n = 4 then
    tell application "Opera"
      activate
      tell window 1
        set bounds to {0, 0, ((scr_width / 4) * 2), (scr_height / 2) - Compensation_A}
      end tell
      activate
      tell window 2
        set bounds to {((scr_width / 4) * 2), 0, scr_width, (scr_height / 2) - Compensation_A}
      end tell
      activate
      tell window 3
        set bounds to {0, (scr_height / 2) + Compensation_A, ((scr_width / 4) * 2), scr_height}
      end tell
      activate
      tell window 4
        set bounds to {((scr_width / 4) * 2), (scr_height / 2) + Compensation_A, scr_width, scr_height}
      end tell
    end tell
  end if
  
  if n = 5 then
    tell application "Opera"
      activate
      tell window 1
        set bounds to {0, 0, ((scr_width / 4) * 2), (scr_height / 2) - Compensation_A}
      end tell
      activate
      tell window 2
        set bounds to {0, (scr_height / 2) + Compensation_A, ((scr_width / 4) * 2), scr_height}
      end tell
      activate
      tell window 3
        set bounds to {((scr_width / 4) * 2), 0, scr_width, (scr_height / 3) - Compensation_B}
      end tell
      activate
      tell window 4
        set bounds to {((scr_width / 4) * 2), (scr_height / 3) + Compensation_C, scr_width, ((scr_height / 3) * 2) + Compensation_D}
      end tell
      activate
      tell window 5
        set bounds to {((scr_width / 4) * 2), ((scr_height / 3) * 2) + Compensation_E, scr_width, scr_height}
      end tell
    end tell
  end if
  
  if n = 6 then
    tell application "Opera"
      activate
      tell window 1
        set bounds to {0, 0, ((scr_width / 4) * 2), (scr_height / 3) - Compensation_B}
      end tell
      activate
      tell window 3
        set bounds to {0, (scr_height / 3) + Compensation_C, ((scr_width / 4) * 2), ((scr_height / 3) * 2) + Compensation_D}
      end tell
      activate
      tell window 5
        set bounds to {0, ((scr_height / 3) * 2) + Compensation_E, ((scr_width / 4) * 2), scr_height}
      end tell
      activate
      tell window 2
        set bounds to {((scr_width / 4) * 2), 0, scr_width, (scr_height / 3) - Compensation_B}
      end tell
      activate
      tell window 4
        set bounds to {((scr_width / 4) * 2), (scr_height / 3) + Compensation_C, scr_width, ((scr_height / 3) * 2) + Compensation_D}
      end tell
      activate
      tell window 6
        set bounds to {((scr_width / 4) * 2), ((scr_height / 3) * 2) + Compensation_E, scr_width, scr_height}
      end tell
    end tell
  end if
  
  if n = 7 then
    tell application "Opera"
      activate
      activate
      tell window 1
        set bounds to {0, 0, (scr_width / 3), (scr_height / 2) - Compensation_A}
      end tell
      activate
      tell window 2
        set bounds to {(scr_width / 3), 0, ((scr_width / 3) * 2), (scr_height / 2) - Compensation_A}
      end tell
      activate
      tell window 3
        set bounds to {0, (scr_height / 2) + Compensation_A, (scr_width / 3), scr_height}
      end tell
      activate
      tell window 4
        set bounds to {(scr_width / 3), (scr_height / 2) + Compensation_A, ((scr_width / 3) * 2), scr_height}
      end tell
      activate
      tell window 5
        set bounds to {((scr_width / 3) * 2), 0, scr_width, (scr_height / 3) - Compensation_B}
      end tell
      activate
      tell window 6
        set bounds to {((scr_width / 3) * 2), (scr_height / 3) + Compensation_C, scr_width, ((scr_height / 3) * 2) + Compensation_D}
      end tell
      activate
      tell window 7
        set bounds to {((scr_width / 3) * 2), ((scr_height / 3) * 2) + Compensation_E, scr_width, scr_height}
      end tell
    end tell
  end if
  
  if n = 8 then
    tell application "Opera"
      activate
      activate
      tell window 1
        set bounds to {0, 0, (scr_width / 3), (scr_height / 2) - Compensation_A}
      end tell
      activate
      tell window 2
        set bounds to {0, (scr_height / 2) + Compensation_A, (scr_width / 3), scr_height}
      end tell
      activate
      tell window 3
        set bounds to {(scr_width / 3), 0, ((scr_width / 3) * 2), (scr_height / 3) - Compensation_B}
      end tell
      activate
      tell window 4
        set bounds to {(scr_width / 3), (scr_height / 3) + Compensation_C, ((scr_width / 3) * 2), ((scr_height / 3) * 2) + Compensation_D}
      end tell
      activate
      tell window 5
        set bounds to {(scr_width / 3), ((scr_height / 3) * 2) + Compensation_E, ((scr_width / 3) * 2), scr_height}
      end tell
      activate
      tell window 6
        set bounds to {((scr_width / 3) * 2), 0, scr_width, (scr_height / 3) - Compensation_B}
      end tell
      activate
      tell window 7
        set bounds to {((scr_width / 3) * 2), (scr_height / 3) + Compensation_C, scr_width, ((scr_height / 3) * 2) + Compensation_D}
      end tell
      activate
      tell window 8
        set bounds to {((scr_width / 3) * 2), ((scr_height / 3) * 2) + Compensation_E, scr_width, scr_height}
      end tell
    end tell
  end if
  
  if n = 9 then
    tell application "Opera"
      activate
      activate
      tell window 1
        set bounds to {0, 0, (scr_width / 3), (scr_height / 3) - Compensation_B}
      end tell
      activate
      tell window 2
        set bounds to {0, (scr_height / 3) + Compensation_C, (scr_width / 3), ((scr_height / 3) * 2) + Compensation_D}
      end tell
      activate
      tell window 3
        set bounds to {0, ((scr_height / 3) * 2) + Compensation_E, (scr_width / 3), scr_height}
      end tell
      activate
      tell window 4
        set bounds to {(scr_width / 3), 0, ((scr_width / 3) * 2), (scr_height / 3) - Compensation_B}
      end tell
      activate
      tell window 5
        set bounds to {(scr_width / 3), (scr_height / 3) + Compensation_C, ((scr_width / 3) * 2), ((scr_height / 3) * 2) + Compensation_D}
      end tell
      activate
      tell window 6
        set bounds to {(scr_width / 3), ((scr_height / 3) * 2) + Compensation_E, ((scr_width / 3) * 2), scr_height}
      end tell
      activate
      tell window 7
        set bounds to {((scr_width / 3) * 2), 0, scr_width, (scr_height / 3) - Compensation_B}
      end tell
      activate
      tell window 8
        set bounds to {((scr_width / 3) * 2), (scr_height / 3) + Compensation_C, scr_width, ((scr_height / 3) * 2) + Compensation_D}
      end tell
      activate
      tell window 9
        set bounds to {((scr_width / 3) * 2), ((scr_height / 3) * 2) + Compensation_E, scr_width, scr_height}
      end tell
    end tell
  end if
  
  if n = 10 then
    tell application "Opera"
      activate
      activate
      tell window 1
        set bounds to {0, 0, (scr_width / 4), (scr_height / 2) - Compensation_A}
      end tell
      activate
      tell window 2
        set bounds to {(scr_width / 4), 0, ((scr_width / 4) * 2), (scr_height / 2) - Compensation_A}
      end tell
      activate
      tell window 3
        set bounds to {0, (scr_height / 2) + Compensation_A, (scr_width / 4), scr_height}
      end tell
      activate
      tell window 4
        set bounds to {(scr_width / 4), (scr_height / 2) + Compensation_A, ((scr_width / 4) * 2), scr_height}
      end tell
      activate
      tell window 5
        set bounds to {((scr_width / 4) * 2), 0, ((scr_width / 4) * 3), (scr_height / 3) - Compensation_B}
      end tell
      activate
      tell window 6
        set bounds to {((scr_width / 4) * 2), (scr_height / 3) + Compensation_C, ((scr_width / 4) * 3), ((scr_height / 3) * 2) + Compensation_D}
      end tell
      activate
      tell window 7
        set bounds to {((scr_width / 4) * 2), ((scr_height / 3) * 2) + Compensation_E, ((scr_width / 4) * 3), scr_height}
      end tell
      activate
      tell window 8
        set bounds to {((scr_width / 4) * 3), 0, scr_width, (scr_height / 3) - Compensation_B}
      end tell
      activate
      tell window 9
        set bounds to {((scr_width / 4) * 3), (scr_height / 3) + Compensation_C, scr_width, ((scr_height / 3) * 2) + Compensation_D}
      end tell
      activate
      tell window 10
        set bounds to {((scr_width / 4) * 3), ((scr_height / 3) * 2) + Compensation_E, scr_width, scr_height}
      end tell
    end tell
  end if
  
  if n = 11 then
    tell application "Opera"
      activate
      activate
      tell window 1
        set bounds to {0, 0, ((scr_width / 4) * 2), (scr_height / 3) - Compensation_B}
      end tell
      activate
      tell window 2
        set bounds to {0, (scr_height / 3) + Compensation_C, (scr_width / 4), ((scr_height / 3) * 2) + Compensation_D}
      end tell
      activate
      tell window 3
        set bounds to {0, ((scr_height / 3) * 2) + Compensation_E, (scr_width / 4), scr_height}
      end tell
      activate
      tell window 4
        set bounds to {(scr_width / 4), (scr_height / 3) + Compensation_C, ((scr_width / 4) * 2), ((scr_height / 3) * 2) + Compensation_D}
      end tell
      activate
      tell window 5
        set bounds to {(scr_width / 4), ((scr_height / 3) * 2) + Compensation_C, ((scr_width / 4) * 2), scr_height + Compensation_D}
      end tell
      activate
      tell window 6
        set bounds to {((scr_width / 4) * 2), 0, ((scr_width / 4) * 3), (scr_height / 3) - Compensation_E}
      end tell
      activate
      tell window 7
        set bounds to {((scr_width / 4) * 2), (scr_height / 3) + Compensation_C, ((scr_width / 4) * 3), ((scr_height / 3) * 2) + Compensation_D}
      end tell
      activate
      tell window 8
        set bounds to {((scr_width / 4) * 2), ((scr_height / 3) * 2) + Compensation_E, ((scr_width / 4) * 3), scr_height}
      end tell
      activate
      tell window 9
        set bounds to {((scr_width / 4) * 3), 0, scr_width, (scr_height / 3) - Compensation_B}
      end tell
      activate
      tell window 10
        set bounds to {((scr_width / 4) * 3), (scr_height / 3) + Compensation_C, scr_width, ((scr_height / 3) * 2) + Compensation_D}
      end tell
      activate
      tell window 11
        set bounds to {((scr_width / 4) * 3), ((scr_height / 3) * 2) + Compensation_E, scr_width, scr_height}
      end tell
    end tell
  end if
  
  if n = 12 then
    tell application "Opera"
      activate
      activate
      tell window 1
        set bounds to {0, 0, (scr_width / 4), (scr_height / 3) - Compensation_B}
      end tell
      activate
      tell window 2
        set bounds to {0, (scr_height / 3) + Compensation_C, (scr_width / 4), ((scr_height / 3) * 2) + Compensation_D}
      end tell
      activate
      tell window 3
        set bounds to {0, ((scr_height / 3) * 2) + Compensation_E, (scr_width / 4), scr_height}
      end tell
      activate
      tell window 4
        set bounds to {(scr_width / 4), 0, ((scr_width / 4) * 2), (scr_height / 3) - Compensation_B}
      end tell
      activate
      tell window 5
        set bounds to {(scr_width / 4), (scr_height / 3) + Compensation_C, ((scr_width / 4) * 2), ((scr_height / 3) * 2) + Compensation_D}
      end tell
      activate
      tell window 6
        set bounds to {(scr_width / 4), ((scr_height / 3) * 2) + Compensation_E, ((scr_width / 4) * 2), scr_height}
      end tell
      activate
      tell window 7
        set bounds to {((scr_width / 4) * 2), 0, ((scr_width / 4) * 3), (scr_height / 3) - Compensation_B}
      end tell
      activate
      tell window 8
        set bounds to {((scr_width / 4) * 2), (scr_height / 3) + Compensation_C, ((scr_width / 4) * 3), ((scr_height / 3) * 2) + Compensation_D}
      end tell
      activate
      tell window 9
        set bounds to {((scr_width / 4) * 2), ((scr_height / 3) * 2) + Compensation_E, ((scr_width / 4) * 3), scr_height}
      end tell
      activate
      tell window 10
        set bounds to {((scr_width / 4) * 3), 0, scr_width, (scr_height / 3) - Compensation_B}
      end tell
      activate
      tell window 11
        set bounds to {((scr_width / 4) * 3), (scr_height / 3) + Compensation_C, scr_width, ((scr_height / 3) * 2) + Compensation_D}
      end tell
      activate
      tell window 12
        set bounds to {((scr_width / 4) * 3), ((scr_height / 3) * 2) + Compensation_E, scr_width, scr_height}
      end tell
    end tell
  end if
  
end tell
Perhaps useful for someone...

[robg adds: On my multi-monitor Mac, these scripts didn't work exactly as I expected -- they arranged the open windows across two of my three displays.]
    •    
  • Currently 2.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (4 votes cast)
 
[7,285 views]  

Arrange Safari and Opera windows via AppleScript | 8 comments | Create New Account
Click here to return to the 'Arrange Safari and Opera windows via AppleScript' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Arrange Safari and Opera windows via AppleScript
Authored by: momerath on Apr 29, '10 12:41:18PM

What's "logical" ? What's "most optimal"? It sounds like your self-proclaimed definitions are arbitrary.



[ Reply to This | # ]
Arrange Safari and Opera windows via AppleScript
Authored by: hejdor34 on Apr 29, '10 10:27:06PM

With "logical" and "most optimal" i mean user-friendly. The windows are not just tiled only horizontally or only vertically, and all the same size, but the first ranged (1,2,3) are are positioned at the top left of the screen and when it's possible, they are bigger sized then the rest of windows.
If you wish, you can take a look on YouTube, I posted there a short video: http://www.youtube.com/watch?v=nQBG0oMnR8w



[ Reply to This | # ]
Mariokartds
Authored by: weegeeborg on Apr 29, '10 12:56:30PM

once i get wifi ill get my code



[ Reply to This | # ]
Arrange Safari and Opera windows via AppleScript
Authored by: philostein on Apr 29, '10 06:51:01PM
Regarding the Opera script bug, I had the same issue moving windows around for lots of different apps. My solution was to double the code - so, for example, in your script:
tell window 2
	set bounds to {scr_width / 2, 0, scr_width, scr_height}
	set bounds to {scr_width / 2, 0, scr_width, scr_height}
end tell
Unfortunately, it would involve changing a lot of code!

Also, when I ran the Safari script from a different space the windows didn't move. Putting a delay 1 after activating Safari solved that.

I like the way the scripts arrange the windows - optimal for any sized monitor.

Cheers, PhilHints.

[ Reply to This | # ]
Arrange Safari and Opera windows via AppleScript
Authored by: Padraic on Apr 30, '10 01:29:39AM

I was actually just starting to do some research on how to do this myself in AppleScript. Thanks!



[ Reply to This | # ]
Arrange Safari and Opera windows via AppleScript
Authored by: renaultssoftware on Apr 30, '10 04:11:49AM

I've always wanted to know how to get screen resolution in AppleScript. I always thought it was a system command somewhere. But thanks!!



[ Reply to This | # ]
Unrolled?
Authored by: bcarter5876 on Apr 30, '10 09:17:22AM

Wouldn't this be a lot more concise with the use of some looping structures?



[ Reply to This | # ]
The Safari script works on Chrome and Firefox too.
Authored by: hejdor34 on Aug 11, '10 10:13:18PM

I noticed that the Safari script works perfectly on Chrome and Firefox. Simply replace all "Safari" strings with "Google Chrome" or "Firefox" ;-)



[ Reply to This | # ]