Skip to content

Instantly share code, notes, and snippets.

@danielsz
Last active August 29, 2015 14:08
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielsz/9c4ed2fbf4c0ac6b2d95 to your computer and use it in GitHub Desktop.
Save danielsz/9c4ed2fbf4c0ac6b2d95 to your computer and use it in GitHub Desktop.
(ns node-test.core
(:require [cljs.nodejs :as nodejs]))
(nodejs/enable-util-print!)
(def cp (.-spawn (nodejs/require "child_process")))
(defn run-cmd [cmd args call-back]
(let [child (cp cmd args)]
(.on (.-stdout child) "data" call-back)
(.on (.-stdout child) "end" #(println (str cmd " process ended")))))
(defn run-osa [args]
(run-cmd "osascript" #js ["-l" "JavaScript" "-e" args] println))
; the form to compile
(defn new-mail []
(let [mail (new js/Application "com.apple.mail")
inbox (.. mail -inbox -messages)
first-message (aget inbox 0)]
(.subject first-message)))
;; compiles to "(function new_mail(){var mail = (new Application('com.apple.mail'));var inbox = mail.inbox.messages;var first_message = (inbox[(0)]);return first_message.subject();})();"
(defn -main []
(run-osa "(function new_mail(){var mail = (new Application('com.apple.mail'));var inbox = mail.inbox.messages;var first_message = (inbox[(0)]);return first_message.subject();})();"))
(set! *main-cli-fn* -main)
(ns js-compiler.core
(:require
[cljs.compiler :as c]
[cljs.analyzer :as a]))
(defn emit-str [cljs]
(c/with-core-cljs
(let [env (a/empty-env)
ast (a/analyze env cljs)]
(with-out-str (c/emit ast)))))
@danielsz
Copy link
Author

This is a proof of concept to show how ClojureScript can be used in the context of Apple's JavaScript for Automation. This is not an integrated workflow. Tooling could be written to create a decent user experience.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment