現在開いているアプリケーションウインドウのUIオブジェクト情報を表示する
script AppDelegate property parent : class "NSObject" property theWindow : missing value
(* 変数のグローバル化(ハンドラが違っても、このスクリプト内であればデータが共有されます) *) --テーブルビュー用 property theDataSource : {} global aTableView, sourceList --ウインドウ1(theWindow)用 global popupButton1, popupButton2, textView1 global freeSizeWidthHeight global progressIndicator1,levelIndicator1 -- ウインドウ2(secondWindow)用 global secondWindow, secondWindowRect global splitViewTextField1, splitViewTextField2
on awakeFromNib() --Nibが呼ばれた直後に実行されるハンドラ(ウインドウが表示される前) theWindow's setFrameAutosaveName_("mainWindow") --前回閉じた時の位置とサイズの情報があれば復帰させる(終了時に自動保存される) set secondWindowRect to current application's NSMakeRect(500, 500, 400, 350) --|secondWindowの原点(左下)とサイズ| my makeSecondWindow() -- セカンドウインドウの作成ハンドラへ secondWindow's setFrameAutosaveName_("secondWindow") -- secondWindowの前回閉じた時の位置とサイズの情報があれば復帰させる end awakeFromNib on applicationWillFinishLaunching_(aNotification) -- ウインドウなどが読み込まれ表示された直後に実行 secondWindow's orderOut_(me) --セカンドウインドウはまだ使わないので一時的に隠します (* macOSのセキュリティーレベルがSystemEventsを妨害するかを判定 *) try tell application "System Events" to set windowList to name of every window of process "Finder" on error errText (* 上記の判定で動作しないと判断された場合は、システム環境設定のプライバシーウインドウを開き、ユーザーに設定を促します *) theWindow's setAlphaValue_(0.0) try display dialog (errText & return & ¬ "信頼できるかを判断の上、次に開くシステム環境設定のプライバシーにこのアプリケーションの追加をお願いします。" & return & ¬ "(このアプリケーションは一旦終了します)") buttons {"キャンセル","プライバシー設定を開く"} default button 1 if (button returned of result) = "プライバシー設定を開く" then tell application "System Preferences" --システム環境設定ウインドウを呼び出します reveal anchor "Privacy_Accessibility" of pane id "com.apple.preference.security" -- セキュリティーウインドウに切り替えます activate -- 最前面に表示します(この場合直前のシステム環境設定のプライバシーのウインドウがアクティブ化されます) end tell end if end try quit me --プライバシー設定を変更するために、このアプリケーションを終了します return end try (* ●●● Window 1 (theWindow) の項目 ●●● *) (* メインのウインドウ(theWindow)の情報&調整 *) set {{view_x, view_y},{view_w, view_h}} to theWindow's contentView()'s frame() -- theWindowに張り付いたViewの矩形を取得 tell theWindow setDelegate_(me) -- theWindowのデリゲート(観察部)を設定します(ウインドウを閉じた時に情報を観察部に送られないと困るので) makeKeyAndOrderFront_(me) -- theWindowをキーウインドウとして最前面にお表示します setMinSize_(current application's NSMakeSize(420,300)) -- theWindowの最小サイズを設定 end tell
(* オートサイジングの情報の準備 *) set notSizable to (current application's NSViewNotSizable) as integer -- 位置とサイズ固定 set minXMargin to (current application's NSViewMinXMargin) as integer -- 左の余白を柔軟に set maxXMargin to (current application's NSViewMaxXMargin) as integer -- 右の余白を柔軟に set minYMargin to (current application's NSViewMinYMargin) as integer -- 下のの余白を柔軟に set maxYMargin to (current application's NSViewMaxYMargin) as integer -- 上の余白を柔軟に set widthSizable to (current application's NSViewWidthSizable) as integer -- 横方向の幅を柔軟に set heightSizable to (current application's NSViewHeightSizable) as integer -- 縦方向の幅を柔軟に set fixedTopAndLeft to minYMargin + maxXMargin -- 上と左を固定・幅固定 set fixedTopAndRight to minYMargin + minXMargin -- 上と右を固定・幅固定 set fixedTopFreeSizeWidth to minYMargin + widthSizable -- 上を固定して左右幅は柔軟に set freeSizeWidthHeight to widthSizable + heightSizable -- 縦と横の幅を柔軟に set freeSizeWidth to widthSizable + maxYMargin + minYMargin --上下の中央で幅を自由に set positionFreeFixedSize to minXMargin + maxXMargin + minYMargin + maxYMargin -- サイズは固定で天地左右を柔軟に set fixedUnderAndRightAndSize to minXMargin + maxYMargin -- 右と下とサイズは固定(左と上は柔軟)
(* テキスト『Process:』表示用。実はボタンを作成 *) set theRect to current application's NSMakeRect(1, view_h - 26, 60, 24) set processButton to current application's class "NSButton"'s alloc()'s initWithFrame_(theRect) tell processButton setBordered_(0) -- 枠を非表示に setTitle_("Process:") -- タイトルを設定 setTarget_(me) -- ターゲットのスクリプトを、自分自身であるここのスクリプトに設定 setAction_("getProcess") -- このボタンがクリックされた場合に送られるハンドラ名 setAutoresizingMask_(fixedTopAndLeft) -- ウインドウがリサイズされた時の変形の仕方の設定(左上に固定で幅の変更は無し) end tell theWindow's contentView()'s addSubview_(processButton)
(* PopupButton作成(1) *) set theRect to current application's NSMakeRect(55, view_h - 25, 150, 23) set popupButton1 to current application's class "NSPopUpButton"'s alloc()'s initWithFrame_pullsDown_(theRect,false) tell popupButton1 addItemsWithTitles_({"-"}) setAction_("actionPopup1") setAutoresizingMask_(fixedTopAndLeft) end tell theWindow's contentView()'s addSubview_(popupButton1)
(* PopupButton作成(2) *) set theRect to current application's NSMakeRect(205, view_h - 25, view_w - 330, 23) set popupButton2 to current application's class "NSPopUpButton"'s alloc()'s initWithFrame_pullsDown_(theRect,false) tell popupButton2 addItemsWithTitles_({"-"}) setAutoresizingMask_(fixedTopFreeSizeWidth) end tell theWindow's contentView()'s addSubview_(popupButton2)
(* Button作成(1) *) set theRect to current application's NSMakeRect(view_w - 130,view_h - 26,75,24) set button1 to current application's class "NSButton"'s alloc()'s initWithFrame_(theRect) tell button1 setBezelStyle_(1) setButtonType_(0) setTitle_("Window") setTarget_(me) setAction_("action1") setAutoresizingMask_(fixedTopAndRight) end tell theWindow's contentView()'s addSubview_(button1)
(* Button作成(2) *) set theRect to current application's NSMakeRect(view_w - 65,view_h - 26,65,24) set button2 to current application's class "NSButton"'s alloc()'s initWithFrame_(theRect) tell button2 setBezelStyle_(1) setButtonType_(0) setTitle_("Menu") setTarget_(me) setAction_("action2") setAutoresizingMask_(fixedTopAndRight) end tell theWindow's contentView()'s addSubview_(button2)
(* TableView作成 *) set {x,y,w,h} to {3,3,view_w - 6, view_h - 28} my makeTableView(x,y,w,h) -- Table作成ハンドラへ
(* ProgressIndicator作成(丸) *) set theRect to current application's NSMakeRect(view_w / 2 - 20,view_h / 2 - 20,40,40) set progressIndicator1 to current application's class "NSProgressIndicator"'s alloc()'s initWithFrame_(theRect) tell progressIndicator1 setDoubleValue_(0.0) setMinValue_(0.0) setMaxValue_(1.0) setStyle_(1) -- |スタイル設定(0:デフォ(棒),1:丸,2:棒)| setIndeterminate_(true) -- |未確定状態(yes/no) デフォルト表示/黒塗り anime時は1/数値表示は0| stopAnimation_(true) --アニメーションを停止状態に setHidden_(true) --まだ使用しないので隠す setAutoresizingMask_(positionFreeFixedSize) end tell theWindow's contentView()'s addSubview_(progressIndicator1) (* LevelIndicator(レベルインジケーター)作成 *) set theRect to current application's NSMakeRect(view_w / 4,view_h / 2 - 60,view_w / 2,15) set levelIndicator1 to current application's class "NSLevelIndicator"'s alloc()'s initWithFrame_(theRect) tell levelIndicator1 setDoubleValue_(8.0) -- |初期値| setMinValue_(0.0) -- |最小値| setMaxValue_(1.0) -- |最大値| setLevelIndicatorStyle_(current application's NSLevelIndicatorStyleRelevancy) --スタイル:黒い縞模様 setHidden_(true) setAutoresizingMask_(freeSizeWidth) end tell theWindow's contentView()'s addSubview_(levelIndicator1) -- (* ●●● Window 2 (secondWindow) の項目 ●●● *) set {{view_x, view_y},{view_w, view_h}} to secondWindow's contentView()'s frame() (* Button作成(3) *) set theRect to current application's NSMakeRect(view_w - 80,0,80,24) set button3 to current application's class "NSButton"'s alloc()'s initWithFrame_(theRect) tell button3 setBezelStyle_(1) setButtonType_(0) setTitle_("閉じる") setTarget_(me) setAction_("action3") setAutoresizingMask_(fixedUnderAndRightAndSize) end tell secondWindow's contentView()'s addSubview_(button3)
(* SplitView作成(上下または左右で並べられる大きさの可変可能な複数のNSViewを持つオブジェクト) *) -- SplitViewに配置するViewアイテムを必要数(今回は2つ)作成 set splitViewItem1 to current application's class "NSView"'s alloc()'s init() set splitViewItem2 to current application's class "NSView"'s alloc()'s init() -- SplitView作成 set aVertical to false --並べる方向(true=左右, false=上下)用 set theRect to current application's NSMakeRect(3,24,view_w - 6,view_h - 30) set splitView1 to current application's class "NSSplitView"'s alloc()'s initWithFrame_(theRect) tell splitView1 setDelegate_(me) setVertical_(aVertical) --Viewの並べる方向の設定 setDividerStyle_(current application's NSSplitViewDividerStyleThick) -- 厚い仕切りのスタイルを設定 addArrangedSubview_(splitViewItem1) -- splitViewItem1をのせる(追加する) addArrangedSubview_(splitViewItem2) -- splitViewItem2をのせる(追加する) setAutoresizingMask_(freeSizeWidthHeight) --ビューのサイズを自由にオートサイジングする end tell secondWindow's contentView()'s addSubview_(splitView1) -- secondWindowのコンテンツビューにのせる -- SplitViewのアイテムのサイズが不明確なので上書き再設定をする(仕切りの数と厚さを考慮します) set {{splitView1_X,splitView1_Y},{splitView1_W,splitView1_H}} to splitView1's frame() set viewItemCount to count of (splitView1's subviews()) -- splitViewに配置されたviewの数を取得 set aDividerThickness to splitView1's dividerThickness() -- splitViewの仕切りの厚さを取得 set totalDividerThickness to aDividerThickness * (viewItemCount - 1) if aVertical then -- ヨコ並びのViewアイテムの大きさ再設定 set splitView1ItemRect to current application's NSMakeSize((splitView1_W - totalDividerThickness) / viewItemCount, splitView1_H) else -- タテ並びのViewアイテムの大きさ再設定 set splitView1ItemRect to current application's NSMakeSize(splitView1_W, (splitView1_H - totalDividerThickness) / viewItemCount) end if splitViewItem1's setFrameSize_(splitView1ItemRect) splitViewItem2's setFrameSize_(splitView1ItemRect)
(* NSTextFieldタイトル(1) *) set {{view_x, view_y},{view_w, view_h}} to splitViewItem1's frame() --1つ目のsplitViewの大きさを取得 -- set theRect to current application's NSMakeRect(0,view_h - 22,150,25) set textField1 to current application's class "NSTextField"'s alloc()'s initWithFrame_(theRect) tell textField1 setSelectable_(false) setBordered_(false) setStringValue_("Script") setDrawsBackground_(false) setAutoresizingMask_(fixedTopAndLeft) end tell splitViewItem1's addSubview_(textField1) (* NSTextFieldデータ表示(1) *) set theRect to current application's NSMakeRect(0,2,view_w,view_h - 16) set splitViewTextField1 to current application's class "NSTextField"'s alloc()'s initWithFrame_(theRect) tell splitViewTextField1 setSelectable_(true) setBordered_(true) setStringValue_(" ") setFont_(current application's class "NSFont"'s systemFontOfSize_(14.0)) setTextColor_(current application's class "NSColor"'s blackColor()) setDrawsBackground_(true) setBackgroundColor_(current application's class "NSColor"'s whiteColor()) setAutoresizingMask_(freeSizeWidthHeight) --ビューのサイズを自由にオートサイジングする end tell splitViewItem1's addSubview_(splitViewTextField1) (* NSTextFieldタイトル(2) *) set {{view_x, view_y},{view_w, view_h}} to splitViewItem2's frame() --1つ目のsplitViewの大きさを取得 -- set theRect to current application's NSMakeRect(0,view_h -25 ,150,25) set textField2 to current application's class "NSTextField"'s alloc()'s initWithFrame_(theRect) tell textField2 setSelectable_(false) setBordered_(false) setStringValue_("Properties") setDrawsBackground_(false) setAutoresizingMask_(fixedTopAndLeft) end tell splitViewItem2's addSubview_(textField2) (* NSTextFieldデータ表示(2) *) set theRect to current application's NSMakeRect(0,2,view_w,view_h - 18) set splitViewTextField2 to current application's class "NSTextField"'s alloc()'s initWithFrame_(theRect) tell splitViewTextField2 setSelectable_(true) setBordered_(true) setStringValue_(" ") setFont_(current application's class "NSFont"'s systemFontOfSize_(14.0)) setTextColor_(current application's class "NSColor"'s blackColor()) setDrawsBackground_(true) setBackgroundColor_(current application's class "NSColor"'s whiteColor()) setAutoresizingMask_(freeSizeWidthHeight) --ビューのサイズを自由にオートサイジングする end tell splitViewItem2's addSubview_(splitViewTextField2) (* ●●● Process情報の取得 ●●● *) my getProcess() end applicationWillFinishLaunching_
(* UI情報の取得 *) on getProcess() -- Process情報の取得 set popButtonTitle1 to (popupButton1's titleOfSelectedItem()) as string set popButtonTitle2 to (popupButton2's titleOfSelectedItem()) as string if popButtonTitle2 = "- No window -" then return try tell application "System Events" to set processList to name of every process whose visible is true on error errText textView1's setString_("::: Err 1 : プロセスリストの取得に失敗 :::") return end try set deleteItem to name of (current application) --|自分自身を対象外にするための準備としてアプリケーション名を取得| tell popupButton1 removeAllItems() addItemsWithTitles_(processList) try removeItemWithTitle_(deleteItem) -- 自分自身を除外 end try end tell
try popupButton1's selectItemWithTitle_(popButtonTitle1) on error textView1's setString_("::: Err 2 : ウインドウリストの取得に失敗 :::") return end try set popButtonTitle1 to popupButton1's titleOfSelectedItem() if popButtonTitle1 = missing value then popupButton1's selectItemAtIndex_(0) set popButtonTitle1 to (popupButton1's titleOfSelectedItem()) as string tell application "System Events" to set windowList to name of every window of process popButtonTitle1 if windowList = {} then set windowList to {"- No Data -"} tell popupButton2 removeAllItems() addItemsWithTitles_(windowList) end tell try popupButton2's selectItemWithTitle_(popButtonTitle2) end try set popButtonTitle2 to popupButton2's titleOfSelectedItem() if popButtonTitle2 = missing value then popupButton2's selectItemAtIndex_(0) end getProcess
(* 『Window』ボタンがクリックされた時のアクション *) on action1() set sourceList to {} set theDataSource to current application's class "NSMutableArray"'s alloc()'s init() theDataSource's addObjectsFromArray_(sourceList) aTableView's reloadData() aTableView's setUsesAlternatingRowBackgroundColors_(false) --縞模様をOFF
set popButtonTitle2 to (popupButton2's titleOfSelectedItem()) as string if popButtonTitle2 = "- No window -" then return
tell progressIndicator1 startAnimation_(true) -- |anime On| setHidden_(false) end tell tell levelIndicator1 setDoubleValue_(0.0) setHidden_(false) end tell delay 0.1
set popButtonTitle1 to (popupButton1's titleOfSelectedItem()) as string set popButtonTitle2 to popupButton2's titleOfSelectedItem() as string try tell application "System Events" to set aContents to entire contents of window popButtonTitle2 of process popButtonTitle1 on error errText log errText return end try my dataOrganize(aContents) end action1
(* 『Menu』ボタンがクリックされた時のアクション *) on action2() set sourceList to {} set theDataSource to current application's class "NSMutableArray"'s alloc()'s init() theDataSource's addObjectsFromArray_(sourceList) aTableView's reloadData() aTableView's setUsesAlternatingRowBackgroundColors_(false) --縞模様をOFF
set popButtonTitle2 to (popupButton2's titleOfSelectedItem()) as string if popButtonTitle2 = "- No window -" then return
tell progressIndicator1 startAnimation_(true) -- |anime On| setHidden_(false) end tell tell levelIndicator1 setDoubleValue_(0.0) setHidden_(false) end tell delay 0.1
set popButtonTitle1 to (popupButton1's titleOfSelectedItem()) as string try tell application "System Events" to set aContents to entire contents of menu bar 1 of process popButtonTitle1 on error errText log errText return end try my dataOrganize(aContents) end action2 (* 閉じるボタンのアクション *) on action3() secondWindow's orderOut_(me) end action3
(* 一つ目のポップアップボタンが変更された時のアクション *) on actionPopup1() set popButtonTitle1 to (popupButton1's titleOfSelectedItem()) as string --PopupButton1の最後に選択されたタイトルを取得(アプリケーション) if popButtonTitle1 = "-" then return --なにも選択されていなかった場合は、何もせず戻る tell application "System Events" to set windowList to name of every window of process popButtonTitle1 --選択したアプリケーションのすべてのウインドウを取得 if windowList = {} then set windowList to {"- No window -"} tell popupButton2 --内容をポップアップボタン2に反映 removeAllItems() addItemsWithTitles_(windowList) end tell popupButton2's selectItemWithTitle_(popButtonTitle2) set popButtonTitle2 to popupButton2's titleOfSelectedItem() if popButtonTitle2 = missing value then popupButton2's selectItemAtIndex_(0) --変更する前に選択されていたタイトルと同じものがあれば、それを選択し直す end actionPopup1 (* テーブルアイテムがクリックされた場合に実行(シングルクリック) *) on tabelAction() if sourceList = {} then return -- テーブルビューにアイテムがない場合はそのまま戻る splitViewTextField1's setStringValue_("") --テキストフィールドを初期化 splitViewTextField2's setStringValue_("") delay 0.01 set lineNo to aTableView's clickedRow() --テーブルビューのクリックした行を取得(1行目は0で数えます) set selectionItem to data1 of item (lineNo + 1) of sourceList --データソースから該当する行の文章を取得 set popButtonTitle1 to popupButton1's titleOfSelectedItem() -- PopupButton1の最後に選ばれた情報を取得 set popButtonTitle2 to popupButton2's titleOfSelectedItem() -- PopupButton2の最後に選ばれた情報を取得 secondWindow's orderFront_(me) -- セカンドウインドウを可視化(最前面に表示) -- (1) code 表示 set codeText to "tell application \"System Events\"" & return & return set codeText to codeText & (ascii character 9) & selectionItem & return & return & "end tell" --| (ascii character 9)はTabのこと | splitViewTextField1's setStringValue_(codeText) -- (2) properties 表示 set codeText to "tell application \"System Events\"" & return set codeText to codeText & "get properties of " & selectionItem & return & "end tell" set aResult to run script codeText -- run script処理(System EventsでUI Elementのプロパティー情報の取得に使っています) try set theData to aResult as integer on error errText set theData to (text ((offset in errText of "{") + 1) thru ((offset in errText of "} into type") - 1) of errText) & return --先頭末尾の"{ }"は削る end try set theData to my setDelimiter(theData, ", «", (ascii character 13) & "«") set theData to my setDelimiter(theData, "\", ", "\"" & return) set theData to my setDelimiter(theData, ", name:", "," & return & "name:") (* 差し替えをするためのキーワードテキストを処理 *) set akeyText to my sashikaekigou() --テキストワードを置いてあるハンドラからデータを取得 repeat with obj in (paragraphs of akeyText) --1行づつ処理を繰り返していく set obj to obj as string set c to offset in obj of "," -- 古いワードと新しいワードの間に挟まれたカンマ[,]の位置を取得 set oldText to text 1 thru (c - 1) of obj --カンマから左側(古いワード)を取得 set newText to text (c + 1) thru -1 of obj -- 右側(新しいワード)を取得 if ((character 1 of newText) as string) = " " then set newText to text 2 thru -1 of newText -- -- 右のワードの1文字目がスペース文字の場合は削除 if theData contains oldText then -- 処理をするtheDataの中に、oldTextの古いワードを発見したら次を処理 set theData to my setDelimiter(theData, oldText, newText) -- 古いワードと新しいワードを入れ替える処理(デリミタ) end if end repeat splitViewTextField2's setStringValue_(theData) end tabelAction (* デリミタ(テキスト差し替え) *) on setDelimiter(textItem, oldText, newText) set textItem to textItem as text set lastDelimit to AppleScript's text item delimiters set AppleScript's text item delimiters to oldText set obj to every text item of textItem set AppleScript's text item delimiters to newText set textItem to obj as text set AppleScript's text item delimiters to lastDelimit return textItem end setDelimiter
(* WindowまたはMenuのUI情報をすべて表示 *) on dataOrganize(theData) (* 受け取ったデータがおそらくそのままではテキストにならないので、エラー処理を使って整理 *) try set theData to theData as integer on error errText set theData to text ((offset in errText of "{") + 1) thru ((offset in errText of "} into type") - 1) of errText --先頭末尾の"{ }"は削る end try (* 共通したコードの整理 *) set theData to my setDelimiter(theData, "\", ", "\"" & return) set theData to my setDelimiter(theData, " of application \"System Events\"", "") set theData to my setDelimiter(theData, " of", " of") (* 読みにくいコードを、読みやすい方に変換 *) set akeyText to my sashikaekigou() --差し替える単語の取得 levelIndicator1's setDoubleValue_(0.05) repeat with obj in (paragraphs of akeyText) set obj to obj as string set c to offset in obj of "," set oldText to text 1 thru (c - 1) of obj set newText to text (c + 1) thru -1 of obj if ((character 1 of newText) as string) = " " then set newText to text 2 thru -1 of newText if theData contains oldText then set theData to my setDelimiter(theData, oldText, newText) end if end repeat levelIndicator1's setDoubleValue_(0.1) -- 第一段階が終了したことをレベルでお知らせ (* テーブルビューに表示 *) set theDataSource to current application's class "NSMutableArray"'s alloc()'s init() set sourceList to {} set i to 0 set maxCount to count of (paragraphs of theData) repeat with obj in (paragraphs of theData) set i to i + 1 set oneLine to obj as text theDataSource's addObjectsFromArray_({{data1: (oneLine as text)}}) set sourceList to sourceList & {{data1: oneLine}} levelIndicator1's setDoubleValue_(0.1 + (i / maxCount * 0.88)) --進歩状況を随時表示 delay 0.001 end repeat aTableView's reloadData() aTableView's setUsesAlternatingRowBackgroundColors_(true) levelIndicator1's setDoubleValue_(1.0) --進歩状況が100%になったことをお知らせ delay 0.5 --画面表示の急な切り替わりの表示の緩和 (気持ちだけ) (* プログレスサークルを不使用状態に変更 *) tell progressIndicator1 stopAnimation_(true) -- anime Off setHidden_(true) -- 非表示状態に end tell (* レベルバーを不使用状態に変更 *) tell levelIndicator1 setDoubleValue_(0.0) --数値をリセット setHidden_(true) -- 非表示状態に end tell end dataOrganize
(* ●●●●●● TableView関連 ここから ●●●●●● *) on makeTableView(x,y,w,h) set sourceList to {} --{{data1: "テキスト"}} (* データーソースを用意する *) set theDataSource to current application's class "NSMutableArray"'s alloc()'s init() theDataSource's addObjectsFromArray_(sourceList)
(* コラムデータ(列)を作成 *) set aColumn1 to current application's class "NSTableColumn"'s alloc()'s initWithIdentifier_("data1") tell aColumn1 setWidth_(2000) --headerCell()'s setTitle_("Code") --テーブルビューのヘッダを隠すため不要 end tell (* コラムデータをテーブルデータにのせる *) set aTableView to current application's class "NSTableView"'s alloc()'s initWithFrame_(current application's NSMakeRect(0, 0, w, h)) tell aTableView addTableColumn_(aColumn1) setDelegate_(me) setAction_("tabelAction") setDataSource_(me) setBackgroundColor_(current application's class "NSColor"'s whiteColor) setHeaderView_(missing value) --ヘッダーを隠す end tell
(* スクロールビューのコンテンツビューにテーブルデータをのせて配置 *) set aScroll to current application's class "NSScrollView"'s alloc()'s initWithFrame_(current application's NSMakeRect(x,y,w,h)) aScroll's setDocumentView_(aTableView) theWindow's contentView()'s addSubview_(aScroll) tell aScroll setHasHorizontalScroller_(true) setHasVerticalScroller_(true) setAutohidesScrollers_(true) setAutoresizingMask_(freeSizeWidthHeight) end tell aTableView's reloadData() --|変更されたテーブルの内容で再表示| end makeTableView (* TableViewの表示行数処理(必須) *) on numberOfRowsInTableView_(aTableView) set dataSourceCount to count of (my theDataSource) return dataSourceCount end numberOfRowsInTableView_
(* TableViewデータの処理(必須) *) on tableView_objectValueForTableColumn_row_(aTableView, aColumn, aRow) set aRecord to (my theDataSource)'s objectAtIndex_(aRow as number) set aIdentifier to (aColumn's identifier()) as string set aResult to (aRecord's valueForKey_(aIdentifier)) return aResult end tableView_objectValueForTableColumn_row_ -- ●●●●●● TableView関連 ここまで
(* 2つ目のウインドウを新規で作成 *) on makeSecondWindow() (* ●●● Window 2 (secondWindow) の項目 ●●● *) (* make new NSWindow *) set aStyle to (current application's NSWindowStyleMaskTitled as integer) --set aStyle to aStyle + (current application's NSWindowStyleMaskClosable as integer) --Closeボタンのみ外す set aStyle to aStyle + (current application's NSWindowStyleMaskMiniaturizable as integer) set aStyle to aStyle + (current application's NSWindowStyleMaskResizable as integer) set aBacking to current application's NSBackingStoreBuffered set secondWindow to current application's class "NSWindow"'s alloc()'s ¬ initWithContentRect_styleMask_backing_defer_(secondWindowRect,aStyle,aBacking,false) tell secondWindow setDelegate_(me) --|デリゲート先の設定| setTitle_("Info") --|タイトル名| setTitleVisibility_(0) --|タイトルバー内のタイトル名の『非表示』設定| setMaxSize_(current application's NSMakeSize(10000,10000)) --|最大サイズ| setMinSize_(current application's NSMakeSize(300,280)) --|最小サイズ| setBackgroundColor_(current application's class "NSColor"'s lightGrayColor) --|背景色| setOpaque_(false) --|透過指示| setAlphaValue_(1.0) --|不透明度| setTitlebarAppearsTransparent_(true) orderBack_(me) end tell end makeSecondWindow
(* 単語の差し替え用のデータ *) on sashikaekigou() set aText to "«class uiel», UI element «class axds», accessibility description «class butT», button «class ccol», column «class chbx», checkbox «class colW», color well «class comB», combo box «class crow», row «class desc», description «class ects», entire contents «class enaB», enabled «class focu», focused «class help», help «class imaA», image «class maxV», maximum value «class mbar», menu bar «class mbri», menu bar item «class menB», menu button «class menE», menu «class menI», menu item «class minW», minimum value «class orie», orientation «class outl», outline «class pcap», application process «class popB», pop up button «class posn», position «class radB», radio button «class rgrp», radio group «class rold», role description «class role», role «class sbrl», subrole «class scra», scroll area «class scrb», scroll bar «class selE», selected «class sgrp», group «class sheE», sheet «class sliI», slider «class splg», splitter group «class splr», splitter «class sttx», static text «class tabB», table «class tabg», tab group «class tbar», toolbar «class titl», title «class txta», text area «class txtf», text field «class valL», value «class vali», value indicator" return aText end sashikaekigou
(* いずれかのウインドウが閉じられたらここを実行(要Delegateの接続) *) on windowWillClose_(sender) set closeWindowName to (title of object of sender) as string set applicationName to name of (current application) if closeWindowName = applicationName then quit me set secondWindowRect to secondWindow's frame end windowWillClose
on applicationShouldTerminate_(sender) log "Quit" return current application's NSTerminateNow end applicationShouldTerminate_
end script |