書式つきテキスト(NSAttributedString)を作成し、その先頭にコンピュータアイコン画像を追加してダイアログ表示するAppleScriptです。
–> Download Script Archive with Libraries
AppleScript名:書式つきテキストを組み立てて、画像を追加 |
— Created 2017-09-25 by Takaaki Naganoya — Modified 2017-09-27 by Shane Stanley — Modified 2024-11-25 by Takaaki Naganoya — 2017-2024 Piyomaru Software use AppleScript use scripting additions use framework "Foundation" use framework "AppKit" use tv : script "tvLib" use hwName : script "hardwareNameLib" property NSFont : a reference to current application’s NSFont property NSColor : a reference to current application’s NSColor property NSString : a reference to current application’s NSString property NSImage : a reference to current application’s NSImage property NSTextAttachment : a reference to current application’s NSTextAttachment property NSAttributedString : a reference to current application’s NSAttributedString property NSMutableDictionary : a reference to current application’s NSMutableDictionary property NSFontAttributeName : a reference to current application’s NSFontAttributeName property NSKernAttributeName : a reference to current application’s NSKernAttributeName property NSImageNameComputer : a reference to current application’s NSImageNameComputer property NSMutableParagraphStyle : a reference to current application’s NSMutableParagraphStyle property NSLigatureAttributeName : a reference to current application’s NSLigatureAttributeName property NSMutableAttributedString : a reference to current application’s NSMutableAttributedString property NSUnderlineStyleAttributeName : a reference to current application’s NSUnderlineStyleAttributeName property NSParagraphStyleAttributeName : a reference to current application’s NSParagraphStyleAttributeName property NSForegroundColorAttributeName : a reference to current application’s NSForegroundColorAttributeName –Attributed Stringを作成 set aFontSize to 48 set aString to getSystemProfileInAGenre("SPHardwareDataType", "machine_name") of hwName set anAssrStr to makeRTFfromParameters(aString, "HelveticaNeue-Light", aFontSize, -2, (aFontSize * 1.5)) of me –添付画像を作成 set anAttach to NSTextAttachment’s alloc()’s init() set anImage to NSImage’s imageNamed:(NSImageNameComputer) anAttach’s setImage:anImage –添付画像をAttributed Stringに添付 set iconString to NSAttributedString’s attributedStringWithAttachment:anAttach anAssrStr’s insertAttributedString:iconString atIndex:0 –冒頭に添付 –ライブラリを用いてダイアログ表示 dispAttrStr(aString, "Computer Icon", anAssrStr, 600, 200) of tv –書式つきテキストを組み立てる on makeRTFfromParameters(aStr as string, fontName as string, aFontSize as real, aKerning as real, aLineSpacing as real) –Font set aVal1 to NSFont’s fontWithName:fontName |size|:aFontSize set aKey1 to (NSFontAttributeName) –Color set aVal2 to NSColor’s blackColor() set aKey2 to (NSForegroundColorAttributeName) –Kerning set aVal3 to aKerning set akey3 to (NSKernAttributeName) –Underline set aVal4 to 0 set akey4 to (NSUnderlineStyleAttributeName) –Ligature set aVal5 to 2 –all ligature ON set akey5 to (NSLigatureAttributeName) –縦書き指定–Japanese tategaki setting (Up to down, right to left direction drawing) set aVal6 to false set aKey6 to (current application’s NSVerticalGlyphFormAttributeName) –Paragraph space set aParagraphStyle to NSMutableParagraphStyle’s alloc()’s init() aParagraphStyle’s setMinimumLineHeight:(aLineSpacing) aParagraphStyle’s setMaximumLineHeight:(aLineSpacing) set akey7 to (NSParagraphStyleAttributeName) set keyList to {aKey1, aKey2, akey3, akey4, akey5, aKey6, akey7} set valList to {aVal1, aVal2, aVal3, aVal4, aVal5, aVal6, aParagraphStyle} set attrsDictionary to NSMutableDictionary’s dictionaryWithObjects:valList forKeys:keyList set attrStr to NSMutableAttributedString’s alloc()’s initWithString:aStr attributes:attrsDictionary return attrStr end makeRTFfromParameters |
More from my site
(Visited 1 times, 1 visits today)