• Welcome to Computer Association of SIUE - Forums.
 

OmniGraffle AppleScript

Started by William Grim, 2007-02-15T04:49:22-06:00 (Thursday)

Previous topic - Next topic

William Grim

Hello there!

I recently bought OmniGraffle in order to redo my thesis diagrams that were done in xfig, because xfig doesn't run on OS X without the hideousness of X11.  OmniGraffle is a freaking AWESOME diagramming tool, but it lacked one feature I need: file conversions on the command-line in order to convert from .graffle to .eps.

So anyway, I know a few of you have Macs, and this might be of some use to you.  It's an AppleScript I wrote that can be used from the command-line to tell OmniGraffle to convert an input file to an output file... it will automatically convert from/to any types known by OmniGraffle.

It's nothing fancy, but it is nifty if you're like me and need to integrate your diagram conversions into some large build system using something like GNU/Make.  It would royally suck to have to convert 10+ images by hand and to make sure they're always up-to-date.

So, here it is, and I hope it helps at least one of you:


on run argv
if length of argv is 0 then
return "Usage: OmniGraffleConverter.scpt "
end if

set infile to item 1 of argv
set outfile to item 2 of argv

set infile to (POSIX file infile) as string
set outfile to (POSIX file outfile) as string

tell application "OmniGraffle"
activate

open file infile
save front window in outfile
quit application saving no
end tell
end run


To use it, first open Script Editor and paste it into there.  Then, save it as OmniGraffleConverter.scpt, which will become a binary file.  On the command-line, do "osascript OmniGraffleConverter.scpt ", and it'll do some internal stuff to format the arguments and then pass the information to OmniGraffle.

Enjoy!
William Grim
IT Associate, Morgan Stanley

Peter Motyka

Quotebecause xfig doesn't run on OS X without the hideousness of X11.
You really find the X11 environment that horrible?  Seems pretty usable for me.  So far, I've resisted MS Office and Photoshop.  Gimp and Open Office are very usable on OS X.  Perhaps I'll get frustrated it by the time these apps get ported to OS X native.

Great script!  Does the output from OmniGraffle look any better than xfig?
SIUE CS Alumni 2002
Grad Student, Regis University
Senior Engineer, Ping Identity
http://motyka.org

William Grim

Quotepmotyko wrote:

You really find the X11 environment that horrible? Seems pretty usable for me. So far, I've resisted MS Office and Photoshop. Gimp and Open Office are very usable on OS X. Perhaps I'll get frustrated it by the time these apps get ported to OS X native.

Yeah, I do find the X11 environment that bad.  It doesn't mesh with the existing environment at all, and pretty much none of the shortcut keys work as expected, because OS X consumes those keys first.  I seem to recall cut/paste not working as expected either.

I'd have to say that MS Office on the Mac is pretty dang good (I still use Latex for "word processing" though, but there are exceptions), and I'd think about Photoshop pretty hard if I needed it.  However, there is a program called Inkscape I was thinking of checking out.  I am not sure, but I don't think it requires X11 running to use it.

Quotepmotyko write:

Great script! Does the output from OmniGraffle look any better than xfig?

I'll let you be the judge of how good OmniGraffle output looks by going here! :-)  I think it looks better, and it's way easier to setup complicated diagrams.  I only took about 2 minutes setting up that diagram; think of how long it'd take in xfig.
William Grim
IT Associate, Morgan Stanley

JR


I hate OpenOffice on OS X more than M$ Office (and that's saying a lot).
Retired President of CAOS

William Grim

I'd have to agree with jrat: the man with a new-found burly beard.  MS Office > OpenOffice on OS X.

Even on Windows, where OpenOffice runs well, I still have to say MS Office smokes it.  I mean we all know I like FOSS stuff, but MS Office unfortunately does reign supreme over OpenOffice.

You know what rocks on OS X though?  APPLESCRIPT!  It's like magic in a box!  You can make all sorts of additions to programs that weren't added by the original authors without having to write full-out extensions!  And the best part is that it's pretty much synonymous with shell scripting for the GUI :)  I know there is VBScript on Windows, but I don't think it's as powerful as this.
William Grim
IT Associate, Morgan Stanley

Kit

I'd have to say that I had a lot of difficulty with MS Office 2003 on XP whereas OO just usually worked. That is, until it started to crash on me.

I recently got Office 2007 and I like it so much I'll never go back to OO.
SIUe Computer Science Graduate

William Grim

Update to the script that now accepts multiples files on the command line:


on run argv
        if length of argv is 0 then
                return "Usage: OmniGraffleConverter.scpt "
        end if

        set i to 0
        repeat with arg in argv
                if i is equal to 0
                        set i to i+1
                        set infile to (POSIX file arg) as string
                else
                        set outfile to (POSIX file arg) as string
                        tell application "OmniGraffle"
                                activate

                                open file infile
                                save front window in outfile
                                --delay 0.30
                                close front window
                        end tell
                        set i to i-1
                end if
        end repeat

        delay 1.0
        tell application "OmniGraffle" to quit application saving ask
end run


This code runs faster wih my Makefiles.
William Grim
IT Associate, Morgan Stanley