Basic Mail Script question

Hello everyone,

I just started on Applescript this week, so I am still learning the ropes.

I am trying create a mail and do some basic operations on them without having the windows poping up.
I have tried and I am at a loss to explain what is happenning.

Any help welcomed!!!

Example 1:



tell application "Mail"
	set myMsg to make new outgoing message with properties {subject:"subject"}
	display dialog myMsg's visible as text
	
	#Why is this windows visible? the library entry says that the default for this property is false
	
end tell


Example 2:



tell application "Mail"
	set myMsg to make new outgoing message with properties {subject:"subject", visible:false}
	display dialog myMsg's visible as text
	# In this second example, the window flickers. It appears than disappears.
	# how can we make it be really completely invisible?
end tell


give this a go DroneScripter

tell application “Mail”
set myMsg to make new outgoing message at end of outgoing messages with properties {subject:“DroneScripter”, visible:false}
end tell

Budgie

Budgie,

Thank you for the quick reply!

Now, I do not if I am doing something wrong but I tried you script and I am getting the same behavior.

Here is what I did.

a) I opened the script editor.
b) I pasted your code
c) I copiled the code
d) I ran the code

results:

  1. Mail opens. I see the main window.
  2. then I see a new message window opening and then disappearing quickly.

This is the behavior (#2) I am trying to avoid. Am I doing something wrong?

not sure what’s going on , works ok here, try the below DroneScripter.

sorry sent the wrong code oops

tell application “System Events” to tell process “Mail”
keystroke “n” using command down
set TheName to “DroneScripter”
set TheAddress to “DroneScripter@test.co.00”
set theSubject to "TEST MAIL: "
tell application “Mail”
activate
set newMessage to make new outgoing message with properties {subject:theSubject}
tell newMessage
make new to recipient at end of to recipients with properties {name:TheName, address:TheAddress}
make new to recipient at end of to recipients with properties {name:TheName, address:TheAddress}
set visible to false --so you cant edit the message
–set visible to true --so you cant edit the message
–send newMessage – un edit so the email will send it’s self without user interaction
end tell
end tell
end tell

Budgie,

The new message window is visible for a fraction of a second before closing again.
I must be cursed…;-(((