Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 20th, 2012  |  syntax: None  |  size: 2.33 KB  |  hits: 5  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. -- Center the iOS Simulator's window on your screen
  2. --
  3. -- Copyright (C) 2012 Sauce Labs Inc
  4. --
  5. -- This work is licensed under the Creative Commons Attribution 3.0 Unported License.
  6. -- To view a copy of this license, visit http://creativecommons.org/licenses/by/3.0/
  7. -- or send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.
  8. --
  9. -- Usage:
  10. -- $ osascript center-ios-simulator.script <scale>
  11. --
  12. -- Examples:
  13. -- $ osascript center-ios-simulator.script 50%
  14. -- $ osascript center-ios-simulator.script 75%
  15. -- $ osascript center-ios-simulator.script 100%
  16.  
  17. on run argv
  18.  
  19.     set requested_scale to item 1 of argv
  20.    
  21.     -- For debugging:
  22.     --tell application "System Events"
  23.     --    activate
  24.     --    display dialog requested_scale
  25.     --end tell
  26.  
  27.     -- Set simulator scale
  28.     set sim_scale to "75%" -- default scale
  29.     if requested_scale is "50%" then
  30.         set sim_scale to "50%"
  31.     else if requested_scale is "75%" then
  32.         set sim_scale to "75%"
  33.     else if requested_scale is "100%" then
  34.         set sim_scale to "100%"
  35.     else
  36.         return "WARNING: Unrecognized scale for iOS Simulator. (Try '50%', '75%', or '100%')"
  37.     end if
  38.    
  39.     tell application "iPhone Simulator" to activate
  40.    
  41.     -- Select requested scale from menu
  42.     tell application "System Events"
  43.         tell process "iPhone Simulator"
  44.             tell menu 1 of menu bar item "Window" of menu bar 1
  45.                 tell menu 1 of menu item "Scale"
  46.                     click menu item sim_scale
  47.                 end tell
  48.             end tell
  49.         end tell
  50.     end tell
  51.  
  52.     -- Get screen dimension
  53.     tell application "System Events" to tell application "Finder"
  54.         set desktopSize to bounds of window of desktop
  55.         set screenWidth to item 3 of desktopSize
  56.         set screenHeight to item 4 of desktopSize
  57.     end tell
  58.  
  59.     -- Center window on screen
  60.     tell application "System Events"
  61.         tell application process "iPhone Simulator"
  62.             set {windowWidth, windowHeight} to size of window 1
  63.             set newPosition to { ((screenWidth - windowWidth) / 2), ((screenHeight - windowHeight) / 2)}
  64.             tell window 1
  65.                 set position to newPosition
  66.             end tell
  67.         end tell
  68.     end tell
  69.  
  70.     -- Bring the window to the front
  71.     tell application "iPhone Simulator" to activate
  72.    
  73. end run