Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Added a command-line argument and did some error trapping. #1

Merged
merged 3 commits into from almost 2 years ago

2 participants

Wil Langford Holger Rapp
Wil Langford

Added a command-line argument to shift everything to the right (for those, like me, who keep their dock on the left.)

At first, I mistakenly thought that the program moved windows among spaces, not screens. Added some error trapping to catch this and clue users in to what screens they have available.

Holger Rapp
Owner

Very nice changes! I'd love to move windows also between spaces - but apple does not provide applescript support for spaces (at least not in 10.6, I do not have access to Lion so I cannot say how the situation is there).

Holger Rapp SirVer closed this April 22, 2012
Holger Rapp SirVer reopened this April 22, 2012
Holger Rapp SirVer merged commit a34c513 into from April 22, 2012
Holger Rapp SirVer closed this April 22, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 3 unique commits by 1 author.

Apr 21, 2012
Added a bit of error checking to clue in those who thought this moved…
… among Spaces instead of screens.
3810dab
Added a left-limit command line option for those who keep their docks…
… on the left.
0f5ed8c
Set left_limit to 0 if not on screen 0. d3a732f
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 17 additions and 4 deletions. Show diff stats Hide diff stats

  1. 21  move_window
21  move_window
@@ -4,6 +4,7 @@
4 4
 import argparse
5 5
 import re
6 6
 import subprocess
  7
+from sys import exit
7 8
 
8 9
 import _mw_helper
9 10
 
@@ -13,6 +14,8 @@ def parse_args():
13 14
     parser = argparse.ArgumentParser(description='Move windows via AppleEvents')
14 15
     parser.add_argument('cmd', type=str, default="0",
15 16
                        help='<screen=0><xratio=1><xpos=0[-ypos]><yratio=1><ypos=0[-ypos]>')
  17
+    parser.add_argument('-L','--left-limit',type=int,default=0,dest='left_limit',
  18
+                       help='sets the left-hand limit (in pixels) so that windows do not get moved under a left-side dock')
16 19
 
17 20
     return parser.parse_args()
18 21
 
@@ -37,6 +40,7 @@ def move_window(x, y, w, h):
37 40
 
38 41
 def main():
39 42
     cmd = parse_args().cmd
  43
+    left_limit = parse_args().left_limit
40 44
     res = _mw_helper.get_resolutions()
41 45
 
42 46
     screen, cmd = (0, cmd) if not cmd else (int(cmd[0]), cmd[1:])
@@ -55,17 +59,26 @@ def main():
55 59
         x, y = 0, 22
56 60
         res[0][1] -= 22
57 61
     else:
58  
-        x = -res[1][0]
59  
-        y = 0
  62
+        try:
  63
+            x = -res[1][0]
  64
+            y = 0
  65
+            left_limit = 0
  66
+        except IndexError:
  67
+            if len(res)<=screen:
  68
+                print "Your screen(s):"
  69
+                for residx in range(len(res)):
  70
+                    print "   [{0}]: {1} x {2}".format(residx,res[residx][0],res[residx][1])
  71
+                print "Tried to move window to screen {0}, but it does not exist.".format(screen)
  72
+                exit()
60 73
 
61 74
     assert(screen in [0,1])
62 75
 
63  
-    one_width = (res[screen][0] / xratio)
  76
+    one_width = ((res[screen][0] - left_limit) / xratio)
64 77
     one_height = (res[screen][1] / yratio)
65 78
 
66 79
     w = one_width * (xpos_e - xpos_s + 1)
67 80
     h = one_height * (ypos_e - ypos_s + 1)
68  
-    x += one_width * xpos_s
  81
+    x += one_width * xpos_s + left_limit
69 82
     y += one_height * ypos_s
70 83
 
71 84
     move_window(x, y, w, h)
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.