Want to export a local mailbox to a mbox file on my mac

Hi,
I am using the system events to click the Mailbox menu and then clicking on the export menu item.
Then the save file dialog appears. I don’t know how to refer to to the widgets in the system events, so I can set the path to where I want to save the file and then clicking the ‘Choose’ button.
How can I do this ?
Thanks,
Regards

In fact I can’t even select the menu item I want, because I have to do the selection like this :

	tell application "System Events" to tell process "Mail"
		set frontmost to true
		click menu item 18 of menu 5 of menu bar 1
	end tell

I dont know the structure of the widgets in the app

If you are talking about changing the target of an open/save dialogue, then you can always use the keyboard shortcut command-shift-G. You can use system events to drive this. Here is an example using TextEdit. I use the ‘name’ of each menu and item but you can also use the appropriate index.

tell application "TextEdit"
	activate
	tell application "System Events"
		tell application process "TextEdit"
			perform action "AXPress" of menu "File" of menu bar 1
			perform action "AXPress" of menu item "Open…" of menu 3 of menu bar 1
			
			delay 0.4
			key code 5 using {command down, shift down}
			
		end tell
	end tell
end tell

At this point, you can enter the appropriate target directory and select the desired item (using keystroke)

Then you can click whatever button, with something like this:

tell application "TextEdit"
	tell application "System Events"
		tell application process "TextEdit"
			
			set uiDialogue to window "Open" of application process "TextEdit" of application "System Events"
			UI elements of uiDialogue
			--> {button "Open" of window "Open" of application process "TextEdit" of application "System Events", button "Cancel" of window "Open" of application process "TextEdit" of application "System Events", button "Options" of window "Open" of application process "TextEdit" of application "System Events", group 1 of window "Open" of application process "TextEdit" of application "System Events"}	
			
			set b1 to button "Open" of uiDialogue
			perform action "AXPress" of b1
			
		end tell
	end tell
end tell

Thanks for the help. I will need to handle the save dialog later.
My current prblem is how to select a mailbox from the tree on the left side of Mail.app. I am currently iterating what I suppose is the tree, but don’t know how to select the node I want :

on exportmailbox(pathToFile)
	tell application "System Events" to tell process "Mail"
		set frontmost to true
		set listofwidgets to every row of outline of scroll area 1 of splitter group 1 of window 1
		log (count items of item 1 of listofwidgets)
		repeat with counter from 1 to count items of item 1 of listofwidgets
			click item counter of item 1 of listofwidgets
		end repeat
	end tell
end exportmailbox

Some things…

  1. Rather than use set frontmost…, I would just use a regular tell to Mail to activate. This should go just above the ‘tell system events’ line.

    tell application "Mail" to activate

  2. I would recommend creating this in regular code as opposed to a handler. You won’t get the same feedback. Once you figure it out, then you can implement it as a handler.

  3. You can specify a UI element that is above the desired target and then get the ui elements of it. Then root through the result and you may find the one that you’re after. The UI elements of uiDialogue line in my prior post does this (as it does in the bottom snippet as well).

  4. Alternatively, you can try using click to identify the widget in question. This snippet below will click at the screen at x=200, y=245 from the top, left corner.

tell application "System Events"
	click at {200, 245}
	--> text field 1 of group 1 of row 8 of outline 1 of scroll area 1 of splitter group 1 of group 1 of splitter group 1 of splitter group 1 of window "devJun — \"stackexchange css - #onetrust-consent-sdk\"" of application process "DEVONthink Pro" of application "System Events"
end tell

Given that the result is a text field —which may or may not be what you’re after— you can back up a level and then get the ui elements of that element, in this case the group 1 element.

tell application "System Events"
	UI elements of group 1 of row 8 of outline 1 of scroll area 1 of splitter group 1 of group 1 of splitter group 1 of splitter group 1 of window "devJun — \"stackexchange css - #onetrust-consent-sdk\"" of application process "DEVONthink Pro"	
	--> {UI element 1 of group 1 of row 8 of outline 1 of scroll area 1 of splitter group 1 of group 1 of splitter group 1 of splitter group 1 of window "devJun — \"stackexchange css - #onetrust-consent-sdk\"" of application process "DEVONthink Pro" of application "System Events", text field 1 of group 1 of row 8 of outline 1 of scroll area 1 of splitter group 1 of group 1 of splitter group 1 of splitter group 1 of window "devJun — \"stackexchange css - #onetrust-consent-sdk\"" of application process "DEVONthink Pro" of application "System Events"}
end tell