Scheme instead of Applescript? - macos

Can I use Scheme instead of Applescript on the Mac to automate apps such as iTunes, iCal, Mail, etc.?

There is no fundamental reason that you could not build another language to construct the messages (Apple Events) that are passed through the OS to other processes. Back in the days of Classic, the MPW shell had constructs for doing exactly that.
Apple provides Open Scripting Architecture to support this kind of thing.
But...
Wikipedia reports that there are Javascript, Perl, Python, Ruby, and Tcl tools that can generate Apple Events with the Javascript OSA component being best integrated and a better MacRuby interface coming.
The result might not feel very scheme-like.

If it’s just that scheme is awesome, you are probably out of luck. But there are other options. appscript currently supports Ruby, Python, and Objective-C.
Combined with the ASTranslate application also linked on the appscript page, you should be able to do anything using appscript that you can do using AppleScript. I’ve used it to import FileMaker databases into MySQL, both directly and using Django, and also to control iTunes.
If you’re inclined that way, it might be possible to port appscript to scheme.

Silly suggestion(?) but: Douglas Crockford built a scheme interpreter in JavaScript, and you can script the mac (using OSA) using javascript. Could this work?

Related

Automating excel in python on a mac

I'm automating excel with python through the COM interface, with pywin32. I'd like to port my script to mac. Is there any chance of this happening? I realize that I can't use COM on a mac, and the xlutils python modules won't work (since I need to copy graphs, etc.). Is there anything else I can use?
Unfortunately development of appscript has been stopped,
I'm not aware the development of AppleScript has been stopped. What is your source on that?
As far as I can tell, AppleScript is still maintained and has a future and is working well.
Also there is a distinction between "AppleScript" the scripting language and the Inter-Application Communication Technology (IAC) called: "AppleEvents"
You can find the AppleScript Editor.app at the following location on your Mac:
/Applications/Utilities/AppleScript Editor.app
Open up the AppleScript Editor.app and then choose from the File menu: "Open Dictionary..."
Then select "Excel.app"
This will open the Apple Event dictionary for Excel. You will be able to see "Nouns" and "Verbs" and "Properties" that are supported in Excel for Apple Events.
AppleScript can be used to send commands to Excel via Apple Events, but so can other scripting languages such as Python.
If I were you, I would consider making an abstract class of Excel and two concrete subclasses, one that uses the Windows version of the code for Windows and anther that uses the Apple Event code that the Mac version of Excel might need.
See: the Wikipedia Article on Apple Events:
http://en.wikipedia.org/wiki/Apple_events
It's really Apple Events -- not AppleScript that you may want to use, but you could look at the following article too:
See Also: the Wikipedia Article on AppleScript:
http://en.wikipedia.org/wiki/AppleScript
--- edit ---
I believe that the misconception that Apple is lessening its support of AppleScript comes from the fact that AppleScript Studio was discontinued, but it was replaced with something just as good or better. Now, you can use AppleScript to develop full-fledged Mac applications in XCode. In addition, AppleScript can also still be used in Automator workflows, in XCode to build Automator actions, and in the AppleScript Editor, all of which are delivered by Apple in the latest version of OS X (Mountain Lion 10.8.4) and in the latest version of XCode (version 4.6.2)
So AppleScript is still a viable option, though the OP was asking about a Python solution. Apple Events are available from Python.
Currently the only possible solution would be appscript, which is a module that allows to write AppleScript macros in python (and ruby). Unfortunately development of appscript has been stopped, but for now it keeps working well enough.

Does Ruby offer a mechanism for responding to Apple Events on OS X?

I'm working on a desktop application for OS X using Ruby-Tk, and I would like to provide an Apple Events interface for the application. This means that the application would define a dictionary of AppleScript commands that it would respond to (corresponding to Apple Events being sent to the application), and users/other applications could script the Ruby-Tk application with AppleScript commands. Other scripting languages support such functionality--Python through the py-aemreceive library at http://appscript.svn.sourceforge.net/viewvc/appscript/py-aemreceive/ and Tcl through the tclAE library at http://tclae.sourceforge.net/. I've been looking for similar functionality in Ruby and have come up empty.
One possible mechanism is the rubyobjc bridge, which provides a low-level interface between Ruby and Objective-C, but this gem appears to be little-used and is sorely lacking in examples and documentation, so I am not sure if this would be a fruitful path to pursue.
NB: MacRuby might work but it is not compatible with Tk, so that rules out MacRuby. Also, RubyOSA and rb-appscript are not what I am looking for--they allow Ruby to send Apple Events to other applications, not receive them.
In the absence of other alternatives, it appears I am going to have to write my own Ruby wrapper for the portions of the AppleEvent C API that I need: mainly AEInstallEventHandler and related functions. Fortunately Apple still supports this API even though it has been relegated to "legacy" status in Apple's developer docs (though, interestingly, it is not deprecated). I'll either integrate these functions via Ruby's ffi gem or, more likely, via Ruby's C API (which I still have to dig into); using the C API directly would reduce the need for dependencies on other gems/modules. If this goes well I will release it as a gem.
Regarding Donal Fellows' comment, my need is for custom AppleEvents--the ones supported via Tk in the docs he recommends can likely be accessed through calls to Tk from Ruby's Tk interface.
You might want to check the appscript library (note: Seems to only work with the OS X-provided Ruby), or try using MacRuby, which wraps pretty much everything of the APIs available in OS X, even the C ones.

why use Google V8

I don't get it. I'm a C/C++ programmer, what's the possible use of V8 for me? There are few examples and tutorials out there, and they all lack substance - I don't want to use another library to just add a couple of numbers or print something in a console window.
My question is: is there a real use for this technology, and if yes, then would be the scenario?
Also, can I do any part of GUI this way?
Help is appreciated.
"V8 is Google's open source JavaScript engine"
So the whole point is ability to write code in JavaScript, and run it quite fast (for an interpreted dynamic language). Google Chrome, which is written in C++, uses it for internal scripting — not only for regular web page scripting, but also for extension code. Let's consider this as a 'real use'.
So, if your app needs scripting, V8 may be good for you (JS is not a perfect language, but stil quite decent). As for GUI, you'll need to bind your GUI components with JS first, there's no built-in UI components (as Tk in TCL).
One real use of v8 is node.js. I hope that is good enough
Google V8 is a JavaScript engine.
I don't really think it is what you are looking for.
V8 is a JavaScript engine. The most common use for it is to allow users of your software to write scripts in simpler language than that your software was written with (C++ in your case).
It´s the same approach of Matlab, AutoCad, Microsoft Office, and etc.
If you write any kind of commercial application, you can expose some APIs and allow other developer to create addons for your applications without require them to know C/C++.
How about this for real use: You can use javascript as a debugging or testing tool - add a javascript console to your app and bind the commands of your GUI application to javascript functions, and you'll be able to test your UI application using javascript scripts. This way you'll reduce the amount of manual testing needed - manual testing would only have to verify that a correct command was excutes as a result of user action.
You can do GUI in javascript the same way that Qt is being used in Python and other scripting languages (see PyQt, and QtRuby, PerlQt, etc.). For how to create bindings for V8 you may want to check out this

Scripting languages in XCode

I notice that Java has a number of ancillary scripting languages. Clojure and Groovy for example. My understanding is that these can be used when the full might and power of Java does not need to be applied and a speedy cludge can be hacked in Groovy/Clojure. But at the end of the day the scripting tools contribution gets compiled into the application
Question 1. Is there a similar scripting in XCode? I was not so interested in Python or Ruby in this situation as they are languages in their own right added in, as indeed I think can happen in Java, but I was looking for a purpose built tools.
Question 2. If there is such a tool would it count the application out vis-a-vis the new Apple guidelines as to what can be used to generate iXxx apps?
F-Script is a scripting language that integrates well with Objective-C/Cocoa applications. Might not be exactly what you're looking for, but it's worth a look.
For such things there is AppleScript, with its own IDE AppleScript Studio. It has bindings to control Cocoa Applications, be embedded inside of them or even work as stand-alone scripts.
The problem is that it cannot be integrated inside iXxx applications because iPhone-OS Cocoa Foundation framework doesn't include it.
As mentioned by mipadi, you can use F-Script for Cocoa applicaitons.
If you are staying mainly in C, then Lua is another option.

Starting programming Mac OS X

I'm starting a Mac OS X app that will connect to a small website I'm currently developing.
The idea is that the app will store a number of snippets on a local database and then sync with the website whenever it can.
So my questions are:
Carbon or Cocoa?
SQLite for local storage / another solution?
Is there any decent free text-editor control with basic syntax highlighting to embed on the app?
For new projects you should use Cocoa. Carbon is only useful to port already existing apps.
Cocoa brings it's own database backend called Core Data. It's quite simple to use but at the same time really powerful.
For syntax highlighting use a NSTextField, they are really powerful in Cocoa. One can even write highly graphical applications like Pages with it. For some examples of syntax highlighting see syntax highlighting on cocoadev.
You could also have a look at how other editors do it. For example there's Smultron, which is discontinued for the moment.
If you know ruby you can try out MacRuby. This let's you use ruby with the Cocoa classes. I'm quite sure that ruby will be the second programming language for the Mac because of its similarities to Objective-C.
At this point in each product's lifecycle, there is not really any compelling reason to use Carbon.
It's a fine API, and fine applications are written using it (Photoshop, iTunes), but a 64 bit version has not been made available, and it just seems that the writing is on the wall.
If you are just learning, and you want your knowledge to transfer to new projects in the future, Cocoa all the way.
Carbon is being phased out. You should really go for Cocoa.
Cocoa has its own database solutions (a flavor of SQL I think).
Cocoa. Carbon is going the way of the dodo and is only available in 32 bits.
And Xcode is free, with lots of syntax highlighting ;)
Check out this link for info about syntax highlighting in cocoa

Resources