Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

moose151

macrumors newbie
Original poster
Oct 23, 2009
2
0
: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?
 

mysterytramp

macrumors 65816
Jul 17, 2008
1,334
4
Maryland
"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:

Code:
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.

Code:
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

macrumors newbie
Original poster
Oct 23, 2009
2
0
"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:

Code:
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.

Code:
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!:)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.