Last active
March 29, 2018 03:45
-
-
Save bacongravy/e36ed04c3411032417250edfbf91ae69 to your computer and use it in GitHub Desktop.
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
var me = Application.currentApplication(); me.includeStandardAdditions = true | |
ObjC.import('Cocoa') | |
ObjC.registerSubclass({ | |
name: 'MainController', | |
methods: { | |
'appDidLaunch:': { | |
types: ['void', ['id']], | |
implementation: function(notification) { | |
var appName = notification.userInfo.objectForKey('NSApplicationName').js | |
me.activate() | |
me.displayAlert(`Hello, ${appName}!`, {message: 'Nice to meet you.'}) | |
Application(appName).activate() | |
} | |
}, | |
'screensaverDidStop:': { | |
types: ['void', ['id']], | |
implementation: function(notification) { | |
me.activate() | |
me.displayAlert('Goodbye, screensaver!', {message: 'It was nice knowing you.'}) | |
} | |
} | |
} | |
}) | |
var controller = $.MainController.new | |
$.NSWorkspace.sharedWorkspace.notificationCenter.addObserverSelectorNameObject(controller, 'appDidLaunch:', $.NSWorkspaceDidLaunchApplicationNotification, undefined) | |
$.NSDistributedNotificationCenter.defaultCenter.addObserverSelectorNameObject(controller, 'screensaverDidStop:', 'com.apple.screensaver.didstop', undefined) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment