how to get default mail client version on mac os x?

一个人想着一个人 提交于 2019-12-12 02:53:59

问题


I am new here. I have searched about default mail client information on mac os x. I found some help here How do I get the default mail client using applescript? But i did not got all the information i wanted.I got default mail client name but could not got its version that i see in "About Mail" section of Mail.app(when launched).


回答1:


LaunchServices is the OS X API that contains info about the user's preferred applications.

The LSGetApplicationForURL() function will return the data you seek. Here's a short example of its use:

#include <CoreFoundation/CoreFoundation.h>
#include <ApplicationServices/ApplicationServices.h>

int main(int argc, char *argv[])
{
  CFURLRef mailURL = CFURLCreateWithString(kCFAllocatorDefault, CFSTR("mailto://"), NULL);
  CFURLRef mailAppURL = NULL;
  OSStatus ret = 0;
  if((ret = LSGetApplicationForURL(mailURL, kLSRolesAll, NULL, &mailAppURL)) == 0)
  {
    CFStringRef path = CFURLCopyFileSystemPath(mailAppURL, kCFURLPOSIXPathStyle);
    CFShow(path);

    CFRelease(path);
    CFRelease(mailAppURL);
  }
  else
  {
    fprintf(stderr, "LaunchServices error %d\n", ret);
  }

  CFRelease(mailURL);
  return ret;
}

On my system, that prints /Applications/Mail.app. If you want more info about the returned item, you can use the LSCopyItemInfoForURL() function on mailAppURL.



来源:https://stackoverflow.com/questions/15401334/how-to-get-default-mail-client-version-on-mac-os-x

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!