Created
October 19, 2012 00:36
-
-
Save seiji/3915599 to your computer and use it in GitHub Desktop.
Control iOS Simulator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/Library/Frameworks/LuaCocoa.framework/Versions/Current/Tools/luacocoa | |
--[[ | |
Controll iOS Simulator | |
--]] | |
LuaCocoa.import("ScriptingBridge") | |
local system_events = SBApplication:applicationWithBundleIdentifier_("com.apple.systemevents") | |
local ios_sim_process = nil | |
if system_events ~= nil then | |
local processes = system_events:processes() | |
for i=1, #processes do | |
if tostring(processes[i]:name()) == "iPhone Simulator" then | |
ios_sim_process = processes[i] | |
end | |
end | |
else | |
print("SystemEvents not available") | |
end | |
if system_events ~= nil then | |
ios_sim_process:setFrontmost_(true) | |
local menu_items = ios_sim_process:menuBars()[1]:menus()[2]:menuItems() | |
local reset_option = nil | |
local quit_option = nil | |
--print(menu_items) | |
for i=1, #menu_items do | |
-- NSLog("%@", menu_items[i]:title()) | |
-- Note the ellipses is not 3 dots but Alt-Semicolon | |
if tostring(menu_items[i]:title()) == "Reset Content and Settings…" then | |
reset_option = menu_items[i] | |
elseif tostring(menu_items[i]:title()) == "Quit iOS Simulator" then | |
quit_option = menu_items[i] | |
end | |
end | |
if not reset_option then | |
print("Warning: Could not find 'Reset Content and Settings…', setting to last known index position") | |
reset_option = menu_items[3] | |
end | |
if not quit_option then | |
print("Warning: Could not find 'Quit iOS Simulator', setting to last known index position") | |
quit_option = menu_items[7] | |
end | |
-- Reset Contents | |
local ret_val = reset_option:clickAt_(reset_option:position()) | |
-- local quit_val = quit_option:clickAt_(quit_option:position()) | |
-- Give the system enough time for the "Are you sure?" dialog to appear | |
os.execute("sleep 1") | |
system_events:keystroke_using_(" ", 0) | |
-- Select Device iPad | |
-- 1 - iPad | |
-- 2 - iPad Retina | |
-- 3 - iPhone | |
-- 4 - iPhone Retina 3.5inch | |
-- 5 - iPhone Retine 4inch | |
local skin_index = 4 | |
menu_items = ios_sim_process:menuBars()[1]:menus()[5]:menuItems() -- Hardware | |
ios_device = menu_items[1]:menus()[1]:menuItems()[skin_index] | |
ios_device:clickAt_(ios_device:position()) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment