getting the account type from mail

Hi all,

I’m struggling while getting the account type from a mail account in an ASOC app.

The following code returns the correct info in vanilla AppleScript, where in ASOC it doesn’t:

tell application "Mail"
return account type of account "My mail account"
end tell

In vanilla AppleScript this returns: POP or IMAP
In ASOC I get:
<NSAppleEventDescriptor: ‘etpo’> for a POP account and
<NSAppleEventDescriptor: ‘etim’> for a IMAP account

Is there a way to coerce this to the actual string values as vanilla AppleScript does?


're getting the same result – it’s just that the console shows AS classes as NSAppleEventDescriptors, which is what they become when they get passed to Cocoa.

If you ask ASOC to cource the result as a string:

tell application "Mail"
   return (account type of account "My mail account") as text
end tell

The result is
¹¹constant ****etimºº → for a IMAP account
¹¹constant ****etpoºº → for a IMAP account

The funny thing is, if you set «constant ****etim» as the value of a AS variable, as in:

set x to «constant ****etim»

The value is replaced by “imap” upon compilation, which remains a constant for which I don’t have a clue how to cource it to a string value.


And you get something similar for AppleScript if you run it outside a script editor. When you do it in a script editor, the editor loads the app’s dictionary and translates between terminology and underlying codes – outside a script editor, that doesn’t happen. (Yes, Xcode is a script editor of sorts, but the console is not a script log.)

Thanks Shane, you pushed me in the right direction.

Running it as an AppleScript app indeed results in the same constant value’s as the ASOC project.

A search on the list pointed me to the run script statement:

set thisAcc to "My mail account"
set accType to run script "tell application \"Mail\" to return (account type of account \"" & thisAcc & "\") as text"

Returns “imap” or “pop” as a string, great!


Using a run statement involves a lot of overhead. Better to do something like this:

set accType to account type of account “My mail account”
if accType = IMAP account then
set accType to “IMAP account”
else if…

Hi Shane,

That’s actually what I was using as a workaround before.

I figured it was a better approach to coerce the actual data returned from instead of relaying on my own interpretation of it in an if statement. If something changes in’s code in the future, the coercing is more likely going to stand, while my own interpretation of the returned data is probably going to fail without an update of my app.

Anyway, I’m going to look into it. Thanks for the valuable info and insights!


Actually, it’s likely to be exactly the other way around. The most common changes are terminology, so relying on attempts to coerce are doomed to failure.