Apple Script: Attach folder actions on startup?

Discussion in 'Mac Programming' started by robx2, Aug 5, 2008.

  1. robx2 macrumors member

    Joined:
    May 27, 2005
    #1
    I've got a simple folder action set up with Automator that moves .mov files from a network drive to a folder on a local drive that Sorenson Squeeze uses as a watch folder to compress to flv.

    The problem is that the local machine periodically gets shut down or restarted and the folder actions are no longer associated with the network folders.

    is there a way to automatically attach a folder action at startup? I know I can't mount the volume at start up, but not sure how to precede beyond that. Or is there another workaround I can use to keep the folder actions associated with the network folder?
     
  2. tedsmith3rd macrumors member

    Joined:
    Aug 30, 2006
    Location:
    US
    #2
    System Events has a folder actions suite that I think can do what you want. In case you're not familiar with Script Editor's library:
    1. Open Script Editor
    2. Select "Library" from the "Window" menu
    3. Double Click "System Events" in the Library window
    4. Scroll down to "Folder Actions Suite" in the "System Events.sdef" window
    If you need help getting it put together post back. I'm not much of a folder actions user.
     
  3. HiRez macrumors 603

    HiRez

    Joined:
    Jan 6, 2004
    Location:
    Western US
    #3
    Just be aware that I've found folder actions to be extremely flakey in Leopard, so much so that I've pretty much stopped using them altogether until they fix them. Note, however, that I have not tried using them since about 10.5.2 or so, so maybe they're better now (but I doubt it because some of the bugs are longstanding and predate Leopard). Problems include folder actions not working on more than one folder at a time, folder actions disabling themselves globally on restarts, folder actions enabled but not triggering, and still the inability of folder actions to wait until files are copied before starting (there's a workaround but it's tedious and error-prone).

    Folder actions: great idea, poor execution.
     
  4. numero macrumors regular

    Joined:
    Jul 23, 2002
    Location:
    OR
    #4
    I concur with HiRez. I am fighting a folder action right now that doesn't seem to be firing. I'm thinking of just changing it over to a cron job. Not as sexy, but it gets the job done.
     
  5. freiheit macrumors 6502a

    Joined:
    Jul 20, 2004
    Location:
    California
    #5
    I third the sentiment

    I second... no, third, the sentiment. I've not used Folder Actions before (been running OSX since Panther) and now that I found a use for them it isn't working well. Mine will work once but then seems to automatically disable itself (Leopard 10.5.4 on an Intel Mac Pro). Doesn't even require a restart, it just seems to happen after one execution or after some period of time elapses. It's very frustrating since I know the script is working and just can't get it to trigger 90% of the time.

    Any other ideas on how to have a script continually monitor a folder, without hogging a lot of system resources, would be appreciated. I'm new to AppleScript but have passable Perl, PHP and shell script knowledge.
     
  6. tedsmith3rd macrumors member

    Joined:
    Aug 30, 2006
    Location:
    US
    #6
    You could try Launch Services, the underlying system that drives folder actions. Write Perl or PHP script, make it executable, then have launch services run it when a folder changes. Lingon is an excellent free front end to the launch services interface. And using it directly has less overhead than using folder actions, so it MIGHT be more reliable. Again, I don't use folder actions so I don't know for sure.
     
  7. HiRez macrumors 603

    HiRez

    Joined:
    Jan 6, 2004
    Location:
    Western US
    #7
    I looked into this a while ago and the problem I ran into is that while there is a LaunchServices callback you can set to trigger a script when something in the filesystem changes, it doesn't send the folder the change even occurred in (or any other info) as an argument when it calls your script. Which is just a terrible design oversight because you can't tell from the script what actually changed, which makes it kind of useless.
     
  8. tedsmith3rd macrumors member

    Joined:
    Aug 30, 2006
    Location:
    US
    #8
    Yeah, that seems like an annoying limitation. But if you're only monitoring one path then you can either hard-code it into your program or pass the path as an argument to your program from your launchd plist.
     
  9. freiheit macrumors 6502a

    Joined:
    Jul 20, 2004
    Location:
    California
    #9
    Thanks for the suggestions

    Thanks for the suggestions. I'll look into that.
     
  10. krimb1 macrumors newbie

    Joined:
    Aug 22, 2006
    #10
    Still a problem

    Just wanted to chime in and say I'm running into the exact same roadblocks as freiheit on a MacBook Pro running 10.5.4. Leopard's done a lot of changes with security and administrator privileges; do you think it might have anything to do with that?
     

Share This Page