def input_box(title): box = NSAlert.alloc().init() box.addButtonWithTitle_(NSString.alloc().initWithString_("OK")) box.setMessageText_(NSString.alloc().initWithString_(title)) textbox = NSTextField.alloc().initWithFrame_(NSMakeRect(0, 0, 200, 24)); box.setAccessoryView_(textbox) box.runModal() return textbox.stringValue()
def set_alert_panel(message, info): buttons = ["OK", "Cancel"] alert = NSAlert.alloc().init() alert.setMessageText_(message) alert.setInformativeText_(info) alert.setAlertStyle_(NSInformationalAlertStyle) app = NSRunningApplication.runningApplicationWithProcessIdentifier_(os.getpid()) app.activateWithOptions_(NSApplicationActivateIgnoringOtherApps) for button in buttons: alert.addButtonWithTitle_(button) buttonPressed = alert.runModal() return buttonPressed
def install_command_line_tools(): target = '/usr/local/bin/yaybu' if os.path.exists(target): if os.path.islink(target) and os.readlink(target) == YAYBUC: NSLog("Command line tools already installed") return alert = NSAlert.alloc().init() alert.setMessageText_("Enable command line support?") alert.setInformativeText_("Yaybu can install a symlink at '/usr/local/bin/yaybu' allowing you to run yaybu from a terminal via the 'yaybu' command.") alert.setAlertStyle_(NSInformationalAlertStyle) alert.addButtonWithTitle_("Yes") alert.addButtonWithTitle_("No") if alert.runModal() == "No": return source = 'do shell script "test ! -d /usr/local/bin && mkdir -p /usr/local/bin; rm -f %s; ln -s %s %s" with administrator privileges' % (target, YAYBUC, target) script = NSAppleScript.alloc().initWithSource_(source) script.executeAndReturnError_(None)