http://ja.wikipedia.org/wiki/Dashcode
下記のことが記載されています。
“Widget Basics” introduces the Dashboard environment and describes how to develop a simple widget.
document.getElementById("YourTextId").innerText = "New Value";
“Designing Widgets” provides guidelines and tips for designing successful widgets.
“Introduction to the Apple Classes” discusses the Apple Classes, what they offer, and how to include them in your widget.
スクロールエリアとか、ボタンとかの話で下記に細かく記載されているので下記参照
“Using Scroll Areas” talks about integrating a scroll area into your widget.
極力使わないようにという
“Using an Apple Slider” tells you how to use a slider control in your widget.
“Using Animation” discusses using the animation-focused Apple Classes.
“Using an Apple Button” talks about using the AppleButton? class to build your own buttons, and how to use the AppleGlassButton? subclass for standard-style buttons.
<script type='text/javascript' src='/System/Library/WidgetResources/AppleClasses/AppleButton.js' charset='utf-8'/>
昔のバージョンでは上記のコードを下記のようにかくんだってさ
<script type='text/javascript' src='AppleClasses/AppleButton.js' charset='utf-8'/>
<body onload="setup();"> ... <div id="myButton"></div> ... </body>
#myButton { position: absolute; right: 20px; bottom: 20px; }
AppleButton( buttonElement, label, height, leftImage, leftImageDown, leftImageWidth, middleImage, middleImageDown, rightImage, rightImageDown, rightImageWidth, onclick );
var gMyButton; function setup() { gMyButton = new AppleButton( document.getElementById("myButton"), "Click Me", 23, "button/buttonLeft.png", "button/buttonLeftDown.png", 11, "button/buttonMiddle.png", "button/buttonMiddleDown.png", "button/buttonRight.png", "button/buttonRightDown.png", 11, buttonClicked); }
gMyButton.onclick
gMyButton.setDisabledImages( leftImageDisabled, middleImageDisabled, rightImageDisabled)
gMyButton.enabled
gMyButton.setEnabled(boolean)
gMyButton.remove()
gMyButton.textElement
“Widget Backs and Preferences” tells you how to display, save, and retrieve preferences. AppleInfoButton?, used on a widget's front to signify that a widget has a back. When clicked, it flips the widget over.
“Syncing Widgets” looks at the Dashboard Sync feature in Mac OS X v.10.5 and how you can handle syncing in your widget.
“Using Widget Events” discusses Dashboard and widget events that your widget may want to be aware of. http://developer.apple.com/library/safari/#documentation/AppleApplications/Conceptual/Dashboard_ProgTopics/Articles/Events.html%23//apple_ref/doc/uid/TP40003044-SW1
“Declaring Control Regions” defines and explains how to work with control regions, areas where controls are present in a widget.
“Resizing Widgets” provides code useful for implementing resizing in your widget.
Using the Canvas talks about using the Canvas feature of WebKit? within your widget.
Using the Pasteboard from JavaScript? talks about supporting copy, cut, and paste in a widget.
Using Drag and Drop From JavaScript? tells you about the handlers needed to support drag and drop in your widget.
“Localizing Widgets” discusses offering your widget with international users in mind, using localizable strings and other resources. [#y77fd738]
“Specifying Access Keys” describes the widget access keys, used to turn on resource access for your widget.
“Accessing External Resources” talks about opening applications or web pages in a browser with your widget.
これをやるまえに、アクセスキーでコマンドラインを使えるようにするかどうか設定が必要
AllowSystem?ってのがBoolean型であるからそれをなんとかするらしいんだけど、 Dashcoadの設定画面で設定するところあったよ。えーっと、開発エディタ画面の左の真ん中あたりに、「ウィジェットの属性」ってのがあるとおもう。
それをクリックして、「コマンドラインアクセスを許可」にチェックをいれときゃなんとかなるんじゃないかな。
パラメータは2つあって、1つ目は、フルパスのコマンドとその引数
例:"/bin/ls -l -a"
例:"cd ~;"
2つめはハンドラで、同期、非同期の切り替えに使うらしく引数をもたせなきゃならないみたいだ。
例:systemHandler これをnullにすると、同期モードになるっぽい
標準出力
var output = widget.system("id -un", null).outputString;
標準エラー
var error = widget.system("id -un", null).errorString;
コマンド状態
var status = widget.system("id -un", null).status;
var myCommand = widget.system("/sbin/ping foo.bar", endHandler); myCommand.onreadoutput = outputHandler;
または、下記の書き方
widget.system("/sbin/ping foo.bar", endHandler).onreadoutput = outputHandler;
で、ハンドラーは引数を絶対とるようにします。
function outputHandler(currentStringOnStdout){ // Code that does something with the command’s current output like... document.getElementById("element").innerText = currentStringOnStdout;}
myCommand.cancel();
myCommand.write("8*5");
myCommand.close();
下記のサイトからダウンロードできるコードを見ていきましょう。
上記のプログラムが起動すると、下記のコードが実行されます。
function setup() { if(window.widget) { currentlyBeingSpoken = widget.system("/usr/bin/osascript -e 'say \"Welcome to Voices!\" using \"Fred\"'" , doneSpeaking); } }
コマンドが終わったら、doneSpeakingと定義した関数が呼ばれます。
しゃべり終わればcurrentlyBeingSpoken?にはnull がはいります。
上記のサンプルのつづきです。ユーザが入力するフェーズです。
if(window.widget) { if(currentlyBeingSpoken != null) { currentlyBeingSpoken.cancel(); } currentlyBeingSpoken = widget.system("/usr/bin/osascript -e 'say \"" + textToSpeak + "\" using \"" + chosenVoice + "\"'" , done); }
しゃべっているかどうか、かぶらないようにしているのがわかります。かぶりそうになると、キャンセルをしています。
音声を切り替えるとしゃべる箇所です。
function voiceChanged(elem) { var chosenVoice = elem.options[elem.selectedIndex].value; document.getElementById("voiceMenuText").innerText = chosenVoice; if(window.widget) { if(currentlyBeingSpoken != null) { currentlyBeingSpoken.cancel(); done(); } currentlyBeingSpoken = widget.system( "/usr/bin/osascript -e 'say \"Hi, I`m " + chosenVoice + ".\" using \"" + chosenVoice + "\"'" , doneSpeaking ); } }
function myonclick(event) { var output = widget.system("/bin/ls -l -a", null).outputString; //alert(output); document.getElementById("textarea").innerText = output; }
画面にコマンド用のテキストを貼付け、出力用のテキストエリアを貼付けて それぞれ、下記のコードにあうように名前をつけた例です。
function doCommand(event) { var inputField = document.getElementById("cmdInput"); var outputArea = document.getElementById("cmdOutput"); var cmd = widget.system("cd ~;" + inputField.value, null); outputArea.value = cmd.outputString; }
“Accessing Command Line Utilities” tells you how to access command-line utilities and scripts from within your widget.
“Creating a Widget Plug-in” discusses native code plug-ins that your widget uses to interact with other applications.
- (id) initWithWebView:(WebView*)webview
- (void) windowScriptObjectAvailable:(WebScriptObject *)windowScriptObject
- (void) windowScriptObjectAvailable:(WebScriptObject *) windowScriptObject { [windowScriptObject setValue:self forKey:@"MyWindowScriptObject"]; ... }
<html> <head> ... <script> ... function someFunction() { ... if (MyWindowScriptObject) { MyWindowScriptObject.someMethod(someArg); } ... } ... </script> </head> ... </html>
Info.plistをあつかうファイルで
NSPrincipalClass? が担当しているようです。
<html> ... <body onload='MyWindowScriptObject.someMethod(someArg)'> ... </body> </html>
Using Objective-C From JavaScript? provides more detail on bridging Objective-C and JavaScript?.
“Delivering Widgets” tells you about packaging and distributing your widget.
そのまま保存しても下記のようなエラーに見舞われる
TypeError: Result of expression 'widget.system' [undefined] is not a function.
開発環境では動作するのに、理由がわからない。
そのご、試してみると、最初からサンプル道理に入力すると、うまく行くが、 どこかの手順を間違えると復活できないようだ。 間違えたら、プロジェクトを入れ替えるしかないのかどうかは、よくわからない。
http://uchyax.exblog.jp/5443700/
http://uchyax.exblog.jp/5359765/
http://uchyax.exblog.jp/5375242/
いろいろダウンロードできる
http://www.dstation.net/modules/mydownloads/
http://www.ie.u-ryukyu.ac.jp/~e035740/nakamurasoba/40/index.html
http://www.apple.com/jp/macosx/features/dashboard/
http://www.apple.com/jp/downloads/dashboard/
http://www.apple.com/downloads/macosx/dashboard/
http://www.dashboardwidgets.com/
http://dpsmac.com/category/dashboard/ http://www.dashboard.jp/
http://www.geocities.jp/widget_mania/
・類似・関連ソフト Yahoo! Widgets(旧 Konfabulator) ttp://widgets.yahoo.com/ Adobe Apollo(Flash や WebKit? を用いたデスクトップアプリ環境) ttp://labs.adobe.com/technologies/apollo/ Amnesty Widget Browser(Panther でも Dashboard) ttp://amnesty.mesadynamics.com/WidgetBrowser?.html
・Mac Dashboard wiki(Dashboard の情報を共有/過去ログ等) http://www2.atwiki.jp/macstar/