Robusto
Robusto

Reputation: 31903

Can you access AppleScript APIs from shell script on Mac OS X?

I already do a lot with shell scripts on the Mac, but I loathe AppleScript, and I would love to be able to access Mac apps' APIs in some other way. Does anyone know any other way to get the power of AppleScript without the pain of its horrible syntax and meager documentation (and its slowness, if possible)?

Upvotes: 1

Views: 265

Answers (2)

macbutch
macbutch

Reputation: 3291

What about MacRuby? It isn't exactly shell scripting but it's not so far removed (and, arguably, much nicer).

Also not sure about the Applescript APIs specifically (not checked) but with HotCocoa you basically have access to Cocoa.

I've pinched this code snippet from here but as you can see it is very readable (this is code just to display a hello world window, admittedly not a typical scripting operation):

require 'hotcocoa'
include HotCocoa

application do |app|
 win = window :size => [100,50]
 b = button :title => 'Hello'
 b.on_action { puts 'World!' }
 win << b
end

Caveat - MacRuby is at v0.6 but is generally stable in my limited usage. Not exactly what you asked for but might be worth a look anyway.

Upvotes: 2

Nicholas Riley
Nicholas Riley

Reputation: 44341

appscript is probably your best bet - there are variants for Python or Ruby which should fit well into shell scripts.

There'll still be some trial and error in dealing with individual applications' vocabularies, which you can't really do much about, but at least you'll have a far more capable language (or two) to wrap around it.

Upvotes: 3

Related Questions