• Stars
    star
    240
  • Rank 168,229 (Top 4 %)
  • Language
    Clojure
  • License
    Eclipse Public Li...
  • Created almost 3 years ago
  • Updated about 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Ad-hoc ClojureScript scripting of Mac applications via Apple's Open Scripting Architecture.

obb

project chat Stability: Experimental

Ad-hoc ClojureScript scripting of Mac applications via Apple's Open Scripting Architecture.

Status

Experimental.

Installation

Homebrew

$ brew install babashka/brew/obb

Manual

Download from Github releases.

Usage

Evaluate an expression:

$ obb -e '(-> (js/Application "Safari") (.-documents) (aget 0) (.url))'
"https://clojure.org/"
$ obb -e '(-> (js/Application "Google Chrome") (.-windows) (aget 0) (.activeTab) (.title))'
#js ["GitHub - babashka/obb: Ad-hoc ClojureScript scripting of Mac applications"]

Or evaluate a file:

$ obb examples/choice.cljs

Or make an executable script by using obb in a shebang:

#!/usr/bin/env obb
(-> (js/Application "Safari")
    (.quit))

How does this tool work?

ClojureScript code is evaluated through SCI, the same interpreter that powers babashka. SCI is compiled to JavaScript which is then by executed by osascript.

Macros

SCI supports macros as first class citizens so you can write a few macros to deal with interop boilerplate:

(defmacro ->clj [obj & interops]
  (let [names (map #(clojure.string/replace (str %) #"[.-]" "") interops)
        ks (mapv keyword names)
        exprs (mapv #(list % obj) interops)]
    `(zipmap ~ks [~@exprs])))

(-> (js/Application "Spotify") (.-currentTrack) (->clj .artist .album .name))
;;=>
{:artist "The Gathering", :album "How to Measure a Planet? (Deluxe Edition)", :name "Travel"}

References

Tips and tricks

Explore app specific APIs

Open Script Editor.app, go to File > Open Dictionary and select the application you would like to explore, e.g. Spotify.app. After selection, select JavaScript instead of AppleScript.

Application bundle

Read here how to create an application bundle from an obb script.

Sister projects

  • babashka: Native, fast starting Clojure interpreter for scripting.
  • nbb: Ad-hoc CLJS scripting on Node.js using SCI.
  • scittle: The Small Clojure Interpreter exposed for usage in browser script tags.

Build

Install Babashka. Then build with:

$ bb build

Then place out/obb anywhere on your path.

Dev

To develop obb you can use the bb dev task which starts a shadow-cljs server and a file watcher.

More Repositories

1

babashka

Native, fast starting Clojure interpreter for scripting
Clojure
3,642
star
2

sci

Configurable Clojure/Script interpreter suitable for scripting and Clojure DSLs
Clojure
1,221
star
3

nbb

Scripting in Clojure on Node.js using SCI
Clojure
772
star
4

neil

A CLI to add common aliases and features to deps.edn-based projects
Clojure
288
star
5

scittle

Execute Clojure(Script) directly from browser script tags via SCI
Clojure
278
star
6

process

Clojure library for shelling out / spawning sub-processes
Clojure
183
star
7

cli

Turn Clojure functions into CLIs!
Clojure
153
star
8

fs

File system utility library for Clojure
Clojure
139
star
9

babashka.curl

A This library is mostly replaced by https://github.com/babashka/http-client
Clojure
119
star
10

bbin

Install any Babashka script or project with one command
Clojure
115
star
11

pods

Pods support for JVM and babashka
Clojure
100
star
12

http-client

HTTP client for Clojure and Babashka built on java.net.http
Clojure
83
star
13

pod-registry

Pod manifests describe where pods can be downloaded, etc.
Clojure
82
star
14

babashka-sql-pods

Babashka pods for SQL databases
Clojure
72
star
15

pod-babashka-aws

Deprecated, use https://github.com/grzm/awyeah-api
Clojure
61
star
16

http-server

Serve static assets
Clojure
58
star
17

book

Babashka book
Clojure
55
star
18

babashka.nrepl

The nREPL server from babashka as a library, so it can be used from other SCI-based CLIs.
Clojure
52
star
19

pod-babashka-etaoin

Deprecated, use https://github.com/clj-commons/etaoin.
Clojure
41
star
20

tools-deps-native

Run tools.deps as a native binary
Clojure
40
star
21

pod-babashka-go-sqlite3

A babashka pod for interacting with sqlite3.
Go
27
star
22

pod-babashka-filewatcher

Babashka filewatcher pod based on Rust notify
Shell
22
star
23

json

JSON abstraction library
Clojure
19
star
24

pod-babashka-fswatcher

Babashka filewatcher pod.
Go
18
star
25

sci.configs

A collection of ready to be used SCI configs
Clojure
17
star
26

instaparse-bb

Use instaparse from babashka
Clojure
16
star
27

pod-babashka-buddy

A pod around buddy core (Cryptographic Api for Clojure).
Clojure
14
star
28

nbb-features

A collection of premade features for nbb
Clojure
10
star
29

toolbox

Script and template for Babashka Toolbox
HTML
9
star
30

pod-babashka-lanterna

Clojure
9
star
31

pod-babashka-malli

Exposing malli to babashka via a pod
Shell
8
star
32

nrepl-client

Clojure
8
star
33

pod-babashka-parcera

A babashka pod wrapping parcera
Clojure
7
star
34

conf

babashka-conf
Clojure
7
star
35

babashka.core

Babashka core utils
Clojure
5
star
36

pod-babashka-instaparse

Instaparse pod
Clojure
4
star
37

sci.nrepl

Clojure
2
star
38

babashka-dev-builds

2
star
39

.build

[INTERNAL] Common tooling for build orchestration
Clojure
1
star
40

babashka.github.io

Clojure
1
star
41

homebrew-brew

Ruby
1
star