Skip to content

Instantly share code, notes, and snippets.

@ofstudio
Last active August 29, 2015 14:12
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 ofstudio/099e2722fbcb234b0676 to your computer and use it in GitHub Desktop.
Save ofstudio/099e2722fbcb234b0676 to your computer and use it in GitHub Desktop.
Example of dialogs / notifications scripting in OS X with Javascript
/**
* Example of dialogs / notifications scripting in OS X with Javascript
* Open /Applications/Script Editor.app, paste the code and click Run button
*
* @author Oleg Fomin <ofstudio@gmail.com>
*
*/
var result,
my_app = Application.currentApplication();
my_app.includeStandardAdditions = true;
result = my_app.displayDialog(
'What is your name',
{
defaultAnswer: 'John Doe'
}
);
my_app.displayNotification (
'Nice to see you',
{
withTitle: 'Cool script',
subtitle: 'Hello, ' + result.textReturned + '!'
}
);
result = my_app.displayDialog(
'Choose Red or Blue (10 seconds to answer)',
{
buttons: ['Red', 'Blue'],
defaultButton: 'Red',
givingUpAfter: 10
}
);
my_app.say('You choose ' + (result.buttonReturned === '' ? 'Red' : result.buttonReturned));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment