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

|

その他のカテゴリー

Accessibility Acrobat Acrobat 2020 Acrobat 2024 Acrobat AddOn Acrobat Annotation Acrobat AppleScript Acrobat ARMDC Acrobat AV2 Acrobat BookMark Acrobat Classic Acrobat DC Acrobat Dialog Acrobat Distiller Acrobat Form Acrobat GentechAI Acrobat JS Acrobat JS Word Search Acrobat Maintenance Acrobat Manifest Acrobat Menu Acrobat Merge Acrobat Open Acrobat PDFPage Acrobat Plugin Acrobat Preferences Acrobat Preflight Acrobat Print Acrobat Python Acrobat Reader Acrobat Reader Localized Acrobat Reference Acrobat Registered Products Acrobat SCA Acrobat SCA Updater Acrobat Sequ Acrobat Sign Acrobat Stamps Acrobat URL List Mac Acrobat URL List Windows Acrobat Watermark Acrobat Windows Acrobat Windows Reader Admin Admin Account Admin Apachectl Admin ConfigCode Admin configCode Admin Device Management Admin LaunchServices Admin Locationd Admin loginitem Admin Maintenance Admin Mobileconfig Admin NetWork Admin Permission Admin Pkg Admin Power Management Admin Printer Admin Printer Basic Admin Printer Custompapers Admin SetUp Admin SMB Admin softwareupdate Admin Support Admin System Information Admin TCC Admin Tools Admin Umask Admin Users Admin Volumes Admin XProtect Adobe Adobe AUSST Adobe Bridge Adobe Documents Adobe FDKO Adobe Fonts Adobe Reference Adobe RemoteUpdateManager Adobe Sap Code AppKit Apple AppleScript AppleScript Duplicate AppleScript entire contents AppleScript List AppleScript ObjC AppleScript Osax AppleScript PDF AppleScript Pictures AppleScript record AppleScript Video Applications AppStore Archive Archive Keka Attributes Automator BackUp Barcode Barcode Decode Barcode QR Bash Basic Basic Path Bluetooth BOX Browser Calendar CD/DVD Choose Chrome Chromedriver CIImage CityCode CloudStorage Color Color NSColor Color NSColorList com.apple.LaunchServices.OpenWith Console Contacts CotEditor CURL current application Date&Time delimiters Desktop Desktop Position Device Diff Disk do shell script Dock Dock Launchpad DropBox Droplet eMail Encode % Encode Decode Encode HTML Entity Encode UTF8 Error EXIFData exiftool ffmpeg File File Name Finder Finder Window Firefox Folder FolderAction Font List FontCollections Fonts Fonts Asset_Font Fonts ATS Fonts Emoji Fonts Maintenance Fonts Morisawa Fonts Python Fonts Variable Foxit GIF github Guide HTML Icon Icon Assets.car Illustrator Image Events ImageOptim Input Dictionary iPhone iWork Javascript Jedit Ω Json Label Language Link locationd lsappinfo m3u8 Mail Map Math Media Media AVAsset Media AVconvert Media AVFoundation Media AVURLAsset Media Movie Media Music Memo Messages Microsoft Microsoft Edge Microsoft Excel Microsoft Fonts Microsoft Office Microsoft Office Link Microsoft OneDrive Microsoft Teams Mouse Music Node Notes NSArray NSArray Sort NSAttributedString NSBezierPath NSBitmapImageRep NSBundle NSCFBoolean NSCharacterSet NSData NSDecimalNumber NSDictionary NSError NSEvent NSFileAttributes NSFileManager NSFileManager enumeratorAtURL NSFont NSFontManager NSGraphicsContext NSGraphicsContext Crop NSImage NSIndex NSKeyedArchiver NSKeyedUnarchiver NSLocale NSMetadataItem NSMutableArray NSMutableDictionary NSMutableString NSNotFound NSNumber NSOpenPanel NSPasteboard NSpoint NSPredicate NSRange NSRect NSRegularExpression NSRunningApplication NSScreen NSSet NSSize NSString NSString stringByApplyingTransform NSStringCompareOptions NSTask NSTimeZone NSUbiquitous NSURL NSURL File NSURLBookmark NSURLComponents NSURLResourceKey NSURLSession NSUserDefaults NSUUID NSView NSWorkspace Numbers OAuth PDF PDF Image2PDF PDF MakePDF PDF nUP PDF Pymupdf PDF Pypdf PDFContext PDFDisplayBox PDFImageRep PDFKit PDFKit Annotation PDFKit AnnotationWidget PDFKit DocumentPermissions PDFKit OCR PDFKit Outline PDFKit Start PDFPage PDFPage Rotation PDFView perl Photoshop PlistBuddy pluginkit plutil postalcode PostScript PowerShell prefPane Preview Python Python eyed3 Python pip QuickLook QuickTime ReadMe Regular Expression Reminders ReName Repeat RTF Safari SaveFile ScreenCapture ScreenSaver Script Editor Script Menu SF Symbols character id SF Symbols Entity Shortcuts Shortcuts Events sips Skype Slack Sound Spotlight sqlite StandardAdditions StationSearch Subtitles LRC Subtitles SRT Subtitles VTT Swift swiftDialog System Events System Settings TemporaryItems Terminal Text Text CSV Text MD Text TSV TextEdit Tools Translate Trash Twitter Typography UI Unit Conversion UTType valueForKeyPath Video VisionKit Visual Studio Code VMware Fusion Wacom Weather webarchive webp Wifi Windows XML XML EPUB XML HTML XML LSSharedFileList XML LSSharedFileList sfl2 XML LSSharedFileList sfl3 XML objectsForXQuery XML OPML XML Plist XML Plist System Events XML RSS XML savedSearch XML SVG XML TTML XML webloc XML xmllint XML XMP YouTube Zero Padding zoom