Just A Moment…

Automatically Resize A Mac Application Window With Automator and AppleScript

Perfect For Screen Recordings

Recently, I needed to record a screencast of a Safari window with full hd dimensions (1920 x 1080). You could adjust the window size through trial and error but I figured there had to be an program or action that  would automate the process and allow me to specify the exact size I need. So I searched google and found two solutions that partly did what I want.

The first set up the script as a service in the application menu and the second centered the new screen on your computer. I combined the best of the two and hope that you will find it useful.

Setting it Up On Your Mac

If you’ve never worked with Automator on your mac, you’ll be surprised how many routine tasks you could automate (renaming a batch of files, nesting folders, automatically sorting new documents, etc). Here’s what you need to do.

  1. Launch automator and create new service.
    Automatically Resize Window Mac Automator
  2. Next, you will want to tell automator that there will be no input for this service.
    Automatically Resize Mac Application Window Using Automator
  3. Add the run AppleScript Action and paste in the code below. This is set to resize your window to 1920×1080 but you could specify any size you need.
    
        (* This AppleScript will resize the current application window to the height specified below and center it in the screen. Compiled with code from Natanial Wools and Amit Agarwal *)
        
        set the_application to (path to frontmost application as Unicode text)
        set appHeight to 1080
        set appWidth to 1920
        
        tell application "Finder"
            set screenResolution to bounds of window of desktop
        end tell
        
        set screenWidth to item 3 of screenResolution
        set screenHeight to item 4 of screenResolution
        
        tell application the_application
            activate
            reopen
            set yAxis to (screenHeight - appHeight) / 2 as integer
            set xAxis to (screenWidth - appWidth) / 2 as integer
            set the bounds of the first window to {xAxis, yAxis, appWidth + xAxis, appHeight + yAxis}
        end tell
        
    
  4. Save and name the service and it will appear under services in your application menu. Voilla! you’re done. Super easy right!
    Automatically Resize Window Mac Automator

If you have other Mac’s you would like to set this up on, you can export the service from automator. Copy it to the other mac and open it, it will prompt you to install the service or open in automator.