AppleScript eMail

[eMail]新規メールを作成する(送信先 BCC指定)


【スクリプトエディタで開く】|

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.6"
use framework "Foundation"
use framework "AppKit"
use scripting additions

property refMe : a reference to current application


###本文
set strBody to "美しい日本語"
###件名
set strSubject to "【機器情報】機器情報を送ります" as text
##送信先は自分自身
set strMailAdd to doGetMyEmailAdd() as text
###BCCで相手のアドレス
set strBCCAdd to "foo@hoge.com" as text


###本文をNSString'sに
set ocidBody to refMe's NSString's stringWithString:(strBody)
###CC必要な場合
set strCCAdd to "" as text
###スキーム
set strScheme to "mailto" as text
###URL初期化
set ocidEmailURL to refMe's NSURL's alloc()'s init()
###コンポーネント初期化
set ocidEmailComponents to refMe's NSURLComponents's alloc()'s init()
###スキーム mailtoを追加
ocidEmailComponents's setScheme:(strScheme)
###パスを追加(setHostじゃないよ)
ocidEmailComponents's setPath:(strMailAdd)
###クエリー追加
set ocidQueryItemArray to refMe's NSMutableArray's alloc()'s initWithCapacity:0
set ocidQueryItem to refMe's NSURLQueryItem's alloc()'s initWithName:("subject") value:(strSubject)
ocidQueryItemArray's addObject:ocidQueryItem
set ocidQueryItem to refMe's NSURLQueryItem's alloc()'s initWithName:("body") value:(ocidBody)
ocidQueryItemArray's addObject:ocidQueryItem
set ocidQueryItem to refMe's NSURLQueryItem's alloc()'s initWithName:("cc") value:(strCCAdd)
ocidQueryItemArray's addObject:ocidQueryItem
set ocidQueryItem to refMe's NSURLQueryItem's alloc()'s initWithName:("bcc") value:(strBCCAdd)
ocidQueryItemArray's addObject:ocidQueryItem
ocidEmailComponents's setQueryItems:(ocidQueryItemArray)
###URLに
set ocidEmailURL to ocidEmailComponents's |URL|
log ocidEmailURL's absoluteString() as text

###デフォルトのeMailクライアント
set strUTI to "com.apple.mail.email" as text
set ocidUTType to refMe's UTType's typeWithIdentifier:(strUTI)
set appShardWorkspace to refMe's NSWorkspace's sharedWorkspace()
set ocidAppPathURL to appShardWorkspace's URLForApplicationToOpenContentType:(ocidUTType)
###URLをeMailクライアントで開く
set ocidConfig to refMe's NSWorkspaceOpenConfiguration's configuration
ocidConfig's setActivates:(true as boolean)
ocidConfig's setHides:(false as boolean)
appShardWorkspace's openURLs:({ocidEmailURL}) withApplicationAtURL:(ocidAppPathURL) configuration:(ocidConfig) completionHandler:(missing value)


###自分のメールアドレスの取得
to doGetMyEmailAdd()
  tell application id "com.apple.AddressBook"
    ###自分のカード
    tell my card
      set strVcardText to vcard as text
    end tell
  end tell
  ####Vcardの内容をリスト化(改行がWINDOWS)
  set AppleScript's text item delimiters to "\r\n"
  set listVcardText to every text item of strVcardText
  set AppleScript's text item delimiters to ""
  ###EMAIL取得用
  set listEmailAdd to {} as list
  set strHomeEmail to "" as text
  set strWORKEmail to "" as text
  ####Vcardの数だけ繰り返し
  repeat with itemVcardText in listVcardText
    ##テキストで確定させて
    set strItemVcardText to itemVcardText as text
    ##telから始まる場合
    if strItemVcardText starts with "EMAIL" then
      ###カンマで区切って
      set AppleScript's text item delimiters to ":"
      set listItemVcardText to every text item of strItemVcardText
      set AppleScript's text item delimiters to ""
      set strType to (item 1 of listItemVcardText) as text
      if strType contains "HOME" then
set strHomeEmail to (item 2 of listItemVcardText) as text
      else if strType contains "WORK" then
set strWORKEmail to (item 2 of listItemVcardText) as text
      else
###後半部分が電番
set strEmail to (item 2 of listItemVcardText) as text
####リストに格納して
copy strEmail to end of listEmailAdd
      end if
    end if
  end repeat
  ###一つに絞る場合
  if strWORKEmail is not "" then
    set strSendAdd to strWORKEmail
  else if strHomeEmail is not "" then
    set strSendAdd to strHomeEmail
  else
    set strSendAdd to (item 1 of listEmailAdd)
  end if
return strSendAdd
  
end doGetMyEmailAdd

|

その他のカテゴリー

Acrobat Acrobat Annotation Acrobat Dialog Acrobat Form Acrobat JS Acrobat Open Acrobat Plugin Acrobat python Acrobat Reader Acrobat Sequ Acrobat Stamps Admin Admin Account Admin Apachectl Admin configCode Admin Device Management Admin LaunchServices Admin Locationd Admin loginitem Admin Maintenance Admin Permission Admin Pkg Admin Power Management Admin Printer Admin SetUp Admin SMB Admin System Information Admin Tools Admin Users Admin Volumes Adobe Apple AppleScript AppleScript Guide AppleScript Accessibility AppleScript AppKit AppleScript Applications AppleScript AppStore AppleScript Archive AppleScript Attributes AppleScript Automator AppleScript AVAsset AppleScript AVconvert AppleScript AVFoundation AppleScript AVURLAsset AppleScript BackUp AppleScript Barcode AppleScript Bash AppleScript Basic AppleScript Basic Path AppleScript Bluetooth AppleScript BOX AppleScript Browser AppleScript Calendar AppleScript CD/DVD AppleScript Choose AppleScript Chrome AppleScript CIImage AppleScript CloudStorage AppleScript Color AppleScript com.apple.LaunchServices.OpenWith AppleScript Console AppleScript Contacts AppleScript CotEditor AppleScript CURL AppleScript current application AppleScript Date&Time AppleScript delimiters AppleScript Desktop AppleScript Device AppleScript Disk AppleScript do shell script AppleScript Dock AppleScript DropBox AppleScript eMail AppleScript Encode Decode AppleScript Error AppleScript EXIFData AppleScript ffmpeg AppleScript File AppleScript Finder AppleScript Firefox AppleScript Folder AppleScript Fonts AppleScript GIF AppleScript HTML AppleScript Icon AppleScript Illustrator AppleScript Image Events AppleScript Image2PDF AppleScript ImageOptim Applescript iWork AppleScript Javascript AppleScript Jedit AppleScript Json AppleScript Label AppleScript List AppleScript locationd AppleScript LRC AppleScript LSSharedFileList AppleScript m3u8 AppleScript MakePDF AppleScript Map AppleScript Math AppleScript Microsoft AppleScript Microsoft Edge AppleScript Microsoft Excel AppleScript Mobileconfig AppleScript Mouse AppleScript Movie AppleScript Music AppleScript NetWork AppleScript Notes AppleScript NSArray AppleScript NSBitmapImageRep AppleScript NSBundle AppleScript NSCFBoolean AppleScript NSCharacterSet AppleScript NSColor AppleScript NSColorList AppleScript NSData AppleScript NSDictionary AppleScript NSError AppleScript NSEvent AppleScript NSFileAttributes AppleScript NSFileManager AppleScript NSFont AppleScript NSFontManager AppleScript NSImage AppleScript NSIndex AppleScript NSKeyedArchiver AppleScript NSKeyedUnarchiver AppleScript NSLocale AppleScript NSMutableArray AppleScript NSMutableDictionary AppleScript NSMutableString AppleScript NSNotFound AppleScript NSNumber AppleScript NSOpenPanel AppleScript NSPasteboard AppleScript NSPDFImageRep AppleScript NSpoint AppleScript NSPredicate AppleScript NSRange AppleScript NSRegularExpression AppleScript NSRunningApplication AppleScript NSScreen AppleScript NSSize AppleScript NSString AppleScript NSStringCompareOptions AppleScript NSTask AppleScript NSTimeZone AppleScript NSURL AppleScript NSURL File AppleScript NSURLBookmark AppleScript NSURLComponents AppleScript NSURLResourceKey AppleScript NSUserDefaults AppleScript NSUUID AppleScript NSView AppleScript NSWorkspace AppleScript Numbers AppleScript OAuth AppleScript ObjC AppleScript OneDrive AppleScript Osax AppleScript PDF AppleScript PDFAnnotationWidget AppleScript PDFContext AppleScript PDFDisplayBox AppleScript PDFDocumentPermissions AppleScript PDFKit AppleScript PDFnUP AppleScript PDFOutline AppleScript Photos AppleScript Photoshop AppleScript Plist System Events AppleScript PostScript AppleScript prefPane AppleScript Preview AppleScript Python AppleScript QR AppleScript QR Decode AppleScript QuickLook AppleScript QuickTime AppleScript record AppleScript Regular Expression AppleScript Reminders AppleScript ReName AppleScript Repeat AppleScript RTF AppleScript Safari AppleScript SaveFile AppleScript ScreenCapture AppleScript ScreenSaver AppleScript Script Editor AppleScript Script Menu AppleScript Shortcuts AppleScript Shortcuts Events AppleScript Sort AppleScript Sound AppleScript Spotlight AppleScript SRT AppleScript StandardAdditions AppleScript stringByApplyingTransform AppleScript System Events AppleScript System Settings AppleScript TemporaryItems AppleScript Terminal AppleScript Text AppleScript Text CSV AppleScript Text TSV AppleScript TextEdit AppleScript Translate AppleScript Trash AppleScript Twitter AppleScript UI AppleScript Unit Conversion AppleScript UTType AppleScript valueForKeyPath AppleScript Video AppleScript VisionKit AppleScript Visual Studio Code AppleScript webarchive AppleScript webp AppleScript Wifi AppleScript XML AppleScript XML EPUB AppleScript XML OPML AppleScript XML Plist AppleScript XML RSS AppleScript XML SVG AppleScript XML TTML AppleScript XML webloc AppleScript YouTube AppleScript Zero Suppress Applications Barcode OnLine Tools CityCode Design iPhone List Logs lsappinfo Memo Music perl PlistBuddy pluginkit postalcode ReadMe SF Symbols character id SF Symbols Entity sips Skype Slack sqlite TCC Tools Typography Video Wacom zoom