ob-applescript.el
ob-applescript.el copied to clipboard
AppleScript integration for Org Babel
#+startup: showall #+TITLE: AppleScript integration for Org Babel
This module lets you run AppleScript from AppleScript source code blocks with Org Babel.
This package is a direct result of attempting to answer a question on [[http://emacs.stackexchange.com/q/26374/10625][this emacs.stackexchange.com thread]].
-
Some simple examples
No arguments, no code -- just return a string.
#+BEGIN_SRC org ,#+BEGIN_SRC applescript "Hello World" ,#+END_SRC
,#+RESULTS: : Hello World #+END_SRC
You can, however, pass a variable to a block:
#+BEGIN_SRC org ,#+BEGIN_SRC applescript :var subject="World" "Hello " & subject ,#+END_SRC
,#+RESULTS: : Hello World #+END_SRC
You can use either =apples= or =applescript= as the language designation, to cater for two popular major modes. Use whichever you like. I prefer the font-locking of the =apples= one. This example also shows you can do interactive stuff.
#+BEGIN_SRC org ,#+BEGIN_SRC apples display alert "Danger! The WHAM is overheating!" ,#+END_SRC
,#+RESULTS: : button returned:OK #+END_SRC
If the result of the evaluation looks like a table, it'll become a table:
#+BEGIN_SRC org ,#+BEGIN_SRC apples "fi fo 1 2 3 4" ,#+END_SRC
,#+RESULTS: | fi | fo | | 1 | 2 | | 3 | 4 | #+END_SRC
-
Installation
=M-x package-install RET ob-applescript RET=
Then, load the package from your =~/.emacs.d/init.el=:
#+BEGIN_SRC emacs-lisp (require 'ob-applescript) #+END_SRC
-
Ideas for future work (you're welcome to help!)
-
=osascript= supports an interactive mode, which means I think it should be possible to support =:session=.
-
Adding some tests.
-
Adding some more documentation & examples.
-