But it has a very annoying problem: if you run the script form within Illustrator the 'Outline Stroke' command fails. But, if you run the script in the Applescript editor with the illustrator document open it works. Which is just plain weird. If anybody understands why this is the case I'd love to hear the reason (and fix).

If anybody has any ideas for successfully outlining strokes in either Javascript or Applescript please respond.

Thanks Carlos, from reading the Illustrator scripting guide for Javascript there's no way to trigger menu commands. You can do that in Applescript, but you have to allow access to assistive devices first in order for it to work.

You can run menu commands but it looks like only those assigned a shortcut key… Not as useful as I had hoped… In CS6 there is also a new feature to send commands to plug-in… Now you might have some luck with that… but I have had none finding a real world example of how this works… My hope is that someone cracks this with pathfinder and other such plug-ins and posts here… There is one sample in the guides…

Yes, that does work. Unfortunately, it only works if all layers containing objects are unlocked. My problem requires me to outline only the items on certain layers, so I need to pick them off layer by layer.

I've accepted that I'm going to have to trigger my script outside of Illustrator. Not ideal, as the workflow is nicer when you trigger it from within. The only other thing I might try is to trigger a script in AI which then triggers my actual script. Sounds a bit mad, but it could work.

Part of the reason for my problems was trying to recursively select objects and then outline them; I've re-written my code to do all the slects together and then outline all of them together.

I've also got the file saving as an svg, but I've got one last problem: the svg being saved is a snapshot of the file *before* the outling takes place. In AI I can see the objects are outlined, but if I open the new svg file, they've been saved as stroked paths. This is my code:

It seems as though the export is being triggered and completing before the outlining can finish. I've tried adding a 'delay' but that doesn't seem to help. What I need is a callback function, but I'm not sure Applescript or Extendscript support them

I think a manual save after outlining is the answer. Without a callback function there's no way of knowing if the outlining has completed (other than writing a potentially endlessly looping script to check, but that just seems like a good way to cause a crash).