PDA

View Full Version : Mail Applescript error




moose151
Oct 23, 2009, 07:03 PM
:confused:
This is my first attempt at Applescript. I 'm try to write a script to move messages that are older than 30 days from one mailbox to another. Here is my script:

tell application "Mail"
activate
set lwdgInbox to mailbox "INBOX" in account "LWDG - Jules"
set archiveBox to mailbox "Archive"

--set numMsg to count of messages in archiveBox
--display dialog numMsg

set dateLimit to 24 * 3600 * 30 -- 30 days
repeat with msg in messages in lwdgInbox
set dateRcvd to date received in msg
if ((current date) - dateRcvd) > dateLimit then
display dialog date string of dateRcvd
move the msg to archiveBox
end if
end repeat
end tell

When I run it I get "Mail got an error: NSInternalScriptError" in the evnt log. is there anyone wh would knw why this is?



chown33
Oct 23, 2009, 07:17 PM
Unpost. Where's the "unpost" button?

mysterytramp
Oct 23, 2009, 09:00 PM
"NSInternalScriptError" essentially means, I think, that Mail got the "move" message but it has no idea what to do with it. "Move" is part of the standard dictionary; every scriptable app should have it, but it's irrelevant to lots of apps. Although you want to "move" a message from one mailbox to another, Mail doesn't understand what the script is saying.

A message's "mailbox" is actually a property you can set:

set mailbox of message x to mailbox "Where I Want It"

Also, if you run this under Snow Leopard, your event list should also have reported -10004 errors every time you called "current date." Basically that is, I think, using a command inside a tell block that doesn't belong. "current date" is a function that you'd be better off calling once. I re-jiggered your code so you eliminate one calculation inside the repeat loop.

set compareToThisDate to (the current date) - (24 * 3600 * 90) -- 90 days

tell application "Mail"
activate

--set numMsg to count of messages in archiveBox
--display dialog numMsg

repeat with msg in messages in inbox
set dateRcvd to date received in msg
if compareToThisDate > dateRcvd then
display dialog date string of dateRcvd
set mailbox of msg to mailbox "Archive"
end if
end repeat

end tell

mt

moose151
Oct 24, 2009, 11:28 AM
"NSInternalScriptError" essentially means, I think, that Mail got the "move" message but it has no idea what to do with it. "Move" is part of the standard dictionary; every scriptable app should have it, but it's irrelevant to lots of apps. Although you want to "move" a message from one mailbox to another, Mail doesn't understand what the script is saying.

A message's "mailbox" is actually a property you can set:

set mailbox of message x to mailbox "Where I Want It"

Also, if you run this under Snow Leopard, your event list should also have reported -10004 errors every time you called "current date." Basically that is, I think, using a command inside a tell block that doesn't belong. "current date" is a function that you'd be better off calling once. I re-jiggered your code so you eliminate one calculation inside the repeat loop.

set compareToThisDate to (the current date) - (24 * 3600 * 90) -- 90 days

tell application "Mail"
activate

--set numMsg to count of messages in archiveBox
--display dialog numMsg

repeat with msg in messages in inbox
set dateRcvd to date received in msg
if compareToThisDate > dateRcvd then
display dialog date string of dateRcvd
set mailbox of msg to mailbox "Archive"
end if
end repeat

end tell

mt

Awesome, this works. Thanks a lot!:)