Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

VideoBeagle

macrumors 6502a
Original poster
Aug 17, 2010
822
18
App Q&A testing by request.
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"
Code:
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)
 

VideoBeagle

macrumors 6502a
Original poster
Aug 17, 2010
822
18
App Q&A testing by request.
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.

Code:
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

Code:
	                          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.
 

kryten2

macrumors 65816
Mar 17, 2012
1,114
99
Belgium
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.

Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" \
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
        <key>Label</key>
        <string>com.test.downloadsmove</string>
        <key>Program</key>
        <string>/usr/bin/osascript</string>
	<key>ProgramArguments</key>
	<array>
		<string>osascript</string>
		<string>/Users/test/Library/Scripts/Move downloaded files to subfolder launchd script.scpt</string>
	</array>
        <key>WatchPaths</key>
        <array>
        <string>/Users/test/Downloads</string>
        </array>
</dict>
</plist>

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 :

A well written Folder Action script leaves the hot folder empty. This avoids repeated application of the action to the same files, and allows Folder Actions to perform more efficiently.
 

Attachments

  • Move downloaded files to subfolder launchd script.zip
    13 KB · Views: 140
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.