FAQ
Greetings,

I've been trying to figure out if it's possible to attach a Python
script to an action via Mac OSX Leopard's File Actions system. I'm
wanting to call a Python script every time a file is added to the
monitored folder. Just adding a .py file doesn't seem to do anything
at all, and I can't find any log output anywhere to see what's going
on.

I'm more just looking to see if this is or is not possible. I'm not
interested in other solutions, as I already have them lined up in case
this is a no-go, but I'd really love to be able to do it this way if
anyone has any experience. Googling around revealed pretty much
nothing.

Any help is much appreciated,
Greg

Search Discussions

  • Diez B. Roggisch at Sep 24, 2008 at 10:58 pm

    squishywaffle at gmail.com schrieb:
    Greetings,

    I've been trying to figure out if it's possible to attach a Python
    script to an action via Mac OSX Leopard's File Actions system. I'm
    wanting to call a Python script every time a file is added to the
    monitored folder. Just adding a .py file doesn't seem to do anything
    at all, and I can't find any log output anywhere to see what's going
    on.

    I'm more just looking to see if this is or is not possible. I'm not
    interested in other solutions, as I already have them lined up in case
    this is a no-go, but I'd really love to be able to do it this way if
    anyone has any experience. Googling around revealed pretty much
    nothing.
    You mean this?

    http://developer.apple.com/documentation/Darwin/Conceptual/FSEvents_ProgGuide/Introduction/chapter_2_section_1.html

    *I* would use ctypes to access Carbon Core. But then that's just me -
    I'm sure you find a better way...

    Diez
  • Sean DiZazzo at Sep 24, 2008 at 11:30 pm

    On Sep 24, 12:31?pm, "squishywaf... at gmail.com" wrote:
    Greetings,

    I've been trying to figure out if it's possible to attach a Python
    script to an action via Mac OSX Leopard's File Actions system. I'm
    wanting to call a Python script every time a file is added to the
    monitored folder. Just adding a .py file doesn't seem to do anything
    at all, and I can't find any log output anywhere to see what's going
    on.

    I'm more just looking to see if this is or is not possible. I'm not
    interested in other solutions, as I already have them lined up in case
    this is a no-go, but I'd really love to be able to do it this way if
    anyone has any experience. Googling around revealed pretty much
    nothing.

    Any help is much appreciated,
    Greg
    I always wondered about Folder Actions... I just tested. You can
    have applescript call python scripts via `do shell script`. But it
    seemed a bit flakey.

    I would either go with applescript all the way, or look in to your
    other options.

    ~Sean
  • Has at Sep 25, 2008 at 11:39 am

    On 25 Sep, 00:30, Sean DiZazzo wrote:

    I always wondered about Folder Actions... ?I just tested. ?You can
    have applescript call python scripts via `do shell script`. ?But it
    seemed a bit flakey.
    Should work in theory. For which values of flakey? e.g. Is it a
    technical problem with Folder Actions, AppleScript, 'do shell script,
    and/or Python, or just your AppleScript code that needs some work
    (e.g. there are some common gotchas with using 'do shell script' that
    often trip up AppleScript newcomers).

    FWIW, I would second the suggestion to look into FSEvents as a
    possible alternative to Folder Actions. There's also kqueue which is
    lower level but may have/have had Python bindings already written for
    it.

    Alternatively, if the OP really wants to use FAs, there are a couple
    of other options for that:

    1. I've got a simple py2app-based application shell and an AppleScript
    that automatically forwards FA events to that application - just
    insert your Python code into the application shell and build it,
    attach the AppleScript to some folders, and you're good to go. Email
    me directly if you want a copy.

    2. If you're brave, you could try using the PyOSA component on the
    appscript website, which allows you to write OSA scripts in Python.
    FAs will work with any kind of OSA script (.scpt files), not just
    AppleScript ones. PyOSA is officially discontinued due to some
    intractable limitations in its/CPython's design (specifically the
    inability of an in-process Python interpreter to sandbox unrelated
    scripts so that they can't interfere with each others' modules, file
    handles, etc). However, it's reasonably functional and should be
    usable for FAs with a little care.


    HTH

    has
    --
    Control AppleScriptable applications from Python, Ruby and ObjC:
    http://appscript.sourceforge.net

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedSep 24, '08 at 7:31p
activeSep 25, '08 at 11:39a
posts4
users4
websitepython.org

People

Translate

site design / logo © 2022 Grokbase