Getting started with OS X Leopard

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mark Carter

    Getting started with OS X Leopard

    One thing I really liked about Ubuntu was that Nautilus allowed you to
    add scripts to a directory which could be accessed via the RMB. It was a
    very simple thing to do.

    I've recently switched to Leopard, and I'm trying to do the same thing.
    I'm fairly experienced with Python, but new to OS X. I have installed
    FinderPop, which lets me add scripts and make them accessible via
    Contextual Menus, but it is not as easy as the Nautilus way.

    The sorts of things I want to do are:
    * copy the directory of Finder to the clipboard
    * add a new file to Finder's directory.
    * find out the size of a directory
    * open a file with Aquamacs, regardless of file type,

    My head's swimming, though. Anyone got any really good pointers and
    sample scripts that will help me work out how to achieve the sorts of
    things I'm trying to do?
  • has

    #2
    Re: Getting started with OS X Leopard

    On 15 Mar, 18:05, Mark Carter <m...@privacy.n etwrote:
    The sorts of things I want to do are:
    * copy the directory of Finder to the clipboard
    * add a new file to Finder's directory.
    * find out the size of a directory
    * open a file with Aquamacs, regardless of file type,
    If you want to control desktop applications directly, that generally
    means using Apple event IPC. The most popular language for application
    scripting is traditionally AppleScript, but Apple event bridges exist
    for other languages as well. The best of these is appscript; see my
    sig for links. Some Finder scripting examples:


    #!/usr/bin/python

    from appscript import *
    from osax import *

    finder = app('Finder')
    standardadditio ns = ScriptingAdditi on()

    folderref = finder.Finder_w indows[1].target

    # set clipboard to path to front window's folder
    path = folderref.get(r esulttype=k.ali as).path
    standardadditio ns.set_the_clip board_to(path)

    # make new empty file in front window's folder
    finder.make(new =k.file, at=folderref.ge t())

    # get size of front window's folder
    # (note: this may return k.missing_value when first run
    # as Finder is sluggish at calculating folder sizes)
    print folderref.size. get()

    # open selected items in TextEdit
    selecteditems = finder.selectio n.get()
    finder.open(sel ecteditems,
    using=app.appli cation_files.ID ('com.apple.tex tedit'))



    HTH

    has
    --
    Control AppleScriptable applications from Python, Ruby and ObjC:



    Comment

    • Mark Carter

      #3
      Re: Getting started with OS X Leopard

      has wrote:
      On 15 Mar, 18:05, Mark Carter <m...@privacy.n etwrote:
      >The sorts of things I want to do are:
      >* copy the directory of Finder to the clipboard
      >* add a new file to Finder's directory.
      >* find out the size of a directory
      >* open a file with Aquamacs, regardless of file type,
      >
      If you want to control desktop applications directly, that generally
      means using Apple event IPC. The most popular language for application
      scripting is traditionally AppleScript, but Apple event bridges exist
      for other languages as well. The best of these is appscript; see my
      sig for links. Some Finder scripting examples:
      >
      >
      #!/usr/bin/python
      >
      ....
      Control AppleScriptable applications from Python, Ruby and ObjC:
      http://appscript.sourceforge.net

      Aah! Many thanks. I see that I had to do
      easy_install appscript
      and ensure I use /usr/bin/python
      I'm off to play with it now. Exciting stuff.

      I installed the Python from MacPorts. That's not quite what I wanted,
      because they only have a version for Python 2.4. *Sigh*. MacPorts seems
      to be getting new ports all the time. The problem is, there also seems
      to be an aweful lot of ports gathering bitrot.

      Am I the only one to form the opinion that OS X can sometimes appear to
      be a bit of a mish-mash?

      I tried XCode the other day. Seemed a bit complicated, if you ask me.
      I've tried to like Lisp, too. In the end, Python just rocks. I started
      out with Glade a short while ago, and I'm impressed how relatively easy
      it is to create GUIs and add handlers in Python.


      Comment

      • Arnaud Delobelle

        #4
        Re: Getting started with OS X Leopard

        On Mar 15, 7:31 pm, Mark Carter <m...@privacy.n etwrote:
        has wrote:
        On 15 Mar, 18:05, Mark Carter <m...@privacy.n etwrote:
        The sorts of things I want to do are:
        * copy the directory of Finder to the clipboard
        * add a new file to Finder's directory.
        * find out the size of a directory
        * open a file with Aquamacs, regardless of file type,
        >
        If you want to control desktop applications directly, that generally
        means using Apple event IPC. The most popular language for application
        scripting is traditionally AppleScript, but Apple event bridges exist
        for other languages as well. The best of these is appscript; see my
        sig for links. Some Finder scripting examples:
        >
        #!/usr/bin/python
        >
        ...
        Control AppleScriptable applications from Python, Ruby and ObjC:
        http://appscript.sourceforge.net
        >
        Aah! Many thanks. I see that I had to do
        easy_install appscript
        and ensure I use /usr/bin/python
        I'm off to play with it now. Exciting stuff.
        >
        I installed the Python from MacPorts. That's not quite what I wanted,
        because they only have a version for Python 2.4. *Sigh*. MacPorts seems
        to be getting new ports all the time. The problem is, there also seems
        to be an aweful lot of ports gathering bitrot.
        Is there a particular reason you want python from MacPorts? OSX
        Leopard comes with python 2.5, that's what I use on my mac.

        --
        Arnaud

        Comment

        • Mark Carter

          #5
          Re: Getting started with OS X Leopard

          Arnaud Delobelle wrote:
          Is there a particular reason you want python from MacPorts? OSX
          Leopard comes with python 2.5, that's what I use on my mac.
          I heard from somewhere that Apple's version was a bit wonky, and that I
          would be better off with a "proper" build.

          Comment

          • Kevin Walzer

            #6
            Re: Getting started with OS X Leopard

            Mark Carter wrote:
            Arnaud Delobelle wrote:
            >
            >Is there a particular reason you want python from MacPorts? OSX
            >Leopard comes with python 2.5, that's what I use on my mac.
            >
            I heard from somewhere that Apple's version was a bit wonky, and that I
            would be better off with a "proper" build.
            Not sure where you heard that. Apple's Python is built according to Mac
            guidelines (as a "framework" ), but it works the same as on other platforms.

            --
            Kevin Walzer
            Code by Kevin

            Comment

            • martin.laloux@gmail.com

              #7
              Re: Getting started with OS X Leopard


              if you are not satisfied with the native version, why not install the
              official version directly from python site
              http://www.python.org/download/ (macpython) instead of using that of
              macports. It moreover is provided with many utilities

              There is a macpython list that you can consult at

              Comment

              • Mark Carter

                #8
                Re: Getting started with OS X Leopard

                martin.laloux@g mail.com wrote:
                if you are not satisfied with the native version, why not install the
                official version directly from python site
                http://www.python.org/download/ (macpython) instead of using that of
                macports. It moreover is provided with many utilities
                >
                There is a macpython list that you can consult at
                http://www.nabble.com/Python---pythonmac-sig-f2970.html
                Thanks.

                Actually, I created my first python appscript (well, "stole" it from a
                previous poster is more like it) - and it's pretty cool when I combine
                it with FinderPop.

                Comment

                Working...