アラートダイアログ上にTextViewを表示して、指定のテキストを閲覧するAppleScriptです。
とくにこれといって何か表示するものを思いつかなかったので、自分自身のソースコードを取得して表示しています。スクリプトエディタやScript Debugger上で実行した場合には自分自身のソースコードをテキストビュー上で表示します。
読み取り専用のスクリプトやアプレットで実行している場合にはソースコードを取得できません。何か適宜自分で表示させたいテキストを与えてみてください。
AppleScript名:アラートダイアログ上にTexViewを表示 |
— Created 2019-07-02 by Takaaki Naganoya — 2019 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" use framework "AppKit" use framework "OSAKit" property |NSURL| : a reference to current application’s |NSURL| property NSFont : a reference to current application’s NSFont property NSView : a reference to current application’s NSView property NSAlert : a reference to current application’s NSAlert property NSColor : a reference to current application’s NSColor property NSTextView : a reference to current application’s NSTextView property NSScrollView : a reference to current application’s NSScrollView property NSRunningApplication : a reference to current application’s NSRunningApplication property OSAScript : a reference to current application’s OSAScript property returnCode : 0 –Get Self Source Code (a kind of joke) set mePath to path to me set asStr to getASsourceFor(mePath) of me set paramObj to {myMessage:"Main Message", mySubMessage:"Sub information", mes1:(asStr), mesWidth:400, mesHeight:200, fontName:"HiraginoSans-W3", fontSize:11.0} –my dispTextViewWithAlertdialog:paramObj–for debug my performSelectorOnMainThread:"dispTextViewWithAlertdialog:" withObject:paramObj waitUntilDone:true on dispTextViewWithAlertdialog:paramObj –Receive Parameters set aMainMes to (myMessage of paramObj) as string –Main Message set aSubMes to (mySubMessage of paramObj) as string –Sub Message set mesStr to (mes1 of paramObj) as string –Text Input field 1 Label set aWidth to (mesWidth of paramObj) as integer –TextView width set aHeight to (mesHeight of paramObj) as integer –TextView height set aFontName to (fontName of paramObj) as string –TextView font name set aFontSize to (fontSize of paramObj) as real –TextView font size — Create a TextView with Scroll View set aScroll to NSScrollView’s alloc()’s initWithFrame:(current application’s NSMakeRect(0, 0, aWidth, aHeight)) set aView to NSTextView’s alloc()’s initWithFrame:(current application’s NSMakeRect(0, 0, aWidth, aHeight)) aView’s setRichText:true aView’s useAllLigatures:true aView’s setTextColor:(current application’s NSColor’s cyanColor()) –cyanColor aView’s setFont:(current application’s NSFont’s fontWithName:aFontName |size|:aFontSize) set aColor to current application’s NSColor’s colorWithDeviceRed:0.0 green:0.0 blue:0.0 alpha:0.5 aView’s setBackgroundColor:aColor aView’s setString:mesStr aScroll’s setDocumentView:aView aView’s enclosingScrollView()’s setHasVerticalScroller:true — set up alert set theAlert to NSAlert’s alloc()’s init() tell theAlert its setMessageText:aMainMes its setInformativeText:aSubMes its addButtonWithTitle:"OK" its addButtonWithTitle:"Cancel" its setAccessoryView:aScroll end tell — show alert in modal loop NSRunningApplication’s currentApplication()’s activateWithOptions:0 my performSelectorOnMainThread:"doModal:" withObject:(theAlert) waitUntilDone:true if (my returnCode as number) = 1001 then error number -128 end dispTextViewWithAlertdialog: on doModal:aParam set (my returnCode) to aParam’s runModal() end doModal: –指定AppleScriptファイルのソースコードを取得する(実行専用Scriptからは取得できない) — Original Created 2014-02-23 Shane Stanley on getASsourceFor(anAlias as {alias, string}) set aURL to |NSURL|’s fileURLWithPath:(POSIX path of anAlias) set theScript to OSAScript’s alloc()’s initWithContentsOfURL:aURL |error|:(missing value) if theScript is equal to missing value then error "Compile Error" — handle error else set sourceText to theScript’s source() end if return sourceText as string end getASsourceFor |