Hi All,
I’m having a bit of an issue with launchd that’s watching a folder for a new file. My launchd is told to run a script whenever a file is added to a specific folder. This part is working perfectly, my script runs, moves the file to another directory and then deletes any hidden files that may have been created in the watched folder. The trouble is 10 seconds later the script runs again. The only reason I can think that it’s running again is because the original file was moved from the watched folder. In documentation I’ve read it says that you must ensure that the folder is empty so moving the file is a necessity but it doesn’t say that moving the file will cause the launchd to run again.
Here’s my launchd:
<?xml version="1.0" encoding="UTF-8"?> Label com.evanesco.watcher ProgramArguments open /Library/Scripts/Evanesco_Control.app QueueDirectories /Users/nikj/DSLRRemoteProHere’s the applescript:
set jpgFolder to (path to home folder as string) & "DSLRRemotePro"
set EvanescoFolder to (path to home folder as string) & "Evanesco_Processing"
set contentsList to every paragraph of (do shell script "ls -1 " & quoted form of POSIX path of jpgFolder)
display dialog "Running" giving up after 3
if (count of items of contentsList) > 0 then
try
do shell script "mv " & quoted form of POSIX path of jpgFolder & "/*" & space & quoted form of POSIX path of EvanescoFolder
end try
try
do shell script "rm -rf " & quoted form of POSIX path of jpgFolder & "/* " & quoted form of POSIX path of jpgFolder & "/.*"
end try
end if
Any help/thoughts gratefully appreciated,
Nik