Skip to content

Instantly share code, notes, and snippets.

@n8henrie
Last active October 17, 2023 22:50
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 n8henrie/5b8ca8a764cc563f260d98c92ea7eb56 to your computer and use it in GitHub Desktop.
Save n8henrie/5b8ca8a764cc563f260d98c92ea7eb56 to your computer and use it in GitHub Desktop.
Automatically click "ok" on the dozens of error notifications I get when syncing with MacOS
#!/usr/bin/osascript -l JavaScript
function click_ok() {
const sys = Application('System Events')
const finder = sys.processes["Finder"]
try {
let sheets = finder.windows.whose({name: "NatePhone"}).sheets().flat()
let message = "cannot be played on this iPhone."
let error_sheet = sheets.filter(sheet => {
return sheet.staticTexts.whose({value: {_contains: message}}).first()
})[0]
let button = error_sheet.buttons.whose({name: "OK"}).first()
button.click()
return true
} catch (e) {
console.log(e)
return false
}
}
(function() {
var counter = 0
while (counter < 10) {
if (click_ok()) {
counter = 0
} else {
counter += 1
delay(0.5)
}
}
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment