Search code examples
macosemailapplescriptosx-yosemite

How do I make this AppleScript Folder Watch ignore hidden items?


I have pretty much spent my entire Sunday trying to find an answer to this and I am now admitting defeat and asking for your help. I've read several examples on here and some other AppleScript sites but non of them seem to work when applied to this script. I do however put this down to me.

I'm trying to use the script below to watch a folder then send me an email when a new item has been added and it works just fine. The trouble I am having is getting it to ignore system [or hidden] folders.

I have removed my efforts to do this as they all kept breaking the whole thing, so the version below works but currently it will include hidden items.

property theName : "Name"
property theAddress : "[email protected]"


on adding folder items to this_folder after receiving added_items
    set added_Items_List to {}
    repeat with oneItem in added_items
        set end of added_Items_List to name of (info for oneItem)
    end repeat
    set {TID, text item delimiters} to {text item delimiters, ", "}
    set added_Items_List to added_Items_List as text
    set text item delimiters to TID
    set dateString to (current date) as string
    set theBody to "There are new files in the FTP folder " & name of (info for this_folder) & ":" & return & return & added_Items_List
    tell application "Mail"
        set newMessage to make new outgoing message with properties {visible:true, subject:"New submissions on FTP: " & dateString, content:theBody}
        tell newMessage
            make new to recipient at end of to recipients with properties {name:theName, address:theAddress}
        end tell
        activate
        send newMessage
    end tell
end adding folder items to

Any help or direction would be much appreciated and hopefully others will benefit from a working solution.

For anyone who come across this post with a similar issue, you may find the answer to your problem on one of these posts.


Solution

  • Hidden files start with a dot, just filter those items

    on adding folder items to this_folder after receiving added_items
    set added_Items_List to {}
    repeat with oneItem in added_items
        set fileName to name of (info for oneItem)
        if fileName does not start with "." then
             set end of added_Items_List to fileName
        end if
    end repeat
    if (count added_Items_List) = 0 then return
    ....
    

    But if the Finder on your machine does not show the hidden files by default you don't need the additional lines.