Apple の脅威の通知と金銭目当てのスパイウェアへの対策について

しばらく返答が寄せられていないようです。 再度ディスカッションを開始するには、新たに質問してください。

Numbersで辞書検索

英単語の一覧リストに、オンライン辞書で検索した和訳を取得する事はできないでしょうか?


Excelだと、VBAとwebクエリで以下のリンクのようなことができるようなのですが、、

http://www.freeformat.co.jp/AddInIndex.htm?FFFunc419.htm


下記のトピックを見つけましたが、automatorはまだなんとかなりそうですが

一からApplescriptを書くのは、全く知識がないので難しそうです。

numbersでエクセルのwebクエリのような機能はありますか?


何卒宜しくお願い致します

IMAC (RETINA 5K, 27-INCH, LATE 2015), iOS 11.1.2

投稿日 2018/01/11 11:41

返信
返信: 12

2018/01/11 20:33 Akeera への返信

失礼致します。


1)オンライン辞書を使う場合、サーバーによってデータへアクセスする方法が異なるので、それぞれに対応した方法を用意する必要があるので、処理が複雑になりそうです。 このサイトの辞書でなければならないというものがありますか?


2)Automator.appには、辞書アプリの辞書を使って単語を調べるアクションがありますので、簡単なワークフローやサービスを作って利用することができます。


次のサービスは選択した文字列を、指定した辞書で検索して、選択した文字列を辞書の定義で置換してくれます。 但し、一つの単語しか置換してくれません。

Numbers.appの表のセルに入っている英単語を選択すると、コンテクスチュアルメニューからサービスを実行できます。

ユーザがアップロードしたファイル

次のワークフローは、ほぼ同じですが、Terminal.appのautomatorコマンドから実行することができます。

ユーザがアップロードしたファイル

Terminal.appのdictコマンドも便利だと思います。


3)Numbers.appの表を操作するには、今の所、どうしてもAppleScriptか、JavaScriptを使う必要があります。 こちらのサイトがとても参考になると思います。


 → Numbers

2018/01/13 09:52 Akeera への返信

Numbers.appの表で選択しているセルから、値を取り出すAppleScriptは以下になります。


tell front document of application "Numbers"

tell active sheet

set theTable to first table whose class of selection range is range

tell theTable

set wordList to value of cells of selection range

end tell

end tell

end tell

--> {"preacher", "wisdom", "Recognition"}


ユーザがアップロードしたファイル

2018/01/13 12:20 Akeera への返信

definitionListは、AppleScriptのテキストオブジェクトが入ったリストです。


リストの扱いについては、こちらを確認してみてください。

 → Manipulating Lists of Items


テキストの扱いについては、こちらが詳しいと思います。

 → Manipulating Text


Web Pageのソースコードから、特定のクラスを取り出す方法は可能ですが、Safari.appを開かなくてはならず、ページの読み込みが終わるのを確認する処理も必要で、複雑で処理の時間も長くなりそうです。 また、著作権の問題もありますので、やらないほうがいいのではないでしょうか?

2018/01/11 12:30 Akeera への返信

選択した文字をGoo辞書で検索する、というApplescriptを公開しておられる方がいました

http://blog.goo.ne.jp/vallie/e/80e09d09c0162d7178b539ab906974e9


(Numbersのセルから英単語の文字列を取得)

検索

(検索結果から、和訳部分を抜き出し、Numbersに戻す)


Numbersとの文字列の受け渡しをAutomatorでやればいいのでしょうか

2018/01/13 11:18 T22T への返信

ありがとうございます!!


1)サイトは、定義がシンプルな三省堂を使いたいです

http://www.sanseido.biz/User/Dic/Index.aspx?TWords=&st=0&DORDER=161517&DailyEJ=checkbox


2)ご教授ありがとうございます。試してみました。

1000単語あるので、このままでは難しいですが、便利ですね!


3)スクリプト、全くの素人ですが、少し格闘してます

2018/01/12 22:59 Akeera への返信

失礼致します。 三省堂のWeb Dictionaryのサイトをみてみたのですが、『Goo辞書で検索する』の方法と似ているようです。


preacherという単語を、デイリーコンサイス英和辞典を使って前方一致で検索する場合は、以下のURLなるようです。


http://www.sanseido.biz/User/Dic/Index.aspx?TWords=preacher&st=0&DORDER=&DailyEJ=checkbox


TWRods=の部分が検索語、st=0が前方一致、DailyEJ=checkboxで辞書を指定しているみたいです(おそらく)。


このURLをAutomator.appの『Webページからテキストを取得』のアクションのインプットとして入力してやると、検索結果を含むテキストを得ることができます。 このテキストから必要な情報を取り出して、Numbers.appに渡すことができそうです。 但し、テキストの最後に、


『このホームページの内容の一部または全部を無断で複製、転載することを禁じます。』


とあるので、著作権の問題に引っかかりそうです。 

2018/01/13 09:58 Akeera への返信

Automator.appのワークフロー(『Webページからテキストを取得』アクションのみ)をデスクトップに保存した場合、それを使って三省堂のWeb Dictionaryのサイトから定義を得るAppleSriptは以下になります。


property wordList : {"preacher", "wisdom", "Recognition"}

property definitionList : {}

property workflowPath : "~/Desktop/GetTextFromWebPage.workflow"


repeat with theWord in wordList

set theURL to "http://www.sanseido.biz/User/Dic/Index.aspx?TWords=" & theWord & "&st=0&DORDER=&DailyEJ=checkbox"

set theScript to "automator -i \"" & theURL & "\" " & workflowPath

set str to (do shell scripttheScript)

set definitionList to definitionList & str

end repeat


definitionList

2018/01/13 11:41 Akeera への返信

重ねて質問すみません。


教えていただいたテキスト取り出しはわからなかったのですが、

ブラウザのクラスを指定して情報を取り出す、という方法がありました。


to getInputByClass(theClass, num) -- defines a function with two inputs, theClass and num

tell application "Safari" --tells AS that we are going to use Safari

set input to do JavaScript "

document.getElementsByClassName('" & theClass & "')[" & num & "].innerHTML;" indocument 1 -- uses JavaScript to set the variable input to the information we want

end tell

return input--tells the function to return the value of the variable input

end getInputByClass

http://www.cubemg.com/how-to-extract-information-from-a-website-using-applescript/


三省堂のページだと、和訳部分のクラスがdiv class="NetDicBody"らしいです。

教えていただいたスクリプトを

この方法に改変する方法を教えたいただけないでしょうか?


何卒よろしくお願いいたします。




tell front document of application "Numbers"

tell active sheet

set theTable to first table whose class of selection range is range

tell theTable

set wordList to value of cells of selection range

end tell

end tell

end tell


property wordList : {"preacher", "wisdom", "Recognition"}

property definitionList : {}

property workflowPath : "~/Desktop/GetTextFromWebPage.workflow"


repeat with theWord in wordList

set theURL to "http://www.sanseido.biz/User/Dic/Index.aspx?TWords=" & theWord & "&st=0&DORDER=&DailyEJ=checkbox"

set theScript to "automator -i \"" & theURL & "\" " & workflowPath

set str to (do shell scripttheScript)

set definitionList to definitionList & str

end repeat


definitionList

2018/01/13 12:06 Akeera への返信

すみません。

クラスを指定するやり方だと、Webページからテキストを取得』アクションが使えなそうですね。。


テキストを抜き出すやり方だと、教えて頂いたページの以下のスクリプトをどう書き換えたらいいのでしょうか?

先のスクリプトで取得した、'definitionList'の変数をどこかに入れれば良さそう、、とまではわかるのですが。。


on trimText(theText, theCharactersToTrim, theTrimDirection)

set theTrimLength to length of theCharactersToTrim

if theTrimDirection is in {"beginning", "both"} then

repeat while theText begins with theCharactersToTrim

try

set theText to characters (theTrimLength + 1) thru -1 of theText as string

on error


-- text contains nothing but trim characters

return ""

end try

end repeat

end if

if theTrimDirection is in {"end", "both"} then

repeat while theText ends with theCharactersToTrim

try

set theText to characters 1 thru -(theTrimLength + 1) of theText as string

on error


-- text contains nothing but trim characters

return ""

end try

end repeat

end if

return theText

end trimText

2018/01/13 11:27 T22T への返信

T22T様


本当にありがとうございます!

なんとお礼を言っていいやら。。


教えたいただいたスクリプトを実行したところ、

和訳を取り出すことができました。


Kindleで調べた英単語を、リストにして取り出したのですが

たくさんの単語に和訳をつけるので途方に暮れていました。

Numbersで辞書検索

Apple サポートコミュニティへようこそ
Apple ユーザ同士でお使いの製品について助け合うフォーラムです。Apple ID を使ってご参加ください。