1

Does anyone know how to setup org-mode so that you can write/process applescript from within org source code blocks? I.e.,

#+BEGIN_SRC applescript

tell application "Emacs"
    [do something amazing]
end tell

#+END_SRC

Thanks!

3 Answers 3

5

It's super rough, but I managed to get a very, very basic integration working last night. Hope it is useful: https://github.com/stig/ob-applescript.el -- that should at least give you something to work with.

3
  • Awesome! Thanks Stig — great job!!!
    – Adam
    Commented Sep 12, 2016 at 21:33
  • You're welcome. If this PR is merged you should be able to install this module from Melpa. I also updated the module to support the apples-mode major mode, and table output. Commented Sep 14, 2016 at 21:18
  • You can now install this using package.el from MELPA. Commented Dec 20, 2016 at 11:18
2

Not sure if Org Babel supports AppleScript, but it supports bash. You can run applescript from Bash using osascript and a bash heredoc:

#+BEGIN_SRC sh
  osascript <<'END'
  display dialog "Hello, World"
  END
#+END_SRC

SE doesn't allow proper formatting. The END statement should be all the way to the left, with no spaces before it.

2
  • Emacs supports do-applescript (an alias for ns-do-applescript) from ns-win.el, so it could also be an elisp code block that calls said function.
    – lawlist
    Commented Aug 19, 2016 at 4:16
  • Thanks @mankoff! Good tip. I was hoping to find a way to support AppleScript directly though, so I could apply font-locking...
    – Adam
    Commented Aug 20, 2016 at 12:01
1

Would a bit of indirection be OK? You can use noweb to have an applescript block inserted into a shell block for execution…

#+name: hello-apples
#+BEGIN_SRC apples
display dialog "Hello, World"
#+END_SRC

#+BEGIN_SRC sh :noweb yes :exports both
osascript -e '<<hello-apples>>'
#+END_SRC

#+RESULTS:
: button returned:OK

I'm using apples-mode because it appears to have better font-locking than applescript-mode but you can use either.

3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.