Problem moving from multiple folders & email script

Hi, being relatively new to this scripting malarky, I imagine I’m making some noob error :rolleyes:. However, my searches thus far have not led me to any obvous conclusion. Thus here is my issue in the hope someone can point me in the right direction.

I’m attempting to setup a script (or multiple scripts) to attach files from several folders (Folder A, FolberB, etc) as soon as they hit the fodler and email them off via Mail. I had previously achieved this using the following:


on adding folder items to thefolder after receiving theAddedItems
    repeat with eachitem in theAddedItems
        
        set theSender to "me@mac.com"
        set recipCommon to "me"
        set recipAddress to "me@mac.com"
        set msgText to "My Files"
        
        tell application "Mail"
            set newmessage to make new outgoing message with properties {subject:"My Files", content:msgText & return & return}
            
            tell newmessage
                set visible to true
                set sender to theSender
                make new to recipient with properties {name:recipCommon, address:recipAddress}
                make new attachment with properties {file name:eachitem} at after the last paragraph
            end tell
            
            send newmessage
        end tell
        
        tell application "Finder"
            move eachitem to "Macintosh HD:Users:admin:documents:myfiles:sent"
        end tell
        
    end repeat
end adding folder items to

The problem with this is that when applied to multiple fodlers, Mail doesn’t seem to be able to handle files arriving concurrently in the folders and only processes the FolderA script.

So given my current knowledge (or lack thereof), I thought it’d be easiest to have ascript move files from each folder into a “Processing” folder and have the Mail script above run from there. Here’s the move script:


on adding folder items to thefolder after receiving theAddedItems
    repeat with eachitem in theAddedItems
        
        tell application "Finder"
            move eachitem to "Macintosh HD:Users:admin:documents:myfiles:processing"
        end tell
        
    end repeat
end adding folder items to

Great in theory. However, when files arrive in the “Processing” fodler, the script fails to recognise the file arrival and doesn’t trigger. It works fine when I drag files into the “Processing” folder myself - it just doesn’t work when a script moves it there.

So, I’ll keep working away at this but if anyone can help, that’d be greatly appreciated :slight_smile:

Ok, so moving on slightly, it appears that I was mistaken and in fact the second script does indeed pick up on the file arriving. However, it doesn’t process properly in that once it creates a new message, it stops just before entering the Recipient. Strangely, again on a manual move to the “processing” folder, the message works fine :confused:

Ok, I’m beginning to think there is some sort of bug here - a 10.5 thing maybe?. Even on dragging files to the folder, only a maximum of 7 are being emailed off. The 8th simply stops just before inputting the recipient.

Frustrating :mad:

Ok, quite possibly, Mail.app is just a little flaky when it comes to handling scripts. I’ve re-adjusted my script for use with Entourage and I’m getting better results albeit still not 100% successful.


on adding folder items to themailfolder after receiving theAddedItems
    repeat with eachitem in theAddedItems
        
        tell application "Microsoft Entourage"
            activate
            set newmessage to make new draft window with properties {to recipients:"me@mac.com", subject:"My Files", attachment:{file:eachitem}}
            send newmessage
            
            tell application "Finder"
                move eachitem to "Macintosh HD:Users:admin:documents:myfiles:sent"
            end tell
        end tell
        
    end repeat
end adding folder items to

A bit more about what I’m trying to achieve:

I have a dictaphone that stores recordings in 5 folders. When I connect the dictaphone, it downloads all recordings to respective Folders A through to E. I need the script/s to check each folder for files and automatically email them off then move them to a sent folder. Each folder can contain one or more recordings.

What I find with my new revised script above when I apply it to each fodler - is that one of two things will happen. Either all the files from one folder will get sent and moved or the first file from each folder gets sent and moved. Everything else stays where it is.

I’m beginning to think the trigger “on adding folder items” might not be the best way to achieve this. Perhaps I should link it to checking for the dictaphone being plugged in then scan all subfolders for files.

Any input gratefully welcome!