Is it just me or is applescript a little buggered on Leopard? I’ve got 10.5.4 and trying to run up some simple scripts. However I’ve run into problems including:
the DELAY command stops the script altogether.
scripts to send off MAIL stops after sending the seventh mail.
Is anyone else experiencing this sort of problem? :mad:
on adding folder items to thefolder after receiving 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 {visible:true, subject:"My Files", content:msgText & return & return}
tell newmessage
set sender to theSender
make new to recipient with properties {name:recipCommon, address:recipAddress}
repeat with eachitem in theAddedItems
tell content to make new attachment with properties {file name:eachitem} at after the last paragraph
end repeat
end tell
send newmessage
end tell
tell application "Finder"
move theAddedItems to folder ((path to documents folder as text) & "myfiles:sent:")
end tell
end adding folder items to
Hi StefanK, thanks for the suggestion. Unfortunately not. Each file needs to be attached to a single email. I posted the problem on another forum and someone pointed out that 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
Let me explain 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.
In this case it would be easier to check whether the dictaphone is connected and
scan the folders. Launchd is a good way to do this.
Sending multiple mails in Mail.app works quite reliably if
there is a delay of some seconds between creating the outgoing mails
Yea, I’ve actually opted for an even simpler approach than even that now - just periodically check the folders. However, I can’t get the damn thing to pickup “entire contents”. I keep getting an Applescript erro saying it “Can’t get the contents…”. Am I missing somehting here
property idletimeout : 60
on MoveFiles()
tell application "Finder"
set NewFiles to every file of entire contents of "Macintosh HD:Users:admin:documents:myfiles:message"
repeat with eachfile in NewFiles
tell application "Microsoft Entourage"
activate
set newmessage to make new draft window with properties {to recipients:"me@mac.com", subject:"MY Files", attachment:{file:eachfile}}
send newmessage
end tell
tell application "Finder"
move eachfile to "Macintosh HD:Users:admin:documents:myfiles:sent"
end tell
end repeat
end tell
end MoveFiles
on run
MoveFiles()
end run
on idle
MoveFiles()
return idletimeout
end idle
Hey StefanK, I’m tantalisingly close to making this work. Thought you might be able to help with one last bit as I got this IDLE handler from an earlier post of yours (I am saving as STAY OPEN). I can’t seem to get this script to run every 10 seconds though. Runs fine when executed manually though
property idletimeout : 10
on MoveFiles()
tell application "Finder"
set filecount to (count of files in entire contents of folder "Macintosh HD:Users:admin:documents:myfiles:message")
if filecount = 0 then
return idletimeout
else
try
set NewFiles to every file of entire contents of folder "Macintosh HD:Users:admin:documents:myfiles:message" as alias list
on error
set NewFiles to every file of entire contents of folder "Macintosh HD:Users:admin:documents:myfiles:message" as alias as list
end try
end if
end tell
repeat with eachfile in NewFiles
tell application "Microsoft Entourage"
activate
set newmessage to make new draft window with properties {to recipients:"me@mac.com", subject:"My Files", attachment:{file:eachfile}}
send newmessage
end tell
tell application "Finder"
move eachfile to "Macintosh HD:Users:admin:documents:myfiles:sent"
end tell
end repeat
end MoveFiles
on run
MoveFiles()
end run
on idle
MoveFiles()
return idletimeout
end idle
Well… solved. Had to save it as an “Application Bundle” for some reason but that got it working. Here’s my complete script for prosperity
property idletimeout : 60
on MoveFiles()
tell application "Finder"
set filecount to (count of files in entire contents of folder "Macintosh HD:Users:admin:documents:myfiles:message")
if filecount = 0 then
return idletimeout
else
try
set NewFiles to every file of entire contents of folder "Macintosh HD:Users:admin:documents:myfiles:message" as alias list
on error
set NewFiles to every file of entire contents of folder "Macintosh HD:Users:admin:documents:myfiles:message" as alias as list
end try
end if
end tell
repeat with eachfile in NewFiles
tell application "Microsoft Entourage"
activate
set newmessage to make new draft window with properties {to recipients:"me@mac.com", subject:"My Files", attachment:{file:eachfile}}
send newmessage
end tell
tell application "Finder"
move eachfile to "Macintosh HD:Users:admin:documents:myfiles:sent"
end tell
end repeat
end MoveFiles
on run
MoveFiles()
end run
on idle
MoveFiles()
return idletimeout
end idle