Thursday, September 06, 2007

ZopeEditManager, Safari, automation

Since Safari 3 debuted, I have been using Safari in lieu of Firefox, more and more. One feature I've missed is Firefox' ability to associate the ExternalEdit files from Plone with the ZopeEditManager. Click on the pencil, and voila, you're editing locally.



Well, I've finally figured out what to do to get this linked up in Safari. Enter Automator.



And if you're a Mac user like myself, it won't come as a surprise that it was actually quite easy.
  1. Launch Automator. You'll see a couple panes on the left (drag-src) and a pane on the right (drag-target).
  2. Your first workflow step will be Find Finder Items (the search box, top left, is a convenient way to find the workflow steps). 
  3. Select the folder where Safari will drop the .zem files (Desktop, in my case)
  4. Select "Name", "Ends with", and ".zem" for the criteria.
  5. Add the final criteria (yep, already on the last one!) - Open Finder Items.

     
  6. Nothing to configure on this workflow step, the default "Open with: Default Application" suits us just fine (note: if ZopeEditManager isn't associated with .zem files on your system, select ZopeEditManager in this drop-down).
  7. Almost done. Save your workflow as a "Folder Action" plugin. File ~ Save As Plug-in...

    Attached to Folder: should be the folder you selected in your first workflow step.
  8. Ctrl-click (i.e. right-click) on the folder you're targeting, select "Enable Folder Actions" if this is the first time you're using , Folder Actions on your system.
  9. Ctrl-click on the folder you're targeting, select Configure Folder Actions ...
  10. Click the "+" for the left pane, select your folder (e.g. Desktop)
  11. Click the "+" for the right pane, select your Automator workflow
  12. Close Folder Actions Setup, you're done!
Test it out by clicking an ExternalEdit link from Safari, should work like a charm.

Enjoy!

7 comments:

fuzzy said...

Smart!

Works well when opting to edit from within the ZMI (pencil icon) ... but for me, can't work with the 'Edit with external application' option that appears in a normal logged-in view of a page.

When I opt to 'Edit with external application', the resulting download lacks a .zem suffix to the filename.

Any suggestions?

Server: Plone 3.0.2 running on Mac OS X Server 10.4.10.

Client: WebKit nightly r27208 (29 October).

Brice said...

@graham

Hmm, ya know, I haven't used that capability, yet. I actually have wondered to myself why I don't get the external edit option on my content pages (and I think I know why, having just seen an option in site_properties a couple days ago). But, that said - I haven't tried that. Let me give it a shot and see what its doing with files.

Cheers,
Brice

p.s. my guess is the Firefox integration works because it still sends that funky mime-type, which this method isn't able to use.

fuzzy said...

In Plone 3: the site administrator's option
'Enable External Editor feature' appears at
Site Setup | Site, that's
/@@site-controlpanel

After that's enabled, then users have the option to 'Enable external editing' at
Dashboard | Personal Preferences,
/personalize_form

FWIW I use RCDefaultApp http://www.rubicode.com/Software/RCDefaultApp/ to set MIME types — and application/x-zope-edit is associated there with ZopeEditManager — but still, no joy with Safari whilst in page view.

Also, at http://plone.org/products/zope-externaleditor-client/ they're seeking help to get Zope External Editor Client (released August 2007) working properly with Mac OS X. It would be really nice to get this cracked!

Thanks

fuzzy said...

For reference: http://dev.plone.org/plone/ticket/7291

Brice said...

@graham

You may be in luck this evening (morning!) - I've come up with a script that will detect the header info that external_edit pops in the file when its downloaded. You may still want the original Automator script for .zem files - not sure if they contain the same header info or not (and its too late to check!)

But anyhow, the script I got working is a simple one-step workflow using "Run Shell Script" (gotta love UNIX).

Set "Pass input:" to "as arguments", then between the "do" and "done" (the loop body), put the following:

grep -l meta_type "$f" | xargs -I {} open -a ZopeEditManager -g {}

Breakdown:
1. grep -l will search for "meta_type" and print out just the name of the file, if it matches
2. xargs will take the printed filename from stdin and pass it to an invoked command, as a parameter
3. open -a will open the ZopeEditManager application (or just re-invoking, if already open) and pass the filename "{}" as a parameter. The "-g" just prevents "open" from bringing ZEM to the foreground (which isn't really desired, the app ZEM activates should come to the foreground.)

There ya go! Should work like a charm :)

Cheers,
Brice

fuzzy said...

Cool, thanks, I'll give that a go.

I'm also reading
http://macenterprise.org/content/view/201/84 (Modifying Safari Safe Files) and editing my
~/Library/Preferences/com.apple.DownloadAssessment.plist

fuzzy said...

Re http://dev.plone.org/plone/ticket/7291#comment:10 if I'm not mistaken, a minor change to Plone will allow ZopeEditManager to work with (at least) Camino.

(Prior to this, Camino tended to work better with the Zope Management Interface (ZMI), which adds .zem to file the file name, than with the standard Plone interface.)

I suspect that we are also tantalisingly close to Safari compatibility with ZopeEditManager.