AppleScript: Watching a folder I need an AppleScript application on the desktop to watch a folder, also on the desktop, for files that have been moved to it.

So far, I have:

global folderSpool
tell application "Finder" to set folderSpool to folder "Spool" of desktop

on adding folder items to folderSpool after receiving the_files
    repeat with each_file in the_files
        set theDialogText to "File is: " &amp; (each_file) &amp; "."
        display dialog theDialogText
    end repeat
end adding folder items to


When I export the script as an application, I set it to: "Stay open after run handler." I then open the application and keep it running.

However, when I move files to the "Spool" folder, nothing happens.

I tried the on idle option, but it kept creating dialogue after dialogue, rather than doing so when files were moved to the folder.

Any ideas?
The command you're using, "on adding folder item", is specific to folder actions, so it won't work in a non-folder action script. I agree with the others that a folder action is the best way to handle it, but if you really want to do it without, you can create a stay open application that queries the contents of the folder and compares it to the last time it ran, and displays the different files. Change the runInterval property to run at your preferred frequency.

Note: For simplicity, I only wrote it to check for files added to the spool folder. You can tweak it to also check for removed files by duplicating the second section in the code below, and looping through spoolFiles and seeing if they are in currentFiles.

AppleScript Code, as a stay-open application, below:

property spoolFiles : {}
property currentFiles : {}
property runInterval : 5 -- interval is in seconds
global folderSpool

on idle
    tell application "Finder"
        set folderSpool to folder "Spool" of desktop
        if (count of spoolFiles) is 0 then set spoolFiles to name of every file of folderSpool
        set currentFiles to name of every file of folderSpool
    end tell

    set changedFiles to {}--Reverse and repeat this section to check for missing files
    repeat with i from 1 to count of currentFiles
        if currentFiles's item i is not in spoolFiles then
            set changedFiles's end to currentFiles's item i
        end if
    end repeat

    repeat with each_file in changedFiles
        set theDialogText to "File is: " &amp; (each_file) &amp; "."
        display dialog theDialogText
    end repeat
    set spoolFiles to currentFiles --important to update the spoolFiles so only new files will get displayed going forward.
    return runInterval
end idle