Folder Actions on Mac OSX Leopard?

S

squishywaffle

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
 
D

Diez B. Roggisch

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/document...ogGuide/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
 
S

Sean DiZazzo

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
 
H

has

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,817
Latest member
DicWeils

Latest Threads

Top