I want to set the position of some windows to certain coordinates.

In particular I have 4 possible positions that those windows should have.

For example if I have 4 windows opened I want them to go one per each position, instead if I have 6 windows opened I want the first 4 windows to go to to position 1,2,3,4 then the last 2 to position 1 and 2. I mean if I had 12 windows opened those should go to position 1,2,3,4,1,2,3,4,1,2,3,4.

At the moment I've managed to get the IDs of those windows in a list.

--list with all windows
set Auch to {...}

repeat with theWindow in Auch
    tell (windows whose title contains theWindow) -- it's working
        set position to {200, 20} --position #1
    end tell
end repeat

This is the code I've written: I'm sure there's a smart way to solve this problem.

1 Answer 1


Use the modulo operator !

set Auch to {...}      --list with all windows
set positionArray to {{..}, {..},{..}} -- The array where you store the positions you want. 

set ind to 0
repeat with theWindow in Auch
    tell (windows whose title contains theWindow)
        set position to item ((ind mod (count of positionArray)) + 1) of positionArray --AppleScript arrays start at 1 
        set ind to (ind + 1)
    end tell
end repeat
  • Sorry, I'm a newbie with applescript. How should I implement this into my code? I'm trying to understand your code :)
    – KingBOB
    Nov 30, 2013 at 18:58
  • I edited my code ! Dec 1, 2013 at 2:09
  • It gives me an error in this line "repeat with ind < (count of array). It says that "from" or "in" was expected instead of "<". However many thanks for your help!
    – KingBOB
    Dec 1, 2013 at 10:24
  • corrected, I had a typo with => while. Dec 1, 2013 at 12:35
  • Sorry if I ask again but now it gives me this error: " couldn't get "ind mod (count of positionArray) + 1". Access not allowed."
    – KingBOB
    Dec 1, 2013 at 14:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .