OSX automator in clojurescript
I don’t quite remember how I found the post, but anyways I landed upon this blog by @mbcrump about how automator now supports Javascript as a language. I don’t even remember how I got the idea of playing with clojurescript to get it to automate tasks, but definitively read it somewhere. Update: Now I was reminded: @borkdude retweeted
(let [mail (new js/Application "com.apple.mail")
inbox (.. mail -inbox -messages)
first-message (aget inbox 0)](.subject first-message)) 2/2
— Daniel Szmulewicz (@danielszmu) October 29, 2014
So how did I go about this?
Starting a new Clojurescript project
This is always a pain, since I hardly ever do it. I took a chance on David Nolens mies plugin for leinigen
This gives you a new project called applescript with a minimal directory-structure.
Transforming js to clojurescript
Given the js-code from @mbcrump’s post:
it was quite easy to translate it to clojurescript
builds it, but bob is not your uncle yet, since it will not run.
Making the stuff run
According to the post, it should only be a matter of running
to execute the script. Problem was, how to achieve this, telling leiningen to include all neccessary js into a file that osascript could run?
The solution
was in project.clj. changing
to
gave me one file, applescript.js, containing everything, which I could run as
#Bonus Just for fun, having a look at applescript.js, all the way at the bottom, you find:
Which translates pretty nicely to the original js-code.