Skip to content

Instantly share code, notes, and snippets.

@JMichaelTX
Last active March 18, 2024 11:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JMichaelTX/2fe0678d2c0491a67942 to your computer and use it in GitHub Desktop.
Save JMichaelTX/2fe0678d2c0491a67942 to your computer and use it in GitHub Desktop.
JXA Alert Function - JavaScript for Automation

JXA Alert Function
See code below.

JMichaelTX JXA Gists
Because there is so little JavaScript for Automation (JXA) code that is published, I plan to publish as much as I can that will hopefully be of help to others learning JXA.

Much of what I publish will be based on the work of others, and I always try to cite those references in the code header. If I have failed to properly credit your code, please post a comment, and I will correct my Gist.

Your JXA Code
If you have example code you'd like to share, please post a link to your code. After having searched and evaluated various options for posting/sharing code, i have concluded that Github Gists is the best.

Bugs/Issues & Suggestions
If you find any bugs or issues, or have suggestions for improvement, please feel free to post a comment.

For more info, see JavaScript for Automation (JXA) Resources

// Assumes that var app has been created in top-level script
// var app = Application.currentApplication()
// app.includeStandardAdditions = true
app.beep()
var oAns = app.displayAlert(
"Alert Title", // main alert text
{
message: "Body Message",
as: "critical",
buttons: ['Cancel', 'Ignore', 'OK'],
defaultButton: 3,
cancelButton: 1
})
if (oAns.buttonReturned === "Cancel") {
// Quit the script?
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment