I use the following code to try to create a new mail account on Ventura.
tell application "Mail"
set AccountName to "online@mail.net"
set newacct to make new pop account with properties {name:AccountName, user name:AccountName, server name:"pop3.mailhosted.net"}
tell newacct
set password to "myPassword"
set full name to AccountName
set email addresses to {AccountName}
set port to 995
set uses ssl to true
end tell
-- no account is created
set smtpservername to "smtp.mailhosted.net"
set smtpusername to AccountName
set addsmtp to make new smtp server with properties {server name:smtpservername}
tell addsmtp
set authentication to "password"
set password to "myPassword"
set uses ssl to true
set port to 465
set user name to AccountName
end tell
-- no smtp server is created
set newsmtpserver to smtp server (smtpservername) -- & ":" & smtpusername) – last part uncomented gives an compiler error
set smtp server of newacct to smtp server newsmtpserver
-- noting added as smtp server to the new account
end tell
(Backtick tags for posting AppleScript code on MacScripter added by NG. See the Markdown Reference here.)
If I do it manually it works fine but not in code, what do I wrong? What code part is wrong? Has this to do with some security settings, or…? Being busy for the whole day till bed time, I can’t figure it out. Any suggestions or solutions?
The result of the script is really weird. Trying with a minimal script:
tell application "Mail"
set AccountName to "online@mail.net"
set newacct to make new pop account with properties {name:AccountName, user name:AccountName, server name:"pop3.mailhosted.net"}
end tell
The result was " accountid “0683AEBF-4367-44F1-B957-5ABCDB560BB9” ofapplication “Mail”". So the script DID create an account.
When I ask for a list of accounts:
tell application "Mail"
get name of accounts
end tell
Your right, it makes one like a ghost account but never get into the accounts list; even after the ‘newAcct’ is created ( for so far ), you can’t get any info or data from it. Also when called multiply times you get multiply ghost accounts; but they are disappeared when restart Mail.
Really weird.
This issue is happening at least from Catalina → Ventura ( Sonoma not tested )
tell application "System Settings"
reveal pane id "com.apple.Internet-Accounts-Settings.extension"
end tell
tell application "System Events" to tell application process "System Settings"
set frontmost to true
tell scroll area 1 of group 1 of group 2 of splitter group 1 of group 1 of window 1
click (every button whose description is "button")
end tell
end tell
Thank you for your idea. I did look into this, but notice two things.
User languages depended; How do I know the German or Dutch name of the button.
I did remember I could get info about a screen when I hoover over the elements ( System 7-9? ). Or was there a tool for that?
Is there a way to do that under MacOS?
I did use
get every UI element
--click (every button whose description is "Cancel") -- to close the current window but doesn't work
--tell window 2 or what shouls I use to get a window/sheet handle
(*
get every button
get properties of every button
get every UI element of every button
get every static text
get properties of every static text
get every UI element of every static text
get every scroll bar
get properties of every scroll bar
get every UI element of every scroll bar
*)
Any way how do I get all of the items following after opening a window?
Is there a way to travers and save all the UI-Items to a file.txt?
The properties of UI element have property description with value “button” the other button has description with value “Help”. If you ask for properties of buttons [s] meaning it will give the properties of all buttons.
To know what kind of class you have inside tell block you use
class of UI elements
When you know the class you could ask for properties
If the return from class of UI elements is {button, button} it means inside this tell block there is 2 UI elements with the class of button 1 and button 2.
When you ask for class of UI elements you will not get the index number.
To know if its button 1 or button 2 we could ask for properties.
tell application "System Settings"
reveal pane id "com.apple.Internet-Accounts-Settings.extension"
end tell
tell application "System Events" to tell application process "System Settings"
set frontmost to true
tell scroll area 1 of group 1 of group 2 of splitter group 1 of group 1 of window 1
-- To get the class of UI elements you do
set classOfUIelements to class of UI elements
-- To get properties of UI elements class you do
set propertiesOfButtons to properties of buttons
-- click (every button whose description is "button")
end tell
end tell
return {uielements:classOfUIelements, buttons:propertiesOfButtons}
There are ways to do it… I belive localized string from scripting additions is used.
If you search for user Yvan_Koenig you could find info how to use it.
No matter what kind of language a user are used you could use button 1. In other words the index will not be different if the users are using the same version of app and maybe also OS. The reason is the developer of some app or Apple could do something that change an working script to something that do not work anymore. The structor of the UI elements could be different.
Thank you
With your script I see nothing about the group or the sheet.
BTW, how do I get the sheet?
I can open the sheet now, but its not by travers or following the path.
tell application "System Settings"
reveal pane id "com.apple.Internet-Accounts-Settings.extension"
end tell
tell application "System Events" to tell application process "System Settings"
repeat until window 1 exists
delay 0.1
end repeat
set frontmost to true
tell scroll area 1 of group 1 of group 2 of splitter group 1 of group 1 of window 1
set classOfUIelements to get class of UI elements
set propertiesOfButtons to properties of buttons
click (every button whose description is "button")
repeat until sheet 1 of sheet 1 of window "Internet Accounts" exists
delay 0.1
end repeat -- runs forever
--set frontmost to true
-- works
-- click button 1 of group 2 of scroll area 1 of group 1 of sheet 1 of window "Internet Accounts" of application process "System Settings" of application "System Events"
click last button of group 2 of scroll area 1 of group 1 of sheet 1 of window "Internet Accounts" of application process "System Settings" of application "System Events"
end tell
end tell
Why does the wait for sheet is running forever?
How can I actually get a handle on the sheet?
Is there no ‘Last’ button in group 2; using a fixed number to get the add account button is dangerous because there can be coming more or less buttons?
Also often times the System Settings window gets gray and the opened dialog disappears and I have to kill the System Settings App.
Is this anything like what you’re trying to achieve?
tell application "System Settings"
activate
reveal pane id "com.apple.Internet-Accounts-Settings.extension"
repeat until (current pane is pane id "com.apple.Internet-Accounts-Settings.extension")
delay 0.1
end repeat
end tell
tell application "System Events"
tell application process "System Settings"
tell window 1
tell scroll area 1 of group 1 of group 2 of splitter group 1 of group 1
click (first button whose description is "button")
end tell
tell sheet 1
repeat until (it exists)
delay 0.1
end repeat
click last button of group 1 of scroll area 1 of group 1
end tell
end tell
end tell
end tell
You have to open the sheet before you could do GUI Scripting.
In other words we use click of some UI elements. When the sheet is front most view
its possible to do GUI Scripting.
the only thing I can can do is guessing whats on there; I do not get any UI Element.
Like I did guess this line
"click last button of group 2 of scroll area 1 of group 1 of sheet 1 of window “Internet Accounts” of application process “System Settings” of application “System Events”
"
why can’t I get a list of items from the sheet 1?
Also when I do a click, the clicked button changes to some extra menu elements, how can I know that?
You have to understand that some UI elements is not visible before you click UI element.
Lets say you have inside tell block UI element {button}
This button send action to the view to open UI element sheet.
When the UI element sheet is visible you could access it with GUI Scripting.
ex.
tell application "System Events" to tell application process "Script Editor"
tell menu bar item "File" of menu bar 1
click (menu items of menu 1 whose name begins with "Save")
end tell
return class of UI elements of window 1
end tell
(**
* The last item from the return is UI element sheet
* It means its ONLY visible when user reveal it. In this case the UI element menu item "Save..." of menu 1
* inside the tell block of UI element menu bar item "File" of UI element menu bar 1 is UI element sheet.
*)