Follow Slashdot stories on Twitter

 



Forgot your password?
typodupeerror
×
Perl Businesses Programming Apple

Perl Carbon/Cocoa Bindings on Mac OS X? 57

gigawattwarlock asks: "As an almost new Mac OS X user (I've been adminning my wife's Mac for a while now), I am used to writing Perl scripts for her Mac, which work just fine. Simply put, I have become spoiled with the GTk bindings for Perl on Linux. I love being able to use and abuse a robust GUI, quickly and easily. And to make matters worse, I find the Aqua interface near addictive ... enough so that the idea of installing another desktop environment (KDE, Gnome, et. al) just seems a little silly, and a bit of overkill, to me. Does anyone know if there are any perl bindings in the works for Mac OS X or maybe even an already existent alternative graphical library or interface within Mac OS X?"
This discussion has been archived. No new comments can be posted.

Perl Carbon/Cocoa Bindings on Mac OS X?

Comments Filter:
  • camelbones (Score:5, Informative)

    by Fiery ( 21015 ) <rsoderberg@gmail.com> on Thursday June 06, 2002 @05:52PM (#3655478) Homepage
    Here's a project [sf.net] that's doing this. They seem to have functioning code, too.
    • Camelbones works pretty well, but the documentation is nearly non-existant, unfortunately. But if you've used AppKit and Foundation from Objective-C (or Java, I suppose) then it shouldn't be too hard to figure out from the examples.

      I made a few simple test programs and didn't have any trouble, but I have a feeling that some of the more esoteric bits of Cocoa might not work too well.

      The PerlObjective-C bridge is pretty good. Perl is pretty well suited for interacting with Objective-C (better than Java, certainly) due to its dynamic nature.

      • Camelbones works pretty well

        Thanks, I'm glad you like it.

        the documentation is nearly non-existant, unfortunately.

        Guilty as charged. All I can say is, I didn't think very many people were interested in it; I can count the daily hits on the project page with one hand. Seems like the interest level is higher than I thought, though, so I'll get off my lazy ass and write more docs, pronto.
        • I would certainly like to see more about this project. I didn't even know it existed until this post. Would love to see some screen shots on the main page. I would even be interested in helping a little, if need be (and time permits).

          -Alex
        • Guilty as charged. All I can say is, I didn't think very many people were interested in it; I can count the daily hits on the project page with one hand. Seems like the interest level is higher than I thought, though, so I'll get off my lazy ass and write more docs, pronto.

          Please do, I've had it installed for a while now, and am very happy with it!
  • Hey, for those Ask Slashdot-style question stories in non-AS categories, could you guys please try to remember to put a question mark in the title?

    An announcement of a Perl binding for Cocoa is somewhat interesting to me, but in general AS's aren't.
  • Just use Objective C (Score:5, Informative)

    by foobar104 ( 206452 ) on Thursday June 06, 2002 @06:06PM (#3655588) Journal
    Yeah. There are several, in various stages of incompleteness.

    But why don't you just read the tutorial and learn to program Cocoa with Objective C? Programming Cocoa apps with Objective-C, using Project Builder and Interface Builder, is, I dare say, easier than writing Perl scripts that call Cocoa functions would be. You don't even need to be terribly familiar with C to write simple apps.

    Don't get me wrong. I love Perl as much as the next guy. But I don't like writing GUI code. It's a pain in the ass, no matter how nice the programming language might be. The combination of Interface Builder and Objective C makes whipping up little Cocoa apps easy as pie, and fun, too.

    You can find the Objective-C Cocoa tutorial in PDF form here [apple.com]. It's also included with the OS X developer's tools under /Developer/Documentation/Cocoa/ObjCTutorial.
    • by BitGeek ( 19506 )
      Please mod this parent up, its NOT off topic.

      The reason is this: Getting access to perl code you've written or integrating perl with an Obj-C API is really easy using this method.

      If you write an application in Obj C (or Java-- actually Java would be my choice) you get to use interface builder to build your UI-- this is the best/fastest way to build a great UI. Then, its a simple matter of linking that UI to the perl scripts you've already written.

      This can be done in a number of ways, the most explicit being to simply call the shell from within your ObjC application.

      ObjC (despite my prior prejudice against it) is turning out to be a pretty decent and relatively easy language to learn. And, of course, when you consider Interface Builder its the best way to build an interface for any language-- just write minimal ObjC to tie your buttons, etc, to the bulk of your code.

      I imagined you'll spend 3 hours learning the ObjC stuff and then be back on your way programming-- and actually get more productive than if you have a Perl Aqua UI to work with because it would be slower to specify that Aqua UI in Perl using the custom API (than using Interface Builder.)

      So please, mod this parent up-- essentially the "bridge" is already there, its just "unconventional". Not "offtopic".
      • Kick ass! I have a defender!

        Everything is proceeding as planned... mwah-ha-ha.
      • I'd definitely use Objective C over Java for Cocoa code--it meshes much better with the way Cocoa works, which isn't much of a surprise.

        Still, you can use the Interface Builder with CamelBones. It's possible to build a fully GUI based app entirely in perl.
    • Actually, for scripting, I think that AppleScript and AppleScript Studio are perfect for building quick GUI apps. In addition, the "do script" AppleScript command allows you to run any other arbitrary script file, including Perl.

      As you pointed out, Interface Builder is wonderful; use Perl through AppleScript Studio.

      Russell Ahrens
    • using Project Builder and Interface Builder, is, I dare say, easier than writing Perl scripts that call Cocoa functions would be.

      Yes indeed it is! That's why I included support for PB+IB in CamelBones from the start - because I hate writing GUI code.
  • Ask Pudge! (Score:5, Informative)

    by 2nd Post! ( 213333 ) <gundbear@pacbe l l .net> on Thursday June 06, 2002 @06:07PM (#3655598) Homepage
    Have you looked here [pudge.net]?

    Pudge has a site with lots of Mac+Perl info and projects, including a link to this [pudge.net], a tool to connect Perl to the Apple Event model.

    Of course this begs the question why you haven't already looked at AppleScript Studio and AppleScript, which allows you to script the OS and many of it's Apps?

    This snippet allows me to start my apps when I get into work:

    tell application "ICQ 3.0X"
    activate
    end tell
    tell application "AOL Instant Messenger (SM)"
    activate
    end tell
    tell application "Yahoo! Messenger"
    activate
    end tell
    tell application "Microsoft Outlook"
    activate
    end tell

    It's not particularly complex nor instructive, but AppleScript is full featured and extensive. I have a cronjob run an AppleScript in the mornings, where the AppleScript opens iTunes, opens a playlist, and then start playing, as my alarm clock!

    tell application "iTunes"
    play user playlist "Sweet-Sad"
    play
    end tell
    • Why not just select these items from System Preferences -> Login?

      They'll load up automatically when you log into your account.

      (Of course you can do a lot more with AppleScript, like the alarm clock idea)

  • From the preface to Building Cocoa Applications: A Step-by-Step Guide, [oreilly.com] (page xviii, after mentioning an upcoming book on Cocoa and Java):
    "(And for those interested in writing Perl applications for this new platform [OS X], watch for
    Programming Cocoa Applications with Perl, also coming soon from O'Reilly.)"
    Note: I don't see anything about this on O'Reilly's new and upcoming [oreilly.com] book list, so it's possibly quite a few months off.
  • jaguar (Score:4, Informative)

    by Anonymous Coward on Thursday June 06, 2002 @06:29PM (#3655785)
    I wouldn't put too much work into your own solutions...

    Perl-Objc bindings are included in jaguar.

    See: Library/Perl/darwin/PerlObjCBridge.pm
    • Re:jaguar (Score:2, Informative)

      by Elian ( 10270 )
      This doesn't work at all well. Tried it, no joy. The problem is that Cocoa only works with real, honest-to-goodness applications, and you have to load the frameworks in the right order.
    • Perl-Objc bindings are included in jaguar.

      Yes, but they only work well with Foundation classes, because they're implemented as a module that gets loaded into a traditional Perl script. AppKit depends pretty heavily on being surrounded by an application bundle, I'm afraid.

      CamelBones is implemented as a framework that gets linked into an application, and lets you build your GUI with Interface Builder. On the other paw, it can't be loaded into a standalone script as a module; like AppKit, it requires an application bundle.

      The two products are addressing different problems, really; which one will be more useful to you depends on what you want to accomplish.
  • F-Script (Score:1, Informative)

    by tarzan353 ( 246515 )
    Another great way to interact with Cocoa apps is F-Script [fscript.org] and F-Script Anywhere [sabi.net].

    I know it's not exactly what the asker was looking for, but AS and Perl have already been discussed in detail. F-Script offers a different type of scriptability.
  • by Splork ( 13498 ) on Thursday June 06, 2002 @07:26PM (#3656184) Homepage
    python apparently has excellent macos X gui support. (i don't pay the apple tax myself so i can't judge first hand). on top of that you should be able to use anything with Qt or Gtk bindings using X on the mac (python and perl both have good bindings there).

    [and before any perl weenies mod this down because i said to use a different language: grow up!]
    • python apparently has excellent macos X gui support.

      I haven't actually *created* anything using PyObjC, but I did learn quite a bit about the inner workings of the Objective-C runtime by studying the code. I'd go so far as to say that I couldn't have written CamelBones without first studying the PyObjC bridge - there's some stuff in there that I still haven't seen documented anywhere. So, as far as my own limited exposure to it goes, I'd say that yes, Python's support for Cocoa is very good.

      I agree with the other part of your post, too - the more options that OS X programmers have, the better. Language bigots need to grow up.
  • need a lot more work before prime-time. This is nothing to do with OS X per se, and not all that much to do with Perl - it's the bindings between the two that need work. I've spent some time trying to track down the status of all of the various ways to do Graphics (GUI and just plain old drawing) in Perl under OS X, and none of them are ready for prime time. (My Mac.com homepage has details I won't go into here - http://homepage.mac.com/bortels if you want to get into sad detail.

    Having said that, if you're *very* familiar with Cocoa already, and are looking more towards GUI and not so much towards video-games, Camelbones is the leading suspect right now. I personally found it confusing, and you need to do development in the Apple Project Builder for the most part, but it has one key thing going for it - it works, and there's sample source.

    (I'm personally on the video-game quest - I want to be able to say "use GLUT", and go nuts, without an IDE getting in the way. But I digress...)

    The Sourceforge page for Camelbones is here: http://sourceforge.net/projects/camelbones/

    A homepage discussing Camelbones (but seemingly not up-to-date - it talks about 0.1, but 0.2 is available) is here: http://camelbones.sourceforge.net/

    -- Tom Bortels
  • More Resources (Score:5, Informative)

    by pudge ( 3605 ) <slashdotNO@SPAMpudge.net> on Thursday June 06, 2002 @10:03PM (#3657188) Homepage Journal
    I meant to respond earlier, but didn't get the chance. There are several ways to go about this. One is to the oft-mentioned CamelBones, which is in initial stages, but is a great start for Cocoa bindings. For Carbon, there is a vaporware project I've played with, a SWIG-based glue for Perl, Python, Tcl, Ruby, and maybe more, and more details of it will be forthcoming when it's ready.

    Right now there is also the Carbon-based MacOSX::File [cpan.org], which offers much of the same functionality as the Mac::Files module included in MacPerl, and there is OSXMacPerl [uec.ac.jp], a basic clone of the MacPerl module (DoAppleScript and more are provided).

    And some day I would like to port the Mac:: modules to Carbon, if I get the tuits.
  • Apple has ported TCL/TK to Aqua natively (ie: no X11 needed), it's somewhere on their Apple Developer site. Sorry, I can't dig for a link right now, I'm about to head out.
  • Perl and AppleScript can both call each other, so you can wire up an interface in AppleScript Studio and call 'do shellscript "script.pl"' do the get Perl bits running. It's an easy approach, and I know a lot of folks who are doing this with minimal pain. AppleScript has access to the authentication model so you can even run stuff as root with a system dialog handling the authentication.

    If you need to call AppleScript stuff from a Perl script you can use the various AppleScript bindings mentioned by others, or just do a system("echo 'tell app to do thing' | osascript"); which will run applescript commands, if a little indirectly. I have done this for things like cleanly quitting GUI apps, and it works great. Of course TMTOWTDI, so you could also open a pipe to osascript and dump in AppleScript commands, which might work nicely in some cases.
  • I have an application written in Perl/Tk, and would love to be able to port it to OS X without either A) rewriting in ObjectiveC, or B) requiring an X server on the client machines.
  • Though it's not done yet. (I'm writing it as I type this :) Additionally, if you're interested, I'll be giving a half-day tutorial on this at O'Reilly's OS X conference at the end of September/beginning of October. As time permits there should be a few articles about it on oreillynet.com, too.

The biggest difference between time and space is that you can't reuse time. -- Merrick Furst

Working...