I found this one quite tough to Google.

I want to have a command (or an app) that opens these 2 applications just the way I want to. In this case I want to open them with these screen sizes -- more or less. If it has to be a terminal command, is it possible to create a shortcut for it? I will be creating more shortcuts for multiple app / screen size combinations.

My browser and text editor


Position your windows how you desire, then run the following AppleScript for each application.

tell application "Terminal" to tell window 1 to get bounds

This will return the bounds of the window, such as:

{200, 200, 700, 700}

Once you have your bounds of each window you wish to include in your specific window layout set, use the following to set the bounds:

tell application "Terminal" to tell window 1 to set bounds to {200, 200, 700, 700}

You can use multiple lines to set multiple window bounds at the same time.

Once you're happy with your layout, Script Editor can save the script as an application (File → Export and choose File Format: Application). This can then be added to your Dock for easy access.

If the application you're trying to manipulate is not scriptable, such as Sublime Text, you can use System Events to tell the application. This will require you to enable Accessibility control in System Preferences → Security & Privacy → Privacy → Accessibility.

To get the bounds of a window of a non-scriptable application, you can use:

tell application "System Events" to tell application process "Sublime Text" to ¬
    get {size, position} of window 1

This will return the size and position of the window, such as:

{{500, 500}, {200, 200}}

To set the bounds of a non-scriptable application, using the result of the previous code:

tell application "System Events" to tell application process "Sublime Text" to ¬
    tell window 1 to set {size, position} to {{500, 500}, {200, 200}}

If the application whose windows you are trying to manipulate are not open prior to running this script, use the following:

tell application "Terminal" to activate

This can be combined with setting the bounds using:

tell application "Terminal"
    tell window 1 to set bounds to {200, 200, 700, 700}
end tell

No delay is necessary since AppleScript will wait for the application to open.

  • In my script what I also needed to do was: do shell script "open -a 'Sublime Text'" (and the same for Google Chrome) and delay 0.2 in order to activate the windows (or open up the apps). If I didn't do this I'd get the error that it couldn't resize the app/process, because it wasn't running. I needed to do the delay to be sure that the shell scripts finish before I resize the windows. – Melvin Roest May 25 '17 at 13:22
  • 1
    @Melvin A better way is to tell the app to ‘activate’. This doesn't require running a separate script, and AppleScript waits for the app to open so no delay is necessary, and it will wait as long as required rather than a specific delay which may be too short. See edited answer – grg May 25 '17 at 13:40
  • Does that also work for non-scriptable apps? – Melvin Roest May 28 '17 at 15:06

You must log in to answer this question.

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