Mercurial > xcodescriptingbridge
comparison ScriptingBridge_iOSSimulatorQuit.lua @ 7:8956367af822
Added ScriptingBridge_iOSSimulatorQuit.lua for Part 4
author | Eric Wing <ewing@anscamobile.com> |
---|---|
date | Thu, 11 Aug 2011 15:44:58 -0700 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
4:fdcbf6da59ec | 7:8956367af822 |
---|---|
1 #!/Library/Frameworks/LuaCocoa.framework/Versions/Current/Tools/luacocoa | |
2 | |
3 LuaCocoa.import("ScriptingBridge") | |
4 LuaCocoa.import("Foundation") | |
5 | |
6 -- Not finding through scripting bridge, so adding here | |
7 kAEDefaultTimeout = -1 | |
8 kNoTimeOut = -2 | |
9 | |
10 local next_skin = arg[1] or nil | |
11 | |
12 -- The simulator does not have a scripting dictionary. | |
13 -- We must manipulate it through system events. | |
14 --local iOSSimulator = SBApplication:applicationWithBundleIdentifier_("com.apple.iphonesimulator") | |
15 local system_events = SBApplication:applicationWithBundleIdentifier_("com.apple.systemevents") | |
16 system_events:setTimeout_(kNoTimeOut) | |
17 | |
18 --local iOSSimulator = systemEvents:processes():byName_("iPhone Simulator") | |
19 local processes = system_events:processes() | |
20 local ios_sim_process = nil | |
21 for i=1, #processes do | |
22 -- print("processes[".. tostring(i) .. "]" .. processes[i]:name()) | |
23 if tostring(processes[i]:name()) == "iPhone Simulator" then | |
24 ios_sim_process = processes[i] | |
25 end | |
26 end | |
27 | |
28 if not ios_sim_process then | |
29 print("Could not find iPhone Simulator process running. Aborting...") | |
30 os.exit(1) | |
31 end | |
32 | |
33 -- Bring the app to the foreground | |
34 ios_sim_process:setFrontmost_(true) | |
35 | |
36 --local menus = ios_sim_process:menuBars()[1]:menus() | |
37 local menu_items = ios_sim_process:menuBars()[1]:menus()[2]:menuItems() | |
38 local reset_option = nil | |
39 local quit_option = nil | |
40 --print(menu_items) | |
41 for i=1, #menu_items do | |
42 -- NSLog("%@", menu_items[i]:title()) | |
43 -- Note the ellipses is not 3 dots but Alt-Semicolon | |
44 if tostring(menu_items[i]:title()) == "Reset Content and Settingsā¦" then | |
45 reset_option = menu_items[i] | |
46 elseif tostring(menu_items[i]:title()) == "Quit iOS Simulator" then | |
47 quit_option = menu_items[i] | |
48 end | |
49 end | |
50 if not reset_option then | |
51 print("Warning: Could not find 'Reset Content and Settingsā¦', setting to last known index position") | |
52 reset_option = menu_items[3] | |
53 end | |
54 if not quit_option then | |
55 print("Warning: Could not find 'Quit iOS Simulator', setting to last known index position") | |
56 quit_option = menu_items[7] | |
57 end | |
58 | |
59 local ret_val = reset_option:clickAt_(reset_option:position()) | |
60 | |
61 -- A confirmation dialog appears and we must hit the correct button. | |
62 -- The sleep helps make sure the alert has enough time to show up. | |
63 os.execute("sleep 1") | |
64 --print(ret_val) | |
65 | |
66 -- This requires that keyboard navigation for buttons is on in Accessibility | |
67 system_events:keystroke_using_(" ", 0) | |
68 | |
69 | |
70 if next_skin == "iphone" then | |
71 next_skin_index = 2 | |
72 elseif next_skin == "ipad" then | |
73 next_skin_index = 1 | |
74 elseif next_skin == "iphone4" then | |
75 next_skin_index = 3 | |
76 end | |
77 | |
78 if next_skin_index then | |
79 | |
80 --menu_items = ios_sim_process:menuBars()[1]:menus()[5]:menuItems()[1]:menuItems() | |
81 -- Will take us to "Devices" | |
82 menu_items = ios_sim_process:menuBars()[1]:menus()[5]:menuItems() | |
83 local iphone_retina = nil | |
84 --[[ | |
85 for i=1, #menu_items do | |
86 NSLog("%@, %@", menu_items[i]:title(), menu_items[i]) | |
87 end | |
88 --]] | |
89 | |
90 -- Can't figure out how to tell if checked | |
91 --[==[ | |
92 local sub_menu_items = ios_sim_process:menuBars()[1]:menus()[5]:menuItems()[1]:menus()[1]:menuItems() | |
93 for i=1, #sub_menu_items do | |
94 NSLog("%@, %@", sub_menu_items[i]:title(), sub_menu_items[i]:value()) | |
95 end | |
96 --]==] | |
97 | |
98 -- Setting the simulator to iPhone 4 mode via menu Menu->Hardware->Devices->iPhone (Retina) | |
99 -- This is because our launch tool doesn't have a way to set between iPhone/iPhone4, | |
100 -- so we leave it as the last user preference. | |
101 iphone_retina = menu_items[1]:menus()[1]:menuItems()[next_skin_index] | |
102 iphone_retina:clickAt_(iphone_retina:position()) | |
103 end | |
104 | |
105 | |
106 -- Now quit the simulator via the menu option. | |
107 quit_option:clickAt_(quit_option:position()) | |
108 | |
109 os.exit(0) | |
110 |