collecting threads from a message

Hi List

In another list I did try to get some answers but unfortunate no reply. Because I am at the end of my knowledge and trials I will place my request here.

It goes about the following:
Lets say, I did do a search in mail and got a nice list of messages.
I see an item that I would like to investigate, but there is only one or two messages from the whole conversation (responses cq threads) in this search result list. But of course I would like to see the whole thread. I do run my script and there I got a new window with my threads only.

I am working in Leopard.

Yesterday I did have some time to put my readings into practice.

I came up with the following.



on run {input, parameters}
	tell application "Mail"
		activate
		set msg to item 1 of (selection as list)
		set msgAccount to name of account of mailbox of msg --<-- (4th error)
		set msgMailboxname to name of mailbox of msg
		
		set viewer to make new message viewer
		--delay 1
		tell application "System Events" to tell application process "Mail"
			keystroke "m" using {command down, shift down}
		end tell
		activate

		-- test point
	-->	return selection & {msg} & {msgAccount} & {msgMailboxname} --> in cases 1-3 they are correct here

		set selected mailboxes of viewer to {mailbox msgMailboxname of account msgAccount}
		delay 0.2
		set selected messages of viewer to {msg}
		delay 0.3
		tell application "System Events" to tell application process "Mail"
			keystroke "k" using {command down, shift down}
		end tell
		
		set visible messages of viewer to selected messages of viewer --<-- (3th error)
		return selection & {msg} & {msgAccount} & {msgMailboxname}
	end tell
end run


This does what I want, but eh BUT;

The following problems are arising here,

1). if I choose a smart folder ( with a selection as of today ), select a message, do my thing ( running the script ), it works.

2). if I choose an account in my inbox folder, select a message, do my thing ( running the script ), it works.

3). if I choose the inbox ( top inbox folder), select a message, do my thing ( running the script ), it fails with the following error;
Mail got an error: Can’t set selected messages of message viewer id 256924272 to selected messages of message viewer id 256924272. (6495536)

4). if I choose a mailbox folder , select a message, do my thing ( running the script ), it fails also with the error;
Mail got an error: Can’t get account of mailbox of message id 446115 of mailbox “Development/Apple/Apple Lists - Applescript Users”. (372668800)

the difference between the two of them is that in the inbox case, the error pops up at the line :" set visible messages of viewer to selected messages of viewer". With the mailbox folder right from the start at set msgAccount to name of account of mailbox of msg.

How is this possible, in the first three trials because the selected message is the same.
The return value reads ( also at the test point in code in all the cases),
{message id 446613 of mailbox “INBOX” of account “rvamerongen” of application “Mail”, “rvamerongen”, “INBOX”}

Please, can anyone help me out with this?

BTW, How can I change the title of a newly created message viewer window?

Rene van Amerongen

Hi,
Try this:

on run {input, parameters}
tell application "Mail"
	activate
	set msg to item 1 of (selection as list)
	try -- to set message account
		set msgAccount to name of account of mailbox of msg --<-- (4th error)
	on error -- it is a local folder
		set msgAccount to "local"
	end try
	
	set msgMailboxname to name of mailbox of msg
	
	set viewer to make new message viewer
	--delay 1
	tell application "System Events" to tell application process "Mail"
		keystroke "m" using {command down, shift down}
	end tell
	
	set selected mailboxes of viewer to {mailbox of msg} --<<-- changed here
	--delay 0.2
	set selected messages of viewer to {msg}
	--delay 0.3
	tell application "System Events" to tell application process "Mail"
		keystroke "k" using {command down, shift down}
	end tell
	
	set visible messages of viewer to selected messages of viewer --<-- (3th error)

	set (name of window of viewer) to (subject of msg) -- set the window title
	set sort column of viewer to date sent column -- order by date
	set sorted ascending of viewer to false -- descending dates

	return selection & {msg} & {msgAccount} & {msgMailboxname}
end tell
end run

Your first issue is because you are trying to use the mailbox name in a hierarchical system when it needs a reference to the mailbox. Referencing the mailbox directly instead of by name, using ‘mailbox of msg’ instead of ‘mailbox msgMailboxname of account msgAccount’, fixes this problem for me.

Your second error is due to the fact that local mailboxes do not have an account. To catch this I have set the request for the mailbox name in a try block.

I have set the window title to the subject of the message and re-ordered to date order (which makes sense to me). This may not be what you want.

Best wishes

John Maisey
www.nhoj.co.uk

Hi John,

Thank you very much. The window name I did figure out, but the local mailbox is tricky stuff.
I did use the try part, but couldn’t let it pass when it was not a inbox box.

Does someone have a good reading about this on the web.
Because I have still the problem when I have a message selected from inside a “On My Mac” (local ) mailbox, and the run the script.
Does this has to do with the name of the maibox? I got the impression that it is a hierarchy problem, f.e the mailbox could be inside another mailbox.

It does not pass the set visible messages of viewer to selected messages of viewer --<-- (3th error) line.
the error
The action “Run AppleScript” encountered an error.
Check the actionʼs properties and try running the workflow again.

btw I see the following things occuring
sometimes the viewer has a value like 8.0175704E+8
sometimes the menu item View>select>All Messages in this thread is greyed out even in the previous run it was enabled

This is the event log



tell application "Mail"
	activate
	get selection
		{message id 445907 of mailbox "Development/Apple/Apple Lists - Applescript Users"}
	get name of account of mailbox of message id 445907 of mailbox "Development/Apple/Apple Lists - Applescript Users"
	get name of mailbox of message id 445907 of mailbox "Development/Apple/Apple Lists - Applescript Users"
		"Apple Lists - Applescript Users"
	make new message viewer
		message viewer id 8.0175704E+8 <<< there is a visible new viewer
end tell
tell application "System Events"
	keystroke "m" using {command down, shift down}
end tell
tell application "Mail"
	get name of mailbox of message id 445907 of mailbox "Development/Apple/Apple Lists - Applescript Users"
		"Apple Lists - Applescript Users"
	display dialog "OK0Apple Lists - Applescript Users"
		{button returned:"OK"}
	set selected mailboxes of message viewer id 8.0175704E+8 to {mailbox of message id 445907 of mailbox "Development/Apple/Apple Lists - Applescript Users"}
	set selected messages of message viewer id 8.0175704E+8 to {message id 445907 of mailbox "Development/Apple/Apple Lists - Applescript Users"}
end tell
tell application "System Events"
	keystroke "k" using {command down, shift down}
end tell
tell application "Mail"
	display dialog "OK1"
		{button returned:"OK"}
	set visible messages of message viewer id 8.0175704E+8 to selected messages of message viewer id 8.0175704E+8
		"Mail got an error: Can't set selected messages of message viewer id 8.0175704E+8 to selected messages of message viewer id 8.0175704E+8."


If I ask later with set viewer2 to front message viewer the id of the front viewer I get is a good value. When I restart Applescript scripter then it works ok again, for some time.

is there a tool that can really step through the code? And debug? If I choose Applescript debugger inside Applescript scripter I get a debugger not installed error “AppleScript debugging failed because Script Debugger is not available on this Macintosh”. Huh Macintosh??

Thanks again

Rene v Amerongen

Hello list

To come back on this and because I have still have the problem when I have a message selected from inside a “On My Mac” (local ) mailbox, and the run the script.
I still have the following questions.

Does this has to do with the name of the maibox? I got the impression that it is a hierarchy problem, f.e the mailbox could be inside another mailbox.

It does not pass the set visible messages of viewer to selected messages of viewer --<-- (3th error) line.
the error
The action “Run AppleScript” encountered an error.
Check the actionʼs properties and try running the workflow again.

Does someone knows a solution for this?

Thank you