自前でメニューを作ってフォントおよびサイズの選択を行おうとするとめんどくさい(時間がかかるし管理も大変)ので、NSFontPanelを用いてフォントを選択する試作品を作ってみました。
ただし、まだ完全ではなく「1つ前の状態が取得できる」という状態なので、修正が必要です。作成はmacOS 10.14.6+Xcode 11.3.1上で行っています。
AppleScript名:AppDelegate.applescript |
— — AppDelegate.applescript — fontPanel — — Created by Takaaki Naganoya on 2020/03/12. — Copyright © 2020 Takaaki Naganoya. All rights reserved. — script AppDelegate property parent : class "NSObject" — IBOutlets property theWindow : missing value property theField : missing value property aFontNameField : missing value property aFontSizeField : missing value property aFontManager : missing value property font : missing value property aFP : missing value on applicationWillFinishLaunching:aNotification set aFontManager to current application’s NSFontManager’s sharedFontManager() aFontManager’s setAction:"appSpecificChangeFont:" set aFP to current application’s NSFontPanel’s sharedFontPanel() set aFont to current application’s NSFont’s fontWithName:"Helvetica" |size|:16 aFontManager’s setSelectedFont:aFont isMultiple:false theField’s setStringValue:"ぴよまるソフトウエア, Piyomaru Software" end applicationWillFinishLaunching: on applicationShouldTerminate:sender — Insert code here to do any housekeeping before your application quits return current application’s NSTerminateNow end applicationShouldTerminate: on clicked:aSender theWindow’s makeFirstResponder:theField aFP’s makeKeyAndOrderFront:me end clicked: on appSpecificChangeFont:sender set aSelFont to sender’s selectedFont() set aDesc to aSelFont’s fontDescriptor() set aPSID to (aDesc’s postscriptName()) as string set aSize to (aDesc’s pointSize()) as real theField’s setFont:aSelFont aFontNameField’s setStringValue:aPSID aFontSizeField’s setStringValue:(aSize as string) end appSpecificChangeFont: end script |