Last active
August 29, 2015 14:08
-
-
Save danielsz/9c4ed2fbf4c0ac6b2d95 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
(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) | |
This file contains hidden or 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
(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))))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.