1. Welcome to the new MacRumors forums. See our announcement and read our FAQ

Applescript folder actions, dropbox, and sleep

Discussion in 'Mac Programming' started by VideoBeagle, Jun 6, 2012.

  1. macrumors 6502a

    I have an applescript folder action that triggers when a text file is put in a folder in Dropbox. (activates a program, processes the text)

    When I do extensive testing at home using the folder locally, accessing it from other computers on my home network, using the dropbox website, using an ipad app, and even having friends elsewhere who are shared to the folder use it, it works as it's supposed to.

    But I'm getting less than positive results when I put files in it when I use the drop box website or ipad app from work during the day. Either it doesn't work like it's supposed to, missing steps in the script, or it doesn't work at all.

    As I know the code of the script works, the problem has to be something else.
    From a chat server I stay connected to, I know it's not a network interruption (and that would delay execution thru dropbox, not break it).

    The only real difference I can think of is that as I'm not using the computer, it's in sleep mode, or at least spun down... (I'm not sure what my power settings are at the moment). Could that be causing issues with the "folder action" part of the script?

    After the script starts going, it activates a program, then has a delay of .5 seconds, and then issues a Cmd N"
    tell window 1
    					delay 0.5
    					keystroke "n" using command down
    Might the problem be that the computer is asleep, it wakes when the dropbox file is created, but while it's waking (it's a g5 with leopard, so not super quick) it's missing commands? (does that even make sense?) and maybe addding a longer delay at the very start might solve it?

    (*The script is discussed in another thread...I wanted to make this thread to focus on the folder action triggering problem)
  2. macrumors 6502a

    I'm currently trying the script with a delay 30 after the trigger and added delays between the key commands hoping that gives the computer enough time to get roaring.

    on adding folder items to this_folder after receiving these_items
    	delay 30
    	repeat with i from 1 to number of items in these_items
    	                          tell window 1
    						delay 5
    						keystroke "n" using command down
    						--delay 3
    						keystroke "v" using command down
    						set position to {xx, yy}
    Given the lack of response of similar issues from others, though, I'm assuming the problem lies with my specific G5/Leopard OS rather than this being a common issue.
  3. macrumors 6502a

    Hmm.. It's still very inconsistent on triggering. Do other folks using dropbox and folder actions have 0 issues?
  4. kryten2, Jun 12, 2012
    Last edited: Jun 12, 2012

    macrumors 6502a

    Instead of a folder action you can also try launchd and a property list file with the WatchPaths key. Property lists are Apple's standard configuration file format. Please note. Property list files are expected to have their name end in ".plist". I put mine in /Users/yourusername/Library/LaunchAgents. Type man launchd.plist in Terminal for more info about the format and keys of the plist file. There's an app called Lingon that does all the work for you or you can create them manually like I do. To load your plist do launchctl load Library/LaunchAgents/name.of.your.plist in Terminal. I think Lingon also does this but It's been a while since I've used it. An example of a plist and I'll attach the script that goes with it.

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" \
    <plist version="1.0">
    		<string>/Users/test/Library/Scripts/Move downloaded files to subfolder launchd script.scpt</string>
    This key looks promising :

    StartInterval <integer>
    This optional key causes the job to be started every N seconds. If the
    system is asleep, the job will be started the next time the computer
    wakes up. If multiple intervals transpire before the computer is woken,
    those events will be coalesced into one event upon wake from sleep.

    It would be best if you left the watched folder empty after processing the files. Just like you would with a folder action. To quote the Applescript Language Guide :


    Attached Files:

  5. macrumors 6502a

    Thanks! I'll look into this!
    (Obviously this is for the stickies script you've been invaluable in helping me with in the other thread:p )

Share This Page