How to present a window from an OSX Swift command line tool or shebang script file?
<p>How to present a window from an OSX Swift command line tool or shebang script file?</p>

<p>Ideally, no additional files are used. No storyboard. No xib.</p>

<p>One example would be an OS X Command Line Tools Xcode project with a single Swift file.</p>

<pre><code>import Cocoa // AppKit, CoreData, Foundation

let arguments = Process.arguments 

if (arguments.contains("usegui")) {
    // show arguments in a window with text field and dismiss button
    // GIVEN: some NSWindow
    let aTextField = NSTextField(frame: NSMakeRect(25, 320, 180, 24))
    aTextField.stringValue = arguments.description
    let mask = NSTitledWindowMask | NSClosableWindowMask
    let aWindow = NSWindow(
        contentRect: NSMakeRect(0, 0, 400, 210), 
        styleMask: mask, 
        backing: NSBackingStoreType.Buffered, 
        `defer`: false)
    aWindow.contentView!.addSubview(aTextField)
    // add button ... 

    /* How to 
    * (a) present the window? 
    * (b) have window dismissed by user?
    */

} else {
    print("Using text IO here.")
    print(arguments)
}
</code></pre>

<p>Another example would be in a shebang Swift script.</p>

<pre><code>#!/usr/bin/swift
import Cocoa // AppKit, CoreData, Foundation

let arguments = Process.arguments 

if (arguments.contains("usegui")) {
    // popup window showing arguments here
} else {
    print(arguments)
}
</code></pre>

<p>Background: Lot's of swift window examples exist in the context of an application.  And, many Swift REPL examples using text I/O.</p>

<p>Is there a reasonable way to popup an information window or request window from a swift CLI tool or swift script?</p>