目次

Dashcodeとは

http://ja.wikipedia.org/wiki/Dashcode

ユーザガイド

http://developer.apple.com/library/safari/#documentation/AppleApplications/Conceptual/Dashcode_UserGuide/Contents/Resources/en.lproj/Introduction/Introduction.html

リファレンス

http://developer.apple.com/library/safari/#documentation/AppleApplications/Reference/Dashboard_Ref/DashboardRef/DashboardRef.html%23//apple_ref/doc/uid/TP40001339

下記のことが記載されています。

ハローワールドと、最小限のプロジェクト構成、XML定義の記述例

“Widget Basics” introduces the Dashboard environment and describes how to develop a simple widget.

http://developer.apple.com/library/safari/#documentation/AppleApplications/Conceptual/Dashboard_ProgTopics/Articles/WidgetBasics.html%23//apple_ref/doc/uid/TP40008117-SW2

ラベル文字のかえ方

document.getElementById("YourTextId").innerText = "New Value";

開発指針

“Designing Widgets” provides guidelines and tips for designing successful widgets.

http://developer.apple.com/library/safari/#documentation/AppleApplications/Conceptual/Dashboard_ProgTopics/Articles/Design.html%23//apple_ref/doc/uid/TP40003053-SW3

AppleClass?と呼ばれる標準部品について

“Introduction to the Apple Classes” discusses the Apple Classes, what they offer, and how to include them in your widget.

スクロールエリアとか、ボタンとかの話で下記に細かく記載されているので下記参照

http://developer.apple.com/library/safari/#documentation/AppleApplications/Conceptual/Dashboard_ProgTopics/Articles/AppleClasses.html%23//apple_ref/doc/uid/TP40003186-SW1

スクロールエリア

“Using Scroll Areas” talks about integrating a scroll area into your widget.

極力使わないようにという

http://developer.apple.com/library/safari/#documentation/AppleApplications/Conceptual/Dashboard_ProgTopics/Articles/AppleScrollArea.html%23//apple_ref/doc/uid/TP40003241-SW2

スライダー

“Using an Apple Slider” tells you how to use a slider control in your widget.

http://developer.apple.com/library/safari/#documentation/AppleApplications/Conceptual/Dashboard_ProgTopics/Articles/AppleSlider.html%23//apple_ref/doc/uid/TP40003242-SW2

アニメーション

“Using Animation” discusses using the animation-focused Apple Classes.

http://developer.apple.com/library/safari/#documentation/AppleApplications/Conceptual/Dashboard_ProgTopics/Articles/AppleAnimator.html%23//apple_ref/doc/uid/TP40003187-SW1

ボタン

“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.

http://developer.apple.com/library/safari/#documentation/AppleApplications/Conceptual/Dashboard_ProgTopics/Articles/AppleButton.html%23//apple_ref/doc/uid/TP40003185-SW5

書き方 HTML

<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'/>

ボタンIDと初期化メソッド名を記入する方法

<body onload="setup();">
   ...
   <div id="myButton"></div>
   ...
</body>

CSSで座標を決めます。

#myButton {
   position: absolute;
   right: 20px;
   bottom: 20px;
}

初期化用のJavascript基本文

AppleButton(
   buttonElement,
   label,
   height,
   leftImage,
   leftImageDown,
   leftImageWidth,
   middleImage,
   middleImageDown,
   rightImage,
   rightImageDown,
   rightImageWidth,
   onclick
);

初期化用のJavascript例

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);
}

AppleButton? オブジェクトのプロパティやメソッド

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.

http://developer.apple.com/library/safari/#documentation/AppleApplications/Conceptual/Dashboard_ProgTopics/Articles/Preferences.html%23//apple_ref/doc/uid/TP40003043-SW3

2台マック持ってたときに、同期するメカニズムがあるらしいので、その説明っぽい。

“Syncing Widgets” looks at the Dashboard Sync feature in Mac OS X v.10.5 and how you can handle syncing in your widget.

http://developer.apple.com/library/safari/#documentation/AppleApplications/Conceptual/Dashboard_ProgTopics/Articles/SyncingWidgets.html%23//apple_ref/doc/uid/TP40004748-SW1

マウスクリックなどイベントの使い方

“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.

http://developer.apple.com/library/safari/#documentation/AppleApplications/Conceptual/Dashboard_ProgTopics/Articles/ControlRegions.html%23//apple_ref/doc/uid/TP40003045-SW3

リサイズ方法

“Resizing Widgets” provides code useful for implementing resizing in your widget.

http://developer.apple.com/library/safari/#documentation/AppleApplications/Conceptual/Dashboard_ProgTopics/Articles/Resizing.html%23//apple_ref/doc/uid/TP40003046-SW1

キャンバスの使い方

http://developer.apple.com/library/safari/#documentation/AppleApplications/Conceptual/Dashboard_ProgTopics/Canvas.html%23//apple_ref/doc/uid/30001236-BAJGJJAH

Using the Canvas talks about using the Canvas feature of WebKit? within your widget.

カットアンドペースト

http://developer.apple.com/library/safari/#documentation/AppleApplications/Conceptual/Dashboard_ProgTopics/CopyAndPaste.html%23//apple_ref/doc/uid/30001234-BAJGJJAH

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.

http://developer.apple.com/library/safari/#documentation/AppleApplications/Conceptual/Dashboard_ProgTopics/DragAndDrop.html%23//apple_ref/doc/uid/30001233-BAJGJJAH

国際化

http://developer.apple.com/library/safari/#documentation/AppleApplications/Conceptual/Dashboard_ProgTopics/Articles/Localization.html%23//apple_ref/doc/uid/TP40003047-SW2

“Localizing Widgets” discusses offering your widget with international users in mind, using localizable strings and other resources. [#y77fd738]

アクセスキー(機能をつかうかどうか)の指定方法

http://developer.apple.com/library/safari/#documentation/AppleApplications/Conceptual/Dashboard_ProgTopics/Articles/AccessKeys.html%23//apple_ref/doc/uid/TP40003048-SW2

“Specifying Access Keys” describes the widget access keys, used to turn on resource access for your widget.

外部リソースにアクセス

http://developer.apple.com/library/safari/#documentation/AppleApplications/Conceptual/Dashboard_ProgTopics/Articles/ExternalAccess.html%23//apple_ref/doc/uid/TP40003049-SW1

“Accessing External Resources” talks about opening applications or web pages in a browser with your widget.

コマンドラインツールにアクセス

これをやるまえに、アクセスキーでコマンドラインを使えるようにするかどうか設定が必要

AllowSystem?ってのがBoolean型であるからそれをなんとかするらしいんだけど、 Dashcoadの設定画面で設定するところあったよ。えーっと、開発エディタ画面の左の真ん中あたりに、「ウィジェットの属性」ってのがあるとおもう。

それをクリックして、「コマンドラインアクセスを許可」にチェックをいれときゃなんとかなるんじゃないかな。

widget.system()

パラメータは2つあって、1つ目は、フルパスのコマンドとその引数

例:"/bin/ls -l -a"

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();

サンプルコード リソースを後から使うプロセスが優先して使う例

下記のサイトからダウンロードできるコードを見ていきましょう。

http://developer.apple.com/library/safari/#samplecode/Voices/Introduction/Intro.html%23//apple_ref/doc/uid/DTS10003699

上記のプログラムが起動すると、下記のコードが実行されます。

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;

}

“Accessing Command Line Utilities” tells you how to access command-line utilities and scripts from within your widget.

http://developer.apple.com/library/safari/#documentation/AppleApplications/Conceptual/Dashboard_ProgTopics/Articles/CommandLine.html%23//apple_ref/doc/uid/TP40003050-SW1

プラグインの作り方

“Creating a Widget Plug-in” discusses native code plug-ins that your widget uses to interact with other applications.

http://developer.apple.com/library/safari/#documentation/AppleApplications/Conceptual/Dashboard_ProgTopics/Articles/WidgetPlugin.html%23//apple_ref/doc/uid/TP40003051-SW1

全てのプラグインが実装しなくてはならないコード

- (id) initWithWebView:(WebView*)webview

- (void) windowScriptObjectAvailable:(WebScriptObject *)windowScriptObject
- (void) windowScriptObjectAvailable:(WebScriptObject *) windowScriptObject
{
   [windowScriptObject setValue:self forKey:@"MyWindowScriptObject"];
   ...
}

WebScriptObject?オブジェクトをプラグインから受け取る例

<html>
<head>
... 
<script>
...
function someFunction()
{
   ...
   if (MyWindowScriptObject)
   {
       MyWindowScriptObject.someMethod(someArg);
   }
   ...
}
...
</script> 
</head>
...
</html>

XCodeの標準的なプロパティ管理ファイル

Info.plistをあつかうファイルで

NSPrincipalClass? が担当しているようです。

ロード後に処理を走らせる方法

<html>
...
<body onload='MyWindowScriptObject.someMethod(someArg)'>
...
</body>
</html>

Objective-Cを呼び出す方法

Using Objective-C From JavaScript? provides more detail on bridging Objective-C and JavaScript?.

http://developer.apple.com/library/safari/#documentation/AppleApplications/Conceptual/Dashboard_ProgTopics/ObjCFromJavaScript.html%23//apple_ref/doc/uid/30001215-BBCBFJCD

作品のパッケージ方法

“Delivering Widgets” tells you about packaging and distributing your widget.

http://developer.apple.com/library/safari/#documentation/AppleApplications/Conceptual/Dashboard_ProgTopics/Articles/Delivery.html%23//apple_ref/doc/uid/TP40003052-SW1

そのまま保存しても下記のようなエラーに見舞われる

TypeError: Result of expression 'widget.system' [undefined] is not a function.

開発環境では動作するのに、理由がわからない。

Dashcode のwiki

http://f16.aaa.livedoor.jp/~pseuho/Newt/pukiwiki.php/?Dashboard%2FDashboard%A5%D7%A5%ED%A5%B0%A5%E9%A5%DF%A5%F3%A5%B0%A5%AC%A5%A4%A5%C9

Dashcodeでプログラミング(ネットワーク上のファイルにアクセスする)

http://uchyax.exblog.jp/5443700/

デバッカの使い方

http://uchyax.exblog.jp/5359765/

http://uchyax.exblog.jp/5375242/

Dashboard Station

いろいろダウンロードできる

http://www.dstation.net/modules/mydownloads/

Widgetをつかっていろいろ実験しているサイト

http://www.ie.u-ryukyu.ac.jp/~e035740/nakamurasoba/40/index.html

トップ   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS