Last active
August 29, 2015 14:12
-
-
Save ofstudio/099e2722fbcb234b0676 to your computer and use it in GitHub Desktop.
Example of dialogs / notifications scripting in OS X with Javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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 <[email protected]> | |
* | |
*/ | |
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