Xcode Plugin

This may be the wrong place for this question but I’ve got some very good help here before so it was the first place that popped into my head.

Anyway, I would like to write a plugin for Apples Xcode. Spacifically I want to add some new templates to Xcode and also to integrate some other things. In short, Im adding full Python support to Xcode.

What I really want to know is are these things possible (adding new templates, menu etc). Also, and please don’t take this the wrong way. Does this have to be done using Applescript? I know theres an applescript plugin template for Xcode… but I kinda had my heart set on doing it in Obj-C. If not, no problems but I would prefer it that way since I had a really hard time with documentation for Applescript before and i’m used to the C based syntax so :).

Thanks in advance!

Mark.

Xcode already has some Python support, though I’ve not used it myself so couldn’t say what. Best place to ask about Python-related stuff on OS X is the MacPython mailing list.

HTH

I have done a lot of work with plugins for xcode, and have run into many obstacles with the architecture. One of the biggest obstacles I found, was that since the plugin is loaded as a bundle of xcode, it does not gain application status of its own but rather allows xcode to hold the application status. This makes allocating large amounts of new memory and dealing with complex data structures quite a bit more difficult than if you were working in a standalone app. I’ve also found there to be a lot of quirks in the way the plugins handle various scripting methods. There seem to be some unexplained bugs or incompatibilities in the plugin architecture that I have yet to overcome. The plugin itself is not a subclass of say nsapplication or nsobject, but is a subclass of the “ASKplugin” class, which has little support and absolutely no documentation or examples. I have received wierd errors when using code within my plugin that is completely error-free when cut&pasted into a stand-alone app.

If you’ve messed with apple’s only plugin sample code found on the ‘plugin loaded’ doc, you’ve probably found that you indeed CAN create a menu quite easily… and depending on the planned intensity of your menu this may work fine for your needs. I would assume though, in your ambitions to add “full” support for just about anything to Xcode using a plugin, that your project will be fairly complex, thus…

The mode I’ve decided to employ, is to use a two-fold approach. Because I am using the “plugin” to do a lot of processing and data management, it’s proven to be unreasonable for me to rely solely on the plugin itself to do all of my work. I use the plugin merely as a gateway to my actual app. I have a menu created by the plugin that launches windows, pops up the about panel, checks for updates, etc. But I use it to call a ‘background application’ that handles all of the actual objects and code. Since I’m writing it myself, it is fairly simple to make calls to my BGapp and for the most part, once it’s activate it no longer communicates with my menu. As you can see, this may not be the perfect solution to everyone’s project design, as I’ve taken the functionality out of the menu and placed it in a window. The menu simply did not have the space and power to do what I’m doing.

As far as the AS/obj-c angle goes… I’d add whatever obj-c you can to your project. As I learn more about obj-c and get more comfortable using it, I find it to be more efficient, easier to code, and more flexible than just AS. No, it’s not possible to write it ENTIRELY out of obj-c, but you can use AS to open the door and then use obj-c to walk through it.

Like I said, I’ve put LOTS of hours into working with the plugin architecture. I’m still far from getting my plugin to real beta stage (mostly because I’m a slacker, though 8)). I’d be happy to share some of my insights with you in more detail, or to help you overcome obstacles if possible. I know that there are a few other people with some experience messing with plugins, too… and maybe they’d lend some insights, as well. PM me if you get to needing more input. I know NOTHING about python, but have come quite a ways with my knowledge of the xcode plugin architecture (after 10 dev versions of the same stupid unfinished plugin :rolleyes:)

Good luck,
j

Wow, thanks for the reply! I have to say that the lack-of-ease with which you can write plugins is very un-Mac like ;). Anyway I’m currently away from home but I’ll make sure I PM you when I get back.

I’m a long time Python guy myself, but having just moved to the Mac for Development I have a lot to learn on the subject, so, can’t say I would mind the help here. It would also be very interesting to get your thoughts on some idea’s.

For the plugin, I would spacifically like to be able to add templates for Python projects etc. other functionality could be added later as my understanding of the subject growns… feel like a newbie again ;). But I don’t really understand what requires the plugin to have AppleScript bindings in it, if a bundles a bundles a bundle, then the internals shouldn’t matter… right?

Thanks again,

Mark.

You should definitely subscribe to the PythonMac SIG - it’s the main hangout for MacPython users and where all the MacPython gurus are at. Also see Jack Jansen’s MacPython homepage. You might also want to check out my appscript project, which provides MacPython with application scripting support equal to AppleScript’s.

MacPython’s Cocoa bridge, PyObjC, includes templates for writing Cocoa apps in Python.

At a guess, they’re implementing the plugin mechanism through the OSA (Open Scripting Architecture), which includes support for nifty stuff like attaching scripts to application objects and calling their handlers. Which is good, in that the OSA itself is language neutral (any language with C bindings can become a ‘plug-n-play’ OSA scripting component by implementing the relevant interfaces), and not so good in that 1. there’s actually very few languages that have bothered to do so with any success (AppleScript, JavaScript OSA, UserTalk), and 2. Cocoa’s OSA support is quite lame and doesn’t support third-party OSA languages anyway. Which is really annoying for folks like me who are trying to get Python’s Apple Event Manager and Open Scripting Architecture up to scratch. Though if the MacPython folks would hurry up and remedy #1 then they might be in a better position to hassle Apple to fix #2 (i.e. we could definitely use more help).

If you want to write Xcode extensions using Python, I think your options are:

  1. [Python] shell scripts

  2. AppleScript plugins that execute Python scripts via ‘do shell script’

  3. AppleScript plugins that call a scriptable faceless background application written in Python (mail me privately if you want to know more about this)

There may be a 4th option, as I think Xcode has the ability to trigger shell scripts as it launches: you could implement your own simple Python plugin system (the ASK plugin system seems to be nothing more than a simple Observer pattern) that loads and executes Python scripts from disk. These scripts could then use appscript to manipulate Xcode just as you would with AppleScript. If you want to discuss further, mail me or post to the MacPython SIG (which I’m already subscribed to - along with plenty folk who know a lot more about Xcode and Python than I do:).

HTH

has

Hey Hamish,

I’ve been thinking about signing up to the MacPython stuff for a while, I would have done it already but since I’ve been traveling for the last 9 months my net time has been very limited. Luckily I’m about done and things are clearing up nicely in that area.

Anyway, after a little exploring I’ve discovered how to add templates to Xcode. Something that should be handy, and it shouldn’t be hard to knock up some basic Python templates. The next stage would be to build a new Window to house the Python shell and possibly a nice menu with some other handy bits i.e. an interface to Pythons help() function would be pretty nice.

I’ll email you in a few days to talk about the other ideas I’ve had. And about maybe helping out with some of the Projects you mentioned might need some extra helping along. The Python OSA library sounds very interesting :).

If anyone would like to get intouch with me directly about this you can find my contact details on Devshed at http://forums.devshed.com/member.php?u=24289

Take care,

Mark.

P.S. Just to explain, being that this is a primarliy Applescript forum. I don’t hate Applescript, infact for small scripts it’s a nice change from the norm’ and very useful. However after about a page things get a little hairy and it really makes me miss good old OOP. Or so is my opinion :wink: