Skip to content

Instantly share code, notes, and snippets.

@mbierman
Last active December 11, 2015 05:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mbierman/4556236 to your computer and use it in GitHub Desktop.
Save mbierman/4556236 to your computer and use it in GitHub Desktop.
Open Mobile Safari to a particular URL, set the user agent to iPhone, and center on screen.
-- Sets Safari to iPhone user agent and loads mobile.walmart.comf
set theURL to "http://mobile.walmart.com"
tell application "Safari" to activate
tell application "Safari"
activate
try
tell window 1 to set current tab to make new tab with properties {URL:theURL}
on error
open location theURL
end try
tell application "System Events"
tell process "Safari"
click menu item "Safari iOS 5.1 — iPhone" of menu "User Agent" of menu item "User Agent" of menu "Develop" of menu bar item "Develop" of menu bar 1
keystroke "r" using {command down}
end tell
end tell
end tell
-- Roughly an iPhone 5 dimension
tell application "Finder"
set screenSize to bounds of window of desktop
set screenWidth to item 3 of screenSize
end tell
tell application "System Events"
set myFrontMost to name of first item of ¬
(processes whose frontmost is true)
end tell
set front_app to (path to frontmost application as Unicode text)
tell application front_app
activate
set bounds of window 1 to {0, 100, 350, 795}
end tell
-- Center the window
try
tell application myFrontMost
set windowSize to bounds of window 1
set windowXl to item 1 of windowSize
set windowYt to item 2 of windowSize
set windowXr to item 3 of windowSize
set windowYb to item 4 of windowSize
set windowWidth to windowXr - windowXl
set bounds of window 1 to {¬
(screenWidth - windowWidth) / 2.0, ¬
windowYt, ¬
(screenWidth + windowWidth) / 2.0, ¬
windowYb}
end tell
end try
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment