脳みその中身

Inside of My Brain

FileMaker で Google Apps (Gmail) の PermanentLink を取得するカスタム関数

自分用に、Google Apps の個々のメールの PermanentLink を取得する FileMaker の カスタム関数を作りました。

理屈は、別記事:Google Apps (Gmail) で PermanentLink を取得する方法 の通りです。

____________________
GetGmailURL ( webviewerObjectName ; shvaOption )
____________________

// Created: 2011/02/15
// by bison
//
// Parameter:
//  webviewerObjectName : Webビューアのオブジェクト名
//  shvaOption : 0 の場合 shvaパラメータを省略します。
//   1 もしくは 空値 ( "" ) の場合は ?shva=1 を付けます。
// Explanation:
//  GMail (Google Apps) の個別メッセージURLの場合、
//  個々のメッセージのパーマネントURL を返します。
//  それ以外の場合、当該Webビューアで表示中のURLを返します。
/////////////////
Let (
[
$myurl = GetLayoutObjectAttribute ( webviewerObjectName ; "source" ) ;
$gmailJudgeText = "https://mail.google.com/mail/" ;
$startPos = Length ( $gmailJudgeText ) ;
$gmailFlag = Left ( $myurl ; $startPos ) = $gmailJudgeText ;
$spos = Position ( $myurl ; "/" ; 1 ; PatternCount ( $myurl ; "/" ) ) // Position of last slash
] ;

Case ( $gmailFlag ;
	Replace ( $myurl ; $startPos ; $spos - $startPos ;
	Case ( shvaOption = 0 or IsEmpty ( shvaOption ) ; "/#all" ;
	"/?shva=1/#all" ) )
	; $myurl ) // Case
)

____________________

※ shvaOption については、
Gmail’s SHVA Parameter
Gmailで日本語を検索した際の不具合
あたりを参照してください。

FileMaker Dictionary 関数

FileMaker Dictionary Functions
以下の blockquote部分は上記出典ページの段落、直後の日本語は内容の拙訳です。
拙訳への具体的な「ちげーよバカ!」な突っ込みは大歓迎です。
※ 万一のトラブルは、出典サイトはもちろん、(たとえそれが僕の拙訳のせいだとしても) 一切関知しませんのであしからず。

素晴らしいカスタム関数を発表してくれた sixfriedrice.com の Jesse Antunes / Geoff Coffey に感謝します。


Since many people were impressed with my named parameters article, I decided to write up another post about the dictionary functions. Actually in all fairness I think three people actually liked it. Vincenzo Menanno, Chris Wack and Sam Barnum this post’s for you!

“named parameters (名前付きパラメータ)” 記事 への皆さんの食いつきがなかなかにすばらしいので、”the Dictionary functions” についての別の post を書くことにしました。
まあ、公平にみて、3人の人たちがこれを気に入ってくれると考えています。
Vincenzo Menanno, Chris Wack and Sam Barnum この post は君たち向けです!

Note: This article was revised November 23, 2007. I added the handyDictReplace function. -Geoff

Note: この記事は、2007/11/23 に改訂しました。
重宝な DictReplace 関数を付け足しました。 – Geoff

First I must warn you, I have left the names of the custom functions the same as the functions we use internally. This means they may seem a little obtuse so feel free to change them. I’m also not getting to in-depth into how they actually work because it could take an extra 5 pages or so (yea I know Geoff… I’m lazy… deal with it). I’m sure most of you will get them pretty quickly despite my inept explanations. Oh yea, I also suggest going back and reading the named parameters post before getting into this post otherwise it probably won’t make much sense.

Enjoy…

まず、最初の注意として…
内部的に使っているカスタム関数の名前はそのまま残しました。
ちょこっとダサイかも知れませんので、自由に変更してください。
それに、どのように振る舞うかの詳細についてまでは触れていません。
そこまでやると、簡単にもう5ページくらいかかってしまうので…はいはい面倒くさがりでごめんね。
ほとんどの方は、私のダサダサな説明などいらないくらいにサクっとおわかりになるでしょうし。
そうそう、 以前に post した “named parameters” の記事についても読んでいただいておいた方がよろしいでしょう。
じゃないと、あんまわからない話になってしまうかも。

楽しんでください…

Note: For the duration of this article I will refer to the custom functionPassParameter( name ; value ) in my previous post as #( ). This saves me 12 key strokes and won’t confuse me because that’s what I call it internally.

Note; 以前 “PassParameter ( name ; value )” として紹介したカスタム関数を#( )としています。こいつのおかげで、12キーストローク楽になりましたし、関数の内部で使っているので別に自分は混乱しないです。( bison 注:2011/02/12 21:09:18 修正しますた。by 今泉さんのありがたいツッコミ)

Using a Dictionary in the Script Result

スクリプト結果で、Dictionary を使う

I actually posted this in the comments of the Named Parameters post. The idea here is that you can not only use the named parameter idea in your script parameters but in your script results as well. So just place your dictionary values in the script result dialog of the Exit Script script step and you’ve go yourself named script results. I like to create a little shortcut to access them like so:

さて、これについては、”Named Parameters” の記事のコメントで post しました。
このアイデアがここで意味するものは…
named parameter のアイデアは、スクリプトパラメータだけでなく、スクリプト結果でも同様に使えるんだよ…ということです。
ですから、スクリプト終了のスクリプトステップの スクリプト結果のダイアログに、あなたの dictionary の値を置いたものをスクリプト結果と名付けて処理を進めれるわけです。
私は、以下のようなちょっとしたショートカットを作るのが好きです;

Name: #R ( name )

Definition:

DictGet ( Get (ScriptResult) ; name )

Checking for a Name in the Dictionary

Dictionary の中の名前をチェックする

There’s also a point where you may want to check if your dictionary contains a certain value. You could do this by simple using your DictGet() custom function on your Dict. By design, a call to the DictGet() will return empty if the name you are looking for isn’t there. That’s when I made DictContains?

また、「特定の値が あなたの dictionary の中に含まれているかどうか」をチェックしたいときもあるでしょう。
これは、シンプルに あなたの Dect について、DictGet ( ) カスタム関数を使うことで可能です。仕組みとして、あなたが探しているものがそこに無ければ、DictGet ( ) をコールすると、空値が返ります。
それで、DictContains? を作ったのです。

Name: DictContains? ( dict, name )

Definition
Let (
 pattern = "<:" & name & ":=";  Position(dict; pattern; 1; 1) > 0
)

All this is doing is checking the dictionary structure for the name of the value you are looking for and returning true if it finds the value and false if it doesn’t.

これが行うことのすべては、あなたが探している値の名前で、dictionary 構造 をチェックして、存在すれば true を返し、存在しなければ false を返すということです。

Note: This will not find any nested dictionary values. So if you were to store a dictionary within a dictionary ie. #( “Account” ; #( “Name” ; “Jesse” ) & #( “Job” ; “Writing confusing custom functions” ) ) you wouldn’t be able to use the DictContains? custom function to see if Job is in the dictionary because it is inside the account dictionary.

Note: 入れ子になった distionary の値は見つけられません。
ですから譬えば…
#( “Account” ; #( “Name” ; “Jesse” ) & #( “Job” ; “Writing confusing custom functions” ) )
といった dictrionary において、”Job” が dictionary にあるかどうかをチェックするのに
DictContains? を使うことはできません。
なぜなら、”Job” は、Account dictionary の内部に存在するからです。

Removing an Entry from a Dictionary

Dictionary から エントリを削除する

You never know when, but there will be a point where you think… “Man, I wish I could remove a value from my dictionary.” Well, maybe you won’t… but I wrote this thing anyway. If you happen to bump into this situation, you can use the nifty function below. DictRemove() simply removes the dictionary name/value pair specified from the dictionary passed in.

いつとは言えませんが、こう考えることもあるでしょう。
「なあ、オイラの dictionary の中から値を削除したいんだけど…」
…まあ、ないかもしれませんが…とにかくそれについて書きました。
もし、ばったり、そんな状況に出くわしたなら、下記の気の利いた関数を使うことができます。
DictRemove ( ) は、特定の name/value のペアを、受け渡された dictionary からシンプルに削除します。

Name: DictRemove ( dict , name )

Definition:

Let(
[
 pattern = "<:" & name & ":=";  entry_start = Position( dict ; pattern ; 1 ; 1);  entry_end = Position( dict ; ":>" ; entry_start + 1; 1);
 dict_beginning = If( entry_start > 0 ; Left ( dict ; entry_start - 1 ) );
 rest_of_dict = Middle( dict ; entry_end + 2 ; 999999 );
 new_dict = dict_beginning & rest_of_dict
];

If( entry_start > 0 ; new_dict ; dict )
)

Replacing an Entry in a Dictionary

Dictionary のエントリを置換する

This function is primarily for convenience. It combines DictRemove with a new entry to effectively replace a value in the dictionary in one shot:

この関数は、やたら便利だったらありゃしません。
DictRemove と新エントリを結合して、一発で dictionary 中の値を効果的に置き換えます。

Name: DictReplace ( dict, name, value )

DictRemove(dict, name) & #(name, value)

Returning the Top Name in a Dictionary

Dictionary 中の Top Name を返す

This custom function was designed to return the name of the first name-value pair in the dictionary. Nothing too special, but I if used in conjunction with the DictRemove() function above, you can pop off the top value of the dictionary with ease.

このカスタム関数は、dictionary 中の 最初の name/value のペアの name を返します。
特別なことは何もしていませんが、上記の DictRemove ( ) 関数と連携させて使うと、簡単に、最初の値を消すことができます。

Name: DictFirst( dict )

Definition:

Let(
   [startValue = "<:";    endValue = ":=";    positionOfStartValue= Position( dict ; startValue ; 1 ; 1 );    endOfStartValue= If( positionOfStartValue > 0 ; positionOfStartValue  + Length(startvalue); -1 );
   beginningOfEndValue= Position( dict; endValue; endOfStartValue; 1 );
   found = If( beginningOfEndValue > -1 and endOfStartValue > -1 ; True; False );
   lengthFoundValue = beginningOfEndValue - endOfStartValue;
   foundValue = Middle( dict; endOfStartValue ; lengthFoundValue )];

   If( found ; foundValue ; "" )
)

Adding to a Dictionary

Dictionary に追加する

This custom function is ridiculously easy. It’s really just a shortcut that looks a little more succinct then actually performing the action manually.

このカスタム関数は、バカほど簡単です。
実際に手動で行うよりほんの少し簡潔にしたショートカットです。

Name:DictAdd( dict; name; value )

Definition:

 dict & #( name ; value )

Dictionary To String

Dictionaryを文字列に

This is quite frankly my favorite custom function ever. Serioulsy, I have a ton of ridiculous functions that no one uses but me, but this is the creme de la creme. I’ll get slightly more indepth about this function because it can be a little tricky to understand. Here is the signature of the function:

これは、実際率直に言って、お気に入りのカスタム関数です。
マジに、自分以外だれが使うねん…な関数を山ほど使っていますが、こいつは、最高です。
ただ理解するのにちょこっとトリッキーかも知れないので、やや詳細に言及します。
これがこの関数の書式です。

Name: DictToString
Parameters:
Dict: A dictionary of your choosing
Format: format you would like to display the data in.

The real magic of this function comes from the Format parameter. This parameter will dictate how you want the data displayed. The function goes through each and every dictionary entry and will put it into whichever format you specific. To achieve this functionality a replace is performed on the Format. $name is replaced with the name of the dictionary entry and $value is replaced with the value of the dictionary entry. Here is the function:

この関数のキモは、Format parameter です。
このパラメータには、「どのようにデータを表示させたいか」を記述します。
この関数は、個々の dictionary エントリに対して実行され、あなたの指定したフォーマットに仕上げます。
$name は、dictionary エントリの name と、$value は、value と置き換えられます。
以下がその関数です。

Name: DictToString( Dict ; Format )

Definition:

 Let(
  [
  firstName  = DictFirst ( dict );
  rawdata = DictGet(dict; firstName) ;
  data = If( not IsEmpty( DictFirst( rawdata ) ) ; DictToString( rawdata ; Format ); rawdata );
  rest = DictRemove( dict ; firstName )

   ];
    If( not IsEmpty(firstName) ;
   Substitute(
                format;
                ["$name"; firstName  ];
                ["$value"; data ]
               )
               &
           If (
                not IsEmpty(rest);
                DictToString(rest; Format)
              )
 ; dict )
)

Let’s say your Format parameter is:
たとえば、あなたのフォーマットパラメータが以下のようだったとします。

`"$name is $value"`

and your dictionary is

そして、あなたの dictionary がこうだったとします。

`<:Jesse:=nuts:>`

the output would be

すると、出力はこうなります。

`Jesse is Nuts`

You can now basically output your dictionaries in any format you so desire. Such as…. you guessed it…. XML.

基本的に、どんなフォーマットにでも思いのままに、あなたの dictionary を出力できます。
たとえば…考えてみそ…XMLとか…

Dictionary To XML

Dictionary を XML に

So once you understand the DictToString() custom function, the DictToXML() function is just a shortcut that I wrote so I don’t have to write the funky format over and over. Here is is:

さて、DictToString ( ) を理解したところで、DictToXML ( ) 関数は、
なんども繰り返し土臭いフォーマットを書かずにすむように作った
単なるショートカットです。
それはこうです。

Name: DictToXML ( dict )

Definition:

DictToString ( dict , "<$name>$value<$name>" )

Let’s say you setup your dictionary like so #( “account” ; #( “name” ; “Jesse” ) & #( “birthday” ; “Yesterday” ) ). You’ll notice that I have put a pair of dictionaries within another dictionary named account. The DictToXML function (really the DictToString() function does the bulk of the work but you get the point) will actually iterate through the outside and inside dictionary and output the following:

さて、あなたの dictionary を

#( “account” ; #( “name” ; “Jesse” ) & #( “birthday” ; “Yesterday” ) )

と設定したとします。
ふたつの dictionary をアカウントという名前のもうひとつの dictionaryに入れたことがわかりますね。
DictToXML 関数 (ほとんどの機能を DictToString ( ) 関数が行うわけではありますが) は、外側と内側の dictionary を行ったり来たりして、以下を出力します。

<account>
<name>Jesse</name>
<birthday>Yesterday</birthday>
</account>

This can be very useful for creating tidbits of xml to post to web actions. Sweet Huh?

Webアクションに post するtidbits の XML を生成するのにピッタリだしょ?よかんべ?


  1. FileMaker – マルチプルスクリプトパラメータの受け渡し
  2. マルチプルパラメータのスクリプトへの受け渡し – 応用編
  3. FileMaker Dictionary 関数 (このエントリ)

マルチプルパラメータのスクリプトへの受け渡し – 応用編

Passing Multiple Parameters to Scripts – Advanced

以下の blockquote部分は上記出典ページの段落、直後の日本語は内容の拙訳です。
拙訳への具体的な「ちげーよバカ!」な突っ込みは大歓迎です。
※ 万一のトラブルは、出典サイトはもちろん、(たとえそれが僕の拙訳のせいだとしても) 一切関知しませんのであしからず。

素晴らしいカスタム関数を発表してくれた sixfriedrice.com の Jesse Antunes / Geoff Coffey に感謝します。


Wouldn’t it be nice if whenever you need a parameter you could just ask for it by name? Lets say that you have a create order script and you want to pass the script the name, street and zip code of the customer. If you were stuck with just the regular old FileMaker functions there ain’t no way that’s happening. But after you are done with this post, you will be able to get the name of your customer with the simple function: GetParameter( “customerName” ).

もし、パラメータを使いたいときはいつでも名前で呼び出せるとしたら、いい感じじゃないですか?
受注スクリプトがあったとしましょう。
そして、そのスクリプトに対して、顧客の名前/住所/郵便番号を受け渡したいとします。
もし、あなたが、FileMakerに元々ある関数で立ち往生しているばかりだとしたら、これはどうにもできません。
しかし、この post の内容をやっつけた後だとしたなら、シンプルな関数で、顧客の名前をとりだすことができるでしょう:
GetParameter (“customerName” )

Alright, since your interest is hopefully already piqued, I’m just going to go ahead and tell you the functions right away. There are three of them. I know that sounds like a lot but if you give me a chance to explain myself, trust me your going to love it and once you get used to them you’ll never go back.

さて、もう十分興味を刺激することはできたでしょうから、その関数の話の中身にさっさと移りましょう。
3つあります。
こう言うと大変そうでしょ?
でも、まあだまされたと思って説明を聞いてくださいな。
あまりに気に入ってしまって、これなしの世界に戻れなくなりますから。

Name:  PassParameter
Parameters:  name,  value
Formula:  "<:" & Substitute( name; ["="; "/="]; [":"; "/:"] ; [">"; "/>"]; ["<" ; "/<"]   ) & ":="                  & Substitute( value; ["="; "/="]; [":"; "/:"] ; [">"; "/>"]; ["<" ; "/<"]   ) & ":>"

Name:  DictGet
Parameters:  dict, name
Formula:  Let( [
              match="<:" & Substitute( name ; ["="; "/="]; [":"; "/:"] ; [">"; "/>"]; ["<" ; "/<"]   ) & ":=";               pstart = Position(dict; match; 1; 1);               start = pstart + Length(match);               end = Position(dict ; ":>"; start; 1);
              len = If(end = 0; 999999999; end - start)];

              If (pstart = 0; "";
              Substitute(Middle(dict; start; len); ["/:"; ":"]; ["/="; "="] ; ["/>"; ">"] ; ["/<" ; "<" ]))
)

Name:  GetParameter
Parameter:  name
Formula:  DictGet(Get(ScriptParameter); name)

These different functions are probably a little bit confusing right now so lets go through them one by one.

たぶん、これらの別々の関数を見て、ちょこっと脳みそがこんがらがっちゃったでしょうから、ひとつひとつ説明していくことにしましょう。

PassParameter( name ; value )

This custom function is your bread and butter. You use it every time you want to pass a parameter to another script. name is the name of the parameter your are passing and value is the actual text that you want to send over. So for instance if you were sending the name of your customer to a script you would use:

これが基本です。
別のスクリプトにパラメータを受け渡したいときには、これを使います。
name というのは、受け渡したいパラメータの名前で、value は受け渡したい値そのものです。
したがって、仮に、顧客の名前をスクリプトに渡したい場合はこうなります。

PassParameter( "customer" ;  "Joe Blow" )

If you want to pass multiple parameters to our order creation script would just string this custom function together using the ampersand like so:

もし、受注システムに対して、複数のパラメータを受け渡したいのなら、& (アンパサンド) を使って以下のように繋げて書けばいいわけです。

PassParameter( "customerName" ;  "Joe Blow" ) &
PassParameter( "street" ; "123 Any St." ) &
PassParameter( "zip" ; 85282 )

How it works: PassParameter() turns the name, value pairs that you pass in into a special format so that they are easy to manage. It basically puts two special characters in front of the name, between the name and value, and after the value. Basically if you were to say PassParameter( “customerName” ; “joe blow” ), this function turns your text into:

実際の動き方:
PassParameter ( ) は、name/value のペアを、処理しやすいように特殊なフォーマットに変換します。
要は、name の前と、name と value の間と、value の後に、2文字の特殊な文字を追加するわけです。
つまり、
PassParameter( “customerName” ; “joe blow” )
と書いたら、返ってくるのは…

<:customerName:=joe blow:>

or in the case of multiple parameters as above it would look like this:

先述の複数のパラメータ例の場合は、以下のような感じになります。

<:customerName:=joe blow:><:street:=123 Any St.:><:zip:=85282:>

This construct of name and value pairs is what we refer to as a dictionary. This becomes important because our next function operates on a dictionary. You’ll notice in the actual definition of the function PassParameter() that I do a couple of substitutions. I use this process to escape the different characters that I use in my delimiters so that my scripts won’t break when you send in those same characters. Don’t worry though, when I get them back out I remove any extra characters that I added.

この name/value のペア構造を dictionary として参照させているわけです。
これは大変大切なことです。
次の関数は、この dictionary を操作する関数です。
PassParameter ( ) の定義式を見れば、二度ほど substitute をしていることがわかりますね。
このプロセスは、デリミタ(区切り記号) として使っているのと同じ文字列をパラメータの内部で使っても、スクリプトが破綻しないように、別の文字列にエスケープするためのものです。
余計な文字列は最終的には除去されますから、ご心配なく。

DictGet( dict, name)

The dict parameter in this custom function is, yup you guessed it, short for dictionary. The second parameter, ‘name’, is just the name of a value that you would like to get out of the dictionary. So if you were to execute the following code:

このカスタム関数内の dict という引数は、(はい!もうわかりましたね!)、dictionary の略ですね。
2番目の引数の name は、dictionary から取り出したい値の名前です。
ですから、もし以下のコードを実行すると…

DictGet( "<:customerName:=joe blow:><:street:=123 Any St.:><:zip:=85282:>" ; "customerName" )

It would return “Joe Blow”. On it’s own this DictGet function doesn’t seem that useful but it is the workhorse of the three functions.

How it Works: DictGet() actually works as a basic text parser. It takes the name that you pass in and turns it into the format you would expect in the dictionary. If the name passed in is “customerName”, then it would be turned into “<:customerName:=”. The we take that weird looking text and search for it in the dictionary. If we find the weird string in the dictionary, then we return the value for it (”joe blow”, otherwise we return an empty string (””). Pretty neat huh?

“Joe Blow” が返ります。
DictGet 関数は、これ自身のみではさほど役に立つとは思えないでしょう。
しかし、DictGet 関数は、くだんの3つの関数の間で馬車馬のように働いてくれるのです。

実際の動き方:
DictGet ( ) は、基本的なテキストパーサとして働きます。
name を受け取ると、dictionary に対して、よき案配のフォーマットに変換します。
渡された name が “customerName” だとすると、
“<:customerName:=”
と変換されます。
そしてこの妙ちくりんなテキストを、dictionary の中で探します。
dictionaryの中に このへんてこテキストを見つけた場合、”joe blow” という値を返すわけです
(見つからなければ、空値 “” が返されます)
なかなかイケてるでしょ?

GetParameter( name )

This is the function you would use whenever you are trying to access data that was passed in using the PassParameter() function. It’s is specifically designed to operate on a script parameter that contains a dictionary. It actually just pulls the value of the name you give it, out of the script parameter using the DictGet() function. Very Simple…. not a whole lot going on here.
Now that you have a pretty good understanding you are pretty much ready to enter into the world of named parameters. Once you get used to using these little gems, I am positive that you will never be able to go back to plain old vanilla script parameters ever again. There are a couple more benefits to using these functions such as using named values in your script results, nesting parameters and accessing multiple occurrences that I will probably get into a later date. For now… I hope these functions help make FileMaker Development a little easier for you.

PassParameter ( ) 関数を使って受け渡されたデータにアクセスしたいときに使います。
dictionary を内包するスクリプト引数を操作するため専用に作成しました。
DictGet ( ) 関数を使って、スクリプト引数から、与えられた name にひもづく値を引き出すわけです。
すごくシンプル。なんちうこたない。
さて、なかなかいい感じで理解できたなら、named parameter の世界に入る準備はいい感じでOK ということです。
いったん、これらのちょっとしたテクを使うのに慣れると、もう、あの古式ゆかしいペラッペラに薄っぺらな標準のスクリプト引数に二度と戻る気はさらさらなくなることでしょう。
これらの関数を使うことで、他にも、二三の恩恵に浴することができます。
スクリプトの結果から 名前で値を引っ張りだしたりとか、入れ子のパラメータからとか、後日言及する複数のオカレンスへのアクセスとか…ね。
とりあえず、これらの関数が、あなたの FileMakerでのデータベース開発を少しでもラクチンにすることを願います。

More About Dictionaries: If you would like to get a little more in-depth into these functions there is a second post that adds functionality to this idea here:FileMaker Dictionary Functions.

NOTE: We had a couple of good comments from some of our early release readers. Genx who blogs on FileMakerMagazine.com added that he thought it would be much more visually appealing and easier to use XML style tags. I can’t remember the exact reason why I didn’t go this route… I am pretty sure it was because I wanted to have two delimiters at each break point in the name/value pair. He did convince us to change the names of the functions from our more nondescript names ( #() #P() ) we started with so that it would be easily understood what each one did. Another useful tip came from Fitch ofpre1.com, who pointed out that another similar name/value pair implementation can be seen in Back Magic from SeedCode.com

dictionary 関連のより詳しい話:
これらの関数についてもっと詳しく知りたい場合、下記の second post で、ここのアイデアの機能追加発展版な記事が読めますぜ。
FileMaker Dictionary Functions

日本語 拙訳

Note:初期版読者からの 良きコメントが、ふたつみっつありました。
FileMakerMagazine.com の blog をやっている Genx からは…
XMLスタイルタグを使えば、もっと見た目で分かりやすくて訴求力のある感じになるんじゃね?…と。
今となってはなんでそのルートに行かなかったのかを思い出せないのですが… おそらくは、たぶん name/value ペアのブレークポイント毎に、2文字のデリミタを差し込みたかったんだと思われます。
また彼がそうしろというのがもっともなので、最初 #() #P() とかいう何なんだかわからない記述にしていたこれらのカスタム関数の名前を、何をするものなのか分かるような名前に変えることにしました。

もうひとつのナイスコメントは、pre1.com の Fitch でもって…
似て非なる name/value ペアの実装方法を指摘してくれました。
Back Magic from SeedCode.comで見られます。


  1. FileMaker – マルチプルスクリプトパラメータの受け渡し
  2. マルチプルパラメータのスクリプトへの受け渡し – 応用編 (このエントリ)
  3. FileMaker Dictionary 関数

FileMaker – マルチプルスクリプトパラメータの受け渡し

FileMaker – Passing Multiple Script Parameters
以下の blockquote部分は上記出典ページの段落、直後の日本語は内容の拙訳です。
拙訳への具体的な「ちげーよバカ!」な突っ込みは大歓迎です。
※ 万一のトラブルは、出典サイトはもちろん、(たとえそれが僕の拙訳のせいだとしても) 一切関知しませんのであしからず。

素晴らしいカスタム関数を発表してくれた sixfriedrice.com の Jesse Antunes / Geoff Coffey に感謝します。


I can think of hundreds of times when I found myself pounding my head against the desk because I had to define yet another global field just to pass a simple value from one script to another. Like you, I myself hate to have lots of cruft clogging up my databases. Luckily, FileMaker 7+ gave us the wonderful addition of script parameters to help relieve this plight. Sometimes, even this isn’t enough and that’s where passing multiple parameters takes over.

あるスクリプトから別のスクリプトに対して、単純な値を渡すためだけに、グローバルフィールドをもうひとつ定義しなければならなくなって…「あーもー!」てなもんで、机に頭を打ちつけていた…あの光景を何百回も思い出すのことあります。
あなたたちと同じで、わたしもデータベース開発作業の足を引っ張るたくさんのあれやこれやに辟易していました。
幸運にも、FileMaker 7 以降では、こんな状況を少しは楽にしてくれる スクリプト引数なるものが追加されたわけですが、複数の引数を受け渡したいとかいうことになると、そんなもんじゃ足りなくなることもよくあります。

Whenever a script is chosen in a perform script step, Filemaker shows a box for an optional script parameter. You can type in whatever your programming heart desires or you can click the edit button and take advantage of Filemaker’s many built-in functions to construct a parameter. Many times, when presented with this option you probably find yourself thinking . . . Boy, I wish I had space for a bunch of different parameters. Well with the use of that tiny edit button, a couple of Filemaker’s functions and a little bit of ingenuity this actually ends up being doable. To pass multiple parameters in filemaker we are basically going to make a ¶ delimited list and then crowbar individual parameters out using the MiddleValues().

スクリプト実行が選択されたときはいつでも、オプショナルなスクリプト引数のためのボックスが表示されます。
あなたのプログラミング魂の赴くままに入力することも、編集ボタンを押して、ビルトインの関数を利用して引数を組み立てることもできます。
そのとき何度もこう思ったはずです。
「にいちゃんよー、一連のパラメータを書く場所がなんとかならんかねー。そのちっぽけな編集ボタンを使って、いくらかの FileMakerの関数を使ったひと工夫でよー。」
FileMakerにおいて、複数の引数を受け渡すには、基本的に、改行区切りリストにぶちこんで、個々の引数を MiddleValues ( ) を使って無理矢理引っ張りだすことになるわけです。

Ok, let’s say we are trying to create a new line item for an order we are going to fulfill for 3 iPhones at a price of $499. We don’t want to have to put the part number (iPhone), the description (”The coolest phone I have ever seen. Wow, it’s also really cheap!”) the quantity(3) and the price($499) in a bunch of different globals to pass our script, so we will just send them in using the script parameter. To do this, select the perform script step and pick the script you are going to call. Then hit the edit button next to the “Optional Script Parameter” box. Filemaker’s trusty old calculation window will pop up and you’re ready to roll. All you have to do is make the parameters you would like to pass into a list like so:

では、たとえば今、499ドルの 3つの iPhone 用に 新しい項目 を作りたいとしましょう。

部品番号 (iPhone) とか、説明 (”The coolest phone I have ever seen. Wow, it’s also really cheap!”) とか、数量 (3)とか、価格 ($499)とかを、スクリプト引き渡しのために一連の別個のグローバルにいちいち入力したかないので、スクリプト引数を使って受け渡したいというわけです。

そのために、スクリプトステップを実行を選択して、実行するスクリプトを指定して、オプションのスクリプトパラメータの横にある編集ボタンをクリックします。
FileMaker の古式ゆかしい計算ウィンドウがポップアップしたら準備完了です。
やんなきゃいけないことは、受け渡したい引数を作ることです。

こんな感じで…

"iPhone" & ¶ &
"The coolest phone I have ever seen.  Wow, it's also really cheap!" &  ¶ &
3 & ¶ &
499

Hit Ok and you are done with your parameter passing. Now comes the part where you pop the values you want from the script parameter. To do this we are just going to simply use the MiddleValues() function. The complete signature of Middlevalues() is:

OKをたたいて引数受け渡しは完了。
さて、お次ぎは、お好みの値を、スクリプト引数から引っ張りだすわけです。
これには、シンプルに MiddleValues ( ) 関数を使うことになります。
この場合の 完全な MiddleValues ( ) の書式は…


MiddleValues ( text ; startingValue ; numberOfValues )

Note: Thanks to David Richards (from the comments) and Genx (from FMForums.com for pointing out that you can simplify these calcs using GetValue instead of MiddleValues. We needed FileMaker 7 support for this particular setup, but if you can live with 8+ only, they’re absolutely right. GetValue does not include the trailing ¶ so you can avoid all the mumbo jumbo about cleaning that up.

Note: David Richards (コメント欄から) と Genx (FMForums.com から) に感謝します。
これらの計算式は、MiddleValues の代わりに、GetValue を使うことでシンプルになることを指摘してくれてありがとう。
私たちは、この特有のセットアップで FileMaker 7 をサポートしなくちゃならないけど (だから MiddleValues で行くわけだけど)、8以降のみなら、彼らは完全に正しいわけです。
GetValue だったら、改行を引きずることもないから、余計なジュゲムジュゲム的記述を削除できるね。

The sole purpose of this function is taking a list of ¶ separated values, exactly like we created in the previous step, and select the values you specify from it. For instance, let’s say we are in the script we called in the first step and we want to get the quantity out of the script parameter. All we would need to do is execute the following bit of code:

この関数の唯一の目的は、(前のステップでやったように) 改行区切りリストを得ることと、そのリストから指定した値を取得することです。
たとえば、最初のステップで呼び出したスクリプトのなかにいて、スクリプト引数から 数量を取り出したいとしましょう。
下記のちょろっとしたコードを実行するだけです。


MiddleValues( Get ( ScriptParameter ) ; 3 ; 1 )

This step tells Filemaker to start from the third value in the script parameter and return one value which is effectively just saying give me the third value in the list. If you want the fourth value, the price, just change the number 3 to a 4. The one will always stay the same because you wouldn’t really want to get more then one value out of the script parameter at a time. It wouldn’t really make sense in a typical script.

We have the value out, we still aren’t quite finished. The MiddleValues function doesn’t get ride of the annoying ¶ that we tacked on the end of our parameters so to delete it we have to add the following code:

このステップは、FileMaker に スクリプト引数の 3番目の値から 一行取得するということです。
(実際には、リストの3番目をよこせと言ってるのと同じ)
もし、4番目の価格の値が欲しいなら、3を4に変えるだけのことです。
一度に複数の値をスクリプト引数から取り出したいことはないでしょうから、一行取得というのはいつも同じです。
典型的なスクリプトではあんまり役にはたたないかもしれません。

値を取り出せはしましたが、まだ終わりではありません。
MiddleValue 関数は、パラメータ全体をつなぐ改行を引きずったままなので、改行を削除するためには、以下のコードを追加してやらなければなりません。


Let(
      parameter = MiddleValues( Get ( ScriptParameter ) ; 2 ; 1 ) ;
      If (
            right ( parameter ; 1 ) = ¶ ;
            left( parameter; length( parameter ) - 1 ) ;
            parameter
          )
     )

This code is a little confusing but it is basically saying if we have a ¶ on the end of our parameter take it off.

Now that you have seen how we plan on getting the values out, you are probably thinking to yourself… What happens if I pass a ¶ in the middle of one of my parameters. This isn’t exactly out of the realm of possibility and it would clearly break your code. For instance if you changed the description on the iphone to read:

このコードは、頭が少しこんがらがるかもしれませんが、要は、パラメータの最後に改行があれば、それを削除しろと言っているだけのものです。

さて、値を取り出そうとする方法を見てきたわけですが、おそらくこう思っていらっしゃるでしょう。
「パラメータの中に改行を含む値を持ちたい場合はどうなるん?」
それはあり得ない領域の話ではありませんし、そうなれば明らかにアウトです。
たとえば、iPhone の説明をこう変えたとしましょう。:


"iPhone" & ¶ &
"The coolest phone I have ever seen.¶Wow, it's also really cheap!" &  ¶ &
"" & ¶ &
499

Unfortunately, Filemaker will mush (concatenate for you technical types) everything together and create the following list:

残念ながら、FileMaker は、すべてを一緒に (数珠つなぎで) まぜこぜにして、以下のようなリストを吐き出すでしょう。


iPhone¶
The coolest phone I have ever seen.¶
Wow, it's also really cheap!¶
¶
499

Now, everything has been shifted down one because of that extra ¶ and we can no longer get the price, quantity nor description that we expect. To take care of this we have to escape the ¶ so that it turns it into just a symbol rather then turning it into a new line in your text. To implement this change we will have to change how we create our list. I know I lied to you, you weren’t quite done with creating your parameter list. Here is the function you will need:

こうなると、すべては、邪魔な改行のせいで一段下がってしまいます。
価格も数量も、期待される形での説明も取得できなくなります。
このことの面倒をみるには、改行をどうにかエスケープさせて、テキストを改行させるためだけのシンボルと扱うようにしなければなりません。
この変更を実装するためには、リストの作成方法を変更しなければなりません。
はい、嘘ついてました。パラメータリストの作成はまったく終わっていませんでした。
以下が、必要な関数です。


Name: Parameter
Parameters: value
Formula: Substitute( value ; "¶"; "\¶" )  & ¶

Using our new code we would rewrite our last list to:

新しいコードをつかうには、先述のリストも書き換える必要があります:


parameter( "iPhone" ) &
parameter( "The coolest phone I have ever seen.¶Wow, it's also really cheap!" ) &
parameter( "" ) &
parameter( 499 )

Not only does this list look a heck of a lot cooler, but it is more functional and a LOT easier to read. OK, we have a custom function to add parameters to a list, we should probably create one to get all that information out so we don’t have to type that horrible blob of code ever again:

これでむちゃくちゃかっちょいーだけでなく、より機能的で、ものすごく読みやすくなったわけです。
さあ、パラメータを追加するカスタム関数もあります。
あのゾッとするコードの一塊をもうタイプしなくてすむようなすべての情報を一緒にしたヤツを作る必要があります:


Name: GetParameter
Parameters: number
Formula:
     Let(
          parameterValue = MiddleValues( Get ( ScriptParameter ) ; number ; 1 ) ;
          substitute( left( parameterValue; length( parameterValue ) - 1 ) ; "\¶" ' "¶" )
         )

Before you go off and pass around parameters all willy nilly, there is one final warning when using this style of parameter passing. To demonstrate it, Let’s go back to our iPhone example. Say that you don’t want to include the quantity just yet, but you still want to send over the price and description. If you tried the following:

さてパラメータを受け渡しまくり始めるには、まだ早いです。
このパラメータ受け渡しスタイルを使うには、否応無しに、最後の警告をひとつしなければなりません。
デモを行うために、例の iPhone の例に立ち返りましょう。
数量を含めることは必要ないけれど、価格と説明の受け渡しは必要だとしましょう。
もし以下のようにやってみると…


Parameter("iPhone") &
Parameter("The coolest phone I have ever seen.  Wow, it's also really cheap!") &
Parameter(499)

The $499 will go into the quantity field because your script that creates the line item thinks that the quantity is the third value, but because the quatity isn’t there the price has shifted up into the third position. To alleviate this problem you just need to make sure that you ALWAYS pass all the parameters to a script, even if one is empty. So your parameter list should look like this:

スクリプト的には、数量は3番目の値だと思っているわけですから、$499 は、数量フィールドに入ってしまいますが、実は、数量はそこではなく、その3番目の位置には、繰り上がって価格が来ることになります。
この問題を軽減するには、(たとえ空っぽの値があったとしても)「いつどんなときも」すべてのパラメータをスクリプトに受け渡すことが条件になります。
したがって、パラメータリストはこうなります:


Parameter("iPhone") &
Parameter("The coolest phone I have ever seen.  Wow, it's also really cheap!") &
Parameter("") &
Parameter(499)

Hopefully, many of you find this quite useful and it will help you build more powerful and less cluttered databases. For those who would like a more technically advanced way of passing parameters, where you can actually associate each parameter with a name, such as qty = 2, then check back soon for another article.

願わくば、みなさんが、よりパワフルでよりすっきりしたデータベースを作る上で助けになり、有益であると思っていただければよいのですが。
それぞれのパラメータを name と結びつけた (たとえば、gty = 2 みたいに) もっと技術的に進歩的なパラメータ受け渡し方法をお望みの向きには、別記事で。


  1. FileMaker – マルチプルスクリプトパラメータの受け渡し (このエントリ)
  2. マルチプルパラメータのスクリプトへの受け渡し – 応用編
  3. FileMaker Dictionary 関数

PassParameter 関連カスタム関数 のいいかげんな和訳をしてみるYO!

先日の FileMakerカンファレンス 2010 で、ユーザーグループのよろず相談コーナーを何時間か担当しました。

僕の最初の担当時間は、午後一で、メイン会場の階に、ちゃんとした場所が確保できず、サブ会場の階の「迷子以外だれがこんなとこ来るねん」な場所でした。

案の定、「すみません、ココへ行きたいんですけど…」な人々相手に、立番おまわりさんな状況で、一時間ほど過ごしたわけですが、人生、悪いことばかりではなく、すこぶる良いことがありました。

それは、有賀さんと今泉さんに、PassParameter などの Dictionary Function の話を聞けたことです。

上述の通り、「暇すぎて死にそう」な1時間に、たまたま僕と同じ時間帯に、よろず相談コーナーに座っていたのがお二人で、
することもないので、いろいろと四方山話のうちに、このすばらしいカスタム関数について伺いました。

いたく感動した僕は、いただいた 超有益なカスタム関数の情報を、ガメているのもなんだし(生来のしゃべりたがり屋の性惰ゆえというのが実のところですが) と、FileMakerがらみの人に会う度に、その話をしたわけです。
もちろん、出典 URL もその度にメールしました。

しかし…こちらと同じテンションで、よろこんでくれる人が非常に少ないわけです。

理由の一部には、おそらく当該Blogエントリが(割りと軽〜い語り口の)英語であることも問題なのではないかと思うに至りました。

ちうことで、使い勝手のあるすばらしいカスタム関数を発表してくれた six.fried.rice の Jesse Antunes タソに ありがとうの意味を込めて、いいかげんこの上ない日本語に訳してみる気になったのでつ。

以下の順番で読み進めれば、分かりやすいと思われます。

  1. FileMaker – マルチプルスクリプトパラメータの受け渡し
  2. マルチプルパラメータのスクリプトへの受け渡し – 応用編
  3. FileMaker Dictionary 関数

CSVファイルを出力して FTPアップロードするまでを FileMaker のスクリプトで行う方法 (Mac OS X)

某クライアント (不動産業) の案件で、『CSV を 吐き出して、FTPで (あらかじめ規定された) Webサーバ上のフォルダ にアップロードする』というものがありました。

そのクライアントは、社内業務に FileMaker を使っているので、FileMaker (Mac OS X) のスクリプトで実行したいわけです。

条件は、以下の通り。

  1. CSVファイルの文字コードは、UTF-8 / 改行コードは、LF。
  2. CSVファイル名は、YYYYMMDDhhmmss_テーブル識別子.csv の形式。
  3. CSV出力と同時にFTPアップロードする。
  4. FTPユーザ名/パスワードなどのFTP関連情報は、FileMakerアクセスからは隠す。
  5. Macを少しだけ使えるスタッフが、Macで、FTPサーバアドレス/FTPユーザ名/パスワードなどのFTP関連情報 をいつでも修正できるように。

1 は、普通にCSV(UTF-8)書き出し後に (Mac OS X での出力なので 改行コードが CR なので LF に修正するために)

$ perl -p -e ‘s/\r/\n/g’ < CR.txt > LF.txt

とやってやればOKですし、なんなら、XML FMPRESULT 指定で…という方法もあります。

2 は、
テーブル識別子を $tableid というグローバル変数に格納しておいて、

Let ( [

$YYMMDD = GetAsText ( Year ( Get ( 日付 ) ) * 10000 + Month ( Get ( 日付 ) ) * 100 + Day ( Get ( 日付 ) ) ) ;
$hhmmss = Right (
"000000" & GetAsText ( Hour ( Get ( 時刻 ) ) ) * 10000 + Minute ( Get ( 時刻 ) ) * 100 + Seconds ( Get ( 時刻 ) ) ;
6
) // Right
] ;
$YYMMDD & $hhmmss & “_” & $tableid & “.csv”
) // Let

とかやってやればOKでしょう。

3 も、4 の条件がなければ、シェルコマンドを do shell script な AppleScript ではじいてやればOKのはずなのですが、この場合、AppleScript内に、FTPユーザ名/パスワードなどの情報を書き込むことになります。
では、FTP情報を埋め込んだ AppleScript をアプリケーション形式で保存しておいて、それを叩いてやれば良さそうなものですが、
5 の条件でいう『Macを少しだけ使えるスタッフ』には、AppleScript の編集は、少し荷が重すぎるようです。

…で、「どうやって、FTPアップロードすべ?」と悩んでいたわけです。

Automator Acriotn : Upload to FTP を使った Automatorフロー例いっそのこと、Transmit 4 などの FTPクライアントソフトの AppleScript 機能を使って…という『一応の解』が出ていたわけですが…ふと「Automator でどーよ!?」と思いました。

「Automator なら Automator のフロー側に FTPユーザ名/パスワードなどをリテラルで格納すれば、FTP関連情報をFileMaker アクセスからは隠せるし、Automatorのワークフローの修正なら、『Macを少しだけ使えるスタッフ』にも修正可能!」

探したところ、Upload to FTPという Automator Action がありました。
これを使って、CSV書き出し用フォルダに、フォルダアクション として設定すれば、オールOK!

具体的な手順の説明は、また後日。

Mac mini Server に FileMaker Server 11 をインストール (Mac OS X Server 10.6 の初期設定)

Snow Leopard Server 搭載 Mac mini を買ってきて電源を入れた直後の画面から、FileMaker Server をインストールする前までの設定を、(冗長に過ぎるかと言うほど) 豊富なスクリーンキャプチャ画像で、流れるように説明……w

注意!:最初からインターネットサーバとして設定したいという場合もあるでしょうが、今回は、逆引きの権限委譲がなされていないプロバイダの固定IPサービスを使用している環境ですので、プライマリ DNS名は、.private を使用しています

また、今のところ、これが一番シンプルでわかりやすいのでは…という設定について述べていますが、諸条件が違えば、そらこの方法では不適当になる場合ももちろんあるでしょう。
Net上に あまり情報がなかったので、記事にしましたが、あくまで、自分メモ程度の情報です。

参考になさる場合、at your own risk でお願いします。

また、間違いなどがあれば、コメント欄ででもご指摘下さい。
今後、間違いや補足情報は、分かり次第、随時 修正していくつもりです。

1) [続ける]をクリック。 Continue reading

Mac mini Server に FileMaker Server 11 をインストール (序章)

Snow Leopard Server (Mac OS X 10.6 Server) 搭載 Mac mini に、FileMaker Server 11 を載っけて、使おうとやってみた。

適当に設定してみたが、なんだか安定しない。
「そんじゃ、クライアント版の Snow Leopard を載せ換えて、そっちでやろう」と思ったのだが、クライアント版の Snow Leopard は、 Snow Leopard Server 搭載 Mac mini にインストールすることができない。

※ もちろん、直接、Mac mini でインストールすることもできないし、他の Mac で、外部HDにインストールして、そのHDを Mac mini に接続しても、暗黒カーテンが降りてくる例のカーネルパニックな画面になって、起動できない。

しょうがないので、Mac OS X Server 10.6 Snow Leopard を再インストールすること数度。
ことごとく、安定しなかったのだが、下記の参考ドキュメントを読みまくったり、エロい人 エライ人 に聞いたり、Apple の XServer系サポートの人 に聞いたり…して、数度のクリーンインストールを繰り返した結果、なんとなく、「こーゆーのが一番シンプルなんじゃね?」というものに、とりあえず行き着いたので、まとめてみたりしようかと…。 Continue reading

Bento 3 リリース!

BENTO 3

Bento の新バージョン Bento 3 がリリースされました。

既存の Bento / Bento 2 のユーザには、リベートプログラムがあるようです。
リベートプログラムは、通常の アップグレードプログラムとは少々手順が違います。

まずは、普通に、どこかで購入し、その後、Bento 3 アップグレードリベート リクエストフォーム で、旧バージョンのインストールキー / 新バージョンのインストールキー / 購入日 / 購入店 などをフォームに入力すると、後日、2,000円分のリベート券が入手できるようです。
(しかし、日本の FileMaker社のサイトでは、リベート券のことをあまり大々的に喧伝していませんね)

なんか面倒にも思えますが、通常の アップグレードだと、旧バージョンの使用権を、新バージョンに更新するというライセンス契約になる場合も多いところ、このリベート・プログラムなら、別途、旧バージョンで事足りるジョブは、別マシンに旧バージョンをインストールしておいて使用するということも、ライセンス的に問題なさそうですよね。

何やら、5人までの共有に対応したとか、iPhoto との連動ができるようになったとかのようですが、詳細は後日、使い心地などもレビュー予定です。

※ 共有を使うには、ファミリーパックの購入が必要ですね。

………………………………………………………………………………………………

2009/10/28 追記:

やっとFileMaker Japan のサイトでも、

Bento 3 アップグレードリベートオファー

としてこの件に対するアナウンスが行われました。
http://www.filemaker.co.jp/promos/

それによると、

今すぐ割引価格で購入(インスタントキャッシュバック) — こちらの FileMaker Store Japan にて、2,000 円割引の価格でお求めいただけます。Store でのご購入には、有効な Bento 1 または Bento 2 のライセンスキーが必要です。

とのことなので、購入 > 申請 > キャッシュバック という形式をとらなくても、キャッシュバック分を引いた金額で購入 という手段ができたようです。

FileMaker社に不安を感じる

■ FileMaker社 日本法人 新社長 が 戦略を語るインタビュー記事

粟倉社長に聞く、ファイルメーカーの戦略
http://ascii.jp/elem/000/000/425/425694/

彼の主張を意訳すると…

  • 従来の販売形態は、データベースソフトといえども、他のアプリケーションと同様に、店頭でのパッケージ販売が主であった。
  • この状態では、素人にも使いやすい 体感的なデータベースソリューションの作成が可能な アプリケーション から脱却できない。

そこで、戦略に3つの柱を考えた。

  1. ライセンス販売を行う直販部隊を新設
  2. FBA企業に、ライセンスの再販を認めた
  3. 大手インテグレータとパートナーシップ

これらは、一見ふつうの話に聞こえる。 Continue reading