Code Monkey home page Code Monkey logo

appdirt's Introduction

appdirt

Make command line Swift apps easily

appdirt is a small chunk of code that can be used to quickly bootstrap a Cocoa app that can be run from the command line, like a shell script.

Using appdirt, you can build quick little apps like scripts. Just include the code (see the section below on minified appdirt) at the top of your script, and write the rest yourself. appdirt exposes some constants of the app it bootstraps to make things easy to get started with.

What's in appdirt?

Runs without using a call to the swift REPL

appdirt is prefixed with #!/usr/bin/swift to allow the script to run directly with:

$ ./your_script

Note that you may have to chmod a+x your_script to get it to run.

Local Constants

  • window - an NSWindow with standard window controls. Closing the window with the close control will automatically close the script. This window supports fullscreen and split view
  • viewController - an NSViewController as the contentViewController of window
  • view - an NSView managed by viewController. It's configured to wantsLayer
  • layer - the CALayer acting as the backing store of view

Using minified appdirt

To help with brevity in your script, a minified version of appdirt is provided as appdirt-minified.swift. This provides a drop-in set of lines - condensed as much as possible - for you to use in your script. It exposes a run() function which can be used to start the NSApplication event loop. This is called at the end of appdirt-minified.swift.

Using appdirt

Most scripts will want to use the minified version of appdirt - see the section above.

To use un-minified appdirt, copy the contents of appdirt.swift into your script. At the end of your script, call NSApplication.sharedApplication().run() to start the NSApplication event loop.

Examples

appdirt comes with 2 examples:

An example webkit-based Wikipedia viewer wikipedia-example-script-with-minified-appdirt.swift wikipedia_screenshot (11 lines of script content)

An example map viewer maps-example-script-with-minified-appdirt.swift map_screenshot (12 lines of script content)

Licensing

See license.md.

appdirt's People

Contributors

peterhajas avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.