01/17 OniOutlinerで選択中の行の内容のうち指定列のデータをすべて取得
OmniOutliner Professional v3.9.5で(通常のOmni Outlinerもtellブロックのアプリ名称を変更すればそのまま動作)、選択中の行のデータの中から指定列(カラム)のデータをすべて取得するAppleScriptです。
つまり、選択行の中の指定カラムのデータを取得するものです。こうした機能が標準搭載されていないほうがおかしいような気がします。そのままGUI上でExcelに選択データをペーストすると、1つの列の中にすべてのデータが入ってしまうなど、動作内容がいまいちです。
そこで、AppleScriptの登場となるわけで……旅行からの帰りの電車の中で勢いだけで作ってしまいました。
まずは、Onni Outliner上で行を選択。

スクリプトを実行すると、どの列のデータを取得するか聞いてきます。Command-クリックを行うことで、複数の列のデータを指定できます。

ためしに、「トピック」列と「Column2」列を選択すると……
{{”line2″, “”}, {”line3″, “●”}, {”line4″, “●”}, {”line5″, “”}}
といった結果が得られます。これは、Excelに貼付けることを前提としてデータを作成しているものであり、あとはExcelへのデータ貼り付けルーチンを作って用意すれば、便利に使えそうです。

……結局、Excelのワークシートを新規作成して、データ転送するところまで作り込んでしまいました。ここまでやると、たしかに便利。
| スクリプト名:OniOutlinerで選択中の行の内容のうち指定列のデータをすべて取得 |
| global tList, numRes set tList to {} tell application “OmniOutliner Professional” tell document 1 set aSel to every row whose selected is true if aSel = {} then display dialog “OmniOutliner上で選択されている行はありませんでした。” buttons {“OK”} default button 1 return end if end tell end tell –どの列を書き出すかを選択 tell application “OmniOutliner Professional” tell document 1 set nList to name of every column set aMes to “項目を選択してください(Command-クリックで複数選択可能)” set numRes to retMultipleItemFromListByItemNo(nList, aMes) of me end tell end tell –選択部分を検出 tell application “OmniOutliner Professional” tell document 1 set aaSel to first item of aSel tell aaSel set aCell to text of every cell set aCell to retSpecifiedItemFromList(numRes, aCell) of me set the end of tList to aCell set cList to every child repeat with i in cList getChildText(i) of me end repeat end tell end tell end tell tList –> {{”line2″, “”}, {”line3″, “●”}, {”line4″, “●”}, {”line5″, “”}} –再帰で指定child以下のテキストをすべて取得する on getChildText(aRoot) tell application “OmniOutliner Professional” tell document 1 tell aRoot set aCell to text of every cell set aCell to retSpecifiedItemFromList(numRes, aCell) of me set the end of tList to aCell set cList to every child repeat with i in cList getChildText(i) of me –再帰処理 end repeat end tell end tell end tell end getChildText –リストから選択してアイテム番号を返す(複数項目選択対応) on retMultipleItemFromListByItemNo(aList, aMes) set aRes to choose from list aList with prompt aMes with multiple selections allowed if aRes = false then return 0 set hitList to {} repeat with i1 in aRes set aRes to contents of i1 set hitNum to 1 repeat with i in aList set j to contents of i if j is equal to aRes then exit repeat end if set hitNum to hitNum + 1 end repeat set the end of hitList to hitNum end repeat return hitList end retMultipleItemFromListByItemNo –指定リストから、指定アイテム目を抽出して返す on retSpecifiedItemFromList(itemNumList, dataList) set newList to {} repeat with i in itemNumList set j to contents of i set a to contents of (item j of dataList) set the end of newList to a end repeat return newList end retSpecifiedItemFromList |

