Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Center the iOS Simulator's window on your screen
-- Center the iOS Simulator's window on your screen
--
-- Copyright (C) 2012 Sauce Labs Inc
--
-- This work is licensed under the Creative Commons Attribution 3.0 Unported License.
-- To view a copy of this license, visit http://creativecommons.org/licenses/by/3.0/
-- or send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.
--
-- Usage:
-- $ osascript center-ios-simulator.script <scale>
--
-- Examples:
-- $ osascript center-ios-simulator.script 50%
-- $ osascript center-ios-simulator.script 75%
-- $ osascript center-ios-simulator.script 100%
on run argv
set requested_scale to item 1 of argv
-- For debugging:
--tell application "System Events"
-- activate
-- display dialog requested_scale
--end tell
-- Set simulator scale
set sim_scale to "75%" -- default scale
if requested_scale is "50%" then
set sim_scale to "50%"
else if requested_scale is "75%" then
set sim_scale to "75%"
else if requested_scale is "100%" then
set sim_scale to "100%"
else
return "WARNING: Unrecognized scale for iOS Simulator. (Try '50%', '75%', or '100%')"
end if
tell application "iPhone Simulator" to activate
-- Select requested scale from menu
tell application "System Events"
tell process "iPhone Simulator"
tell menu 1 of menu bar item "Window" of menu bar 1
tell menu 1 of menu item "Scale"
click menu item sim_scale
end tell
end tell
end tell
end tell
-- Get screen dimension
tell application "System Events" to tell application "Finder"
set desktopSize to bounds of window of desktop
set screenWidth to item 3 of desktopSize
set screenHeight to item 4 of desktopSize
end tell
-- Center window on screen
tell application "System Events"
tell application process "iPhone Simulator"
set {windowWidth, windowHeight} to size of window 1
set newPosition to { ((screenWidth - windowWidth) / 2), ((screenHeight - windowHeight) / 2)}
tell window 1
set position to newPosition
end tell
end tell
end tell
-- Bring the window to the front
tell application "iPhone Simulator" to activate
end run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment