One of the greatest things on any platform is scripting. In some ways OSX offers better scripting than either Linux or Windows. That’s because the vast majority of applications on OSX are scriptable. (I actually think scripting on Windows is better except that outside of Microsoft few applications really enable scripting)
The biggest problem on OSX is the language Apple chose for scripting: Applescript. It’s one of those languages which is very easy to read and understand and very painful to actually write in. That’s why I prefer to do all my scripting in Python + Appscript. Appscript is a very nice addition to Python that allows you to do native scripting of applications with Python rather than Applescript.
In Python + Appscript you’d write
app('TextEdit').documents['Read Me'].paragraphs[1].get()
instead of
tell application "TextEdit"
get paragraph 1 of document "Read Me"
end tell
While I suppose one could argue the latter is easier to read the former is definitely easier to write. Especially when you start doing complex scripting.
The other big advantage is that you are writing in Python and can leverage all the libraries and source code that Python has.
Since converting between the two isn’t always obvious the Appscript install includes a program that will translate between Applescript and Python making it very easy to see how to write code.
The one downside to Python + Appscript is that there aren’t that many online resources for it. Since I do nearly all my scripting in Python now I’ll try and put up various tips for leveraging it in a practical fashion.
Related posts:
.jpg)
Recent Comments