Skip to content

Instantly share code, notes, and snippets.

@irskep
Last active August 29, 2015 14:18
Show Gist options
  • Save irskep/372ec06c16df621828ca to your computer and use it in GitHub Desktop.
Save irskep/372ec06c16df621828ca to your computer and use it in GitHub Desktop.
var Safari = Application('Safari');
var SystemEvents = Application('System Events');
var SafariEvents = SystemEvents.processes['Safari'];
var openDevTools = function(deviceName, appName) {
var getDevSubMenuItem = function(i) {
return SafariEvents.menuBars[0]
.menuBarItems['Develop'].menus['Develop']
.menuItems[deviceName].menus[deviceName]
.menuItems[i];
}
try {
console.log("Finding correct menu...");
var labelIndex = 0;
while (getDevSubMenuItem(labelIndex).name() != appName) {
console.log("Skipping " + getDevSubMenuItem(labelIndex).name());
labelIndex += 1;
}
getDevSubMenuItem(labelIndex + 1).click();
Safari.activate();
return true;
} catch (e) {
return false;
}
}
var didSucceed = false;
while (!didSucceed) {
console.log("Attempting to open dev tools");
delay(1);
didSucceed = openDevTools("Slam Jamsen's iPhone", "HTML5 Fart App 2.0");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment