Desired Outcome:
By holding down the key combination Shift-Command-Comma or Shift-Command-Period, you will be able to snap the active window to the left half or to the right half of the screen, respectively. This will allow you to show two windows side-by-side, which is nice for comparing two documents (or for having the baseball game scores and your work document open side-by-side).Step 1 - Open Automator
Automator is located in Macintosh HD > Applications. It has a cute little icon of a robot holding a pipe (representing workflows, I guess. Or maybe it is a bazooka). Double-click that little guy.Step 2 - Select "Service"
The first thing you see should be a dialog for choosing a template. Choose "Service" (the gear icon) and click Choose.Step 3 - Set the Input
We want to be able to launch the AppleScripts no matter where we are or which application we are currently runnning. Therefore, you need to set "Service receives selected" to "no input" in the drop down combo-box. You may leave the other comb-box as "any application".Step 4 - Insert the AppleScript
In the search box with the magnifying glass, type "Run AppleScript". This should give you one hit. Drag that action into the large gray workspace which says "Drag actions or files here to build your workflow".Delete the line that says (* Your script goes here*), and copy and paste the following code into that section:
tell application "Finder"
set screen_resolution to bounds of window of desktop
set screen_width to item 3 of screen_resolution
set screen_height to item 4 of screen_resolution
end tell
tell application "System Events"
set frontmostApplication to name of the first process whose frontmost is true
end tell
tell application frontmostApplication
activate
set the bounds of the first window to {0, 0, screen_width / 2, screen_height}
end tell
You can test it out by hitting the green play button. It should snap your current window (which in this case is the automator) to the left half of your screen. If you want to leave some borders, you can modify the bounds of the windows in the script.
Step 5 - Save as Service.
Choose File > Save as ...Give it a name, such as Tile_Left
Step 6 - Create a Tile_Right script
Go to File > New.Repeat steps 2 through 5. This time, you will insert the following code:
tell application "Finder"
set screen_resolution to bounds of window of desktop
set screen_width to item 3 of screen_resolution
set screen_height to item 4 of screen_resolution
end tell
tell application "System Events"
set frontmostApplication to name of the first process whose frontmost is true
end tell
tell application frontmostApplication
activate
set the bounds of the first window to {screen_width / 2, 0, screen_width, screen_height}
end tell
Save the file as a service. I called it Tile_Right
After this, you may quit Automator. Almost done!
Step 7 - Assign keyboard shortcuts to Tile_Left and Tile_Right
Open System Preferences (Go to Apple icon in top left corner and select "System Preferences..." Choose Keyboard > Keyboard Shortcuts > ServicesIn the right window, scroll down until you see your new services. Mine show up at the bottom under General. I called mine "Tile_Left" and "Tile_Right". Make sure the check marks are on for both of them.
To assign a keyboard short cut, highlight the action by clicking it once. Then click once on the right side of the highlighted region where the key commands will go (I know this is a confusing explanation - see picture for some guidance). Enter the key combination you would like to use. Note that some key combinations cannot be used or are already taken. I mapped Tile_Left to Shift-Command-Comma and Tile_Right to Shift-Command-Period. Just hold down those three keys and the symbols should show up to the right of the action.
Setting up keyboard shortcuts for AppleScript actions |
Nice and quite informative post. I really look forward to your other posts.
ReplyDeleteLenovo - 15.6" Essential Notebook - 4 GB Memory - 320 GB Hard Drive - Matte Black
Lenovo - 14" ThinkPad Edge Notebook - 4 GB Memory - 500 GB Hard Drive - Matte Black