Run script every time there's a change in a folder?

Hi Everyone,
I'm sure running a command based on a change in a folder is a common question, but I can't seem to find it through my searching. I tried searching and looking through the manual but I'm probably just not clear on what to look up and would appreciate help or being pointed in the right direction.
I'm trying to have Hazel run an apple script every time there is any change in a folder (new file, file updated, etc..). The script then makes Devonthink reindex that folder. The apple script works on its own. I was able to get it to work within Devothink by making it an Automator workflow (for some reason pasting it as an embedded apple script resulted in errors). I should also mention that the folder has many subfolders.
In my attempts, I used the "any" of the following conditions are met option. With the following conditions:
sub-file/folder count - did change
size - did change
created - did change
Here's the Apple script incase anyone is interested
I'm sure running a command based on a change in a folder is a common question, but I can't seem to find it through my searching. I tried searching and looking through the manual but I'm probably just not clear on what to look up and would appreciate help or being pointed in the right direction.
I'm trying to have Hazel run an apple script every time there is any change in a folder (new file, file updated, etc..). The script then makes Devonthink reindex that folder. The apple script works on its own. I was able to get it to work within Devothink by making it an Automator workflow (for some reason pasting it as an embedded apple script resulted in errors). I should also mention that the folder has many subfolders.
In my attempts, I used the "any" of the following conditions are met option. With the following conditions:
sub-file/folder count - did change
size - did change
created - did change
Here's the Apple script incase anyone is interested
- Code: Select all
-- Update indexed items of all databases
-- Created by Christian Grunenberg on Tue Mar 25 2014.
-- Copyright (c) 2014. All rights reserved.
-- Set to true if indexed items are not only located at the root of the database
property pAllRecords : false
tell application id "DNtp"
try
set theDatabases to databases
show progress indicator "Updating Indexed Items" steps (count of theDatabases)
repeat with theDatabase in theDatabases
step progress indicator (name of theDatabase as string)
set theRecords to records of theDatabase -- Children of root
repeat with theRecord in theRecords
if pAllRecords or theRecord is indexed then
synchronize record theRecord -- Updates children of theRecord too
end if
end repeat
end repeat
hide progress indicator
on error error_message number error_number
hide progress indicator
if the error_number is not -128 then display alert "DEVONthink Pro" message error_message as warning
end try
end tell