2017年3月30日木曜日

FileMaker PowerShell と連携、戻り値取得。cmdコマンドを実行。プラグイン不要

FileMaker PowerShell と連携、戻り値取得。cmdコマンドを実行。プラグイン不要。
OS:Windows

FileMaker 12以降?

フィールド:Command
値:
$Rsult=cmd /C dir /b "c:\" ;
$return=$Rsult -join "%0A" ;

フィールド:CallBack
値:
Start-Process ('fmp://$/{ファイル名}?script=FireCommand&$Return='+$return);

FileMakerから実行
以下のようにすると送信結果の戻り値の取得が取得出来ます。
スクリプト名:FireCommand
If [ not IsEmpty ( $Return )]
フィールド設定 [PS::Result; $return]
フィールドへ移動 []
現在のスクリプト終了 []
Else If [Get ( スクリプト引数 ) = 1]
変数を設定 [$Script; 値:Quote ( Substitute ( PS::Command & PS::CallBack ; ¶ ; "" ) )]
Event を送信 [「aevt」; 「odoc」; "powershell -windowstyle hidden -Command " & $Script]
End If



※戻り値が多いと全部は、取得できません。
そんなときは、以下を使えば、解決します。
ProcessMakerTL(プロセス メーカー ティー エル)
FileMaker補助アプリケーション

FileMaker PowerShell と連携、戻り値取得。dirコマンドっぽく使う。プラグイン不要


FileMaker PowerShell と連携、戻り値取得。dirコマンドっぽく使う。プラグイン不要。
OS:Windows

FileMaker 12以降?

フィールド:Command
値:
$Rsult=Get-ChildItem "C:\" | Select-Object Fullname;
$return=$Rsult.FullName -join "%0A" ;

フィールド:CallBack
値:
Start-Process ('fmp://$/{ファイル名}?script=FireCommand&$Return='+$return);

FileMakerから実行
以下のようにすると送信結果の戻り値の取得が取得出来ます。
スクリプト名:FireCommand
If [ not IsEmpty ( $Return )]
フィールド設定 [PS::Result; $return]
フィールドへ移動 []
現在のスクリプト終了 []
Else If [Get ( スクリプト引数 ) = 1]
変数を設定 [$Script; 値:Quote ( Substitute ( PS::Command & PS::CallBack ; ¶ ; "" ) )]
Event を送信 [「aevt」; 「odoc」; "powershell -windowstyle hidden -Command " & $Script]
End If

2017年3月29日水曜日

ChatWork へ新しいタスクを追加|PowerShell|FileMaker

ChatWork へ新しいタスクを追加
http://developer.chatwork.com/ja/endpoint_rooms.html#POST-rooms-room_id-tasks
PowerShell
FileMaker

以下のPowerShellを実行すれば、ChatWork へ新しいタスクが追加されます。

フィールド:Command
値:
Add-Type -AssemblyName System.Web;
$encode = [System.Text.Encoding]::UTF8;
[DateTime]$dateTime = '2017/4/1';
$limit = '{0:#}' -f (New-TimeSpan 1970/1/1 $dateTime).TotalSeconds;
$headers = @{'X-ChatWorkToken' = '自分のAPIトークン'};
$body='body='+[System.Web.HttpUtility]::UrlEncode('こんにちわ',$encode);
$body+='&limit='+$limit;
$body+='&to_ids='+'担当者のアカウントID';
$return=Invoke-RestMethod -Method POST -Uri https://api.chatwork.com/v2/rooms/{room_id}/tasks -Headers $headers -body $body;
$return=$return.task_ids ;

FileMakerから実行
以下のようにすると送信結果の「task_ids」が取得出来ます。

フィールド:CallBack
値:
Start-Process ('fmp://$/PowerShell?script=FireCommand&$Return='+$return);

スクリプト名:FireCommand
If [ not IsEmpty ( $Return )]
フィールド設定 [PS::Result; $return]
フィールドへ移動 []
現在のスクリプト終了 []
Else If [Get ( スクリプト引数 ) = 1]
変数を設定 [$Script; 値:Quote ( Substitute ( PS::Command & PS::CallBack ; ¶ ; "" ) )]
Event を送信 [「aevt」; 「odoc」; "powershell -windowstyle hidden -Command " & $Script]
End If

ChatWork へ新しいメッセージを追加|PowerShell|FileMaker

ChatWork へ新しいメッセージを追加
http://developer.chatwork.com/ja/endpoint_rooms.html#POST-rooms-room_id-messages
PowerShell
FileMaker

以下のPowerShellを実行すれば、ChatWork へ新しいメッセージを追加が追加されます。

フィールド:Command
値:
Add-Type -AssemblyName System.Web;
$encode = [System.Text.Encoding]::UTF8;
$headers = @{'X-ChatWorkToken' = '自分のAPIトークン'};
$body='body='+[System.Web.HttpUtility]::UrlEncode('こんにちわ',$encode);
$return=Invoke-RestMethod -Method POST -Uri https://api.chatwork.com/v1/rooms/{room_id}/messages -Headers $headers -body $body;
$return=$return.message_id ;


FileMakerから実行
以下のようにすると送信結果の「message_id」が取得出来ます。

フィールド:CallBack
値:
Start-Process ('fmp://$/PowerShell?script=FireCommand&$Return='+$return);

スクリプト名:FireCommand
If [ not IsEmpty ( $Return )]
フィールド設定 [PS::Result; $return]
フィールドへ移動 []
現在のスクリプト終了 []
Else If [Get ( スクリプト引数 ) = 1]
変数を設定 [$Script; 値:Quote ( Substitute ( PS::Command & PS::CallBack ; ¶ ; "" ) )]
Event を送信 [「aevt」; 「odoc」; "powershell -windowstyle hidden -Command " & $Script]
End If

2017年3月12日日曜日

別PCのFileMakerのスクリプトを実行。簡易版

http://joy-h.com/bbs2/viewtopic.php?id=6096
上記に書いたものと同じ内容。

別PCのFileMakerのスクリプトを実行。
動作検証は、少なめです。何か予期しない不具合があるかも?

テーブルを一つ作成し、

テーブル:Command
フィールド:Target
フィールド:Source

ターゲットのテーブルと
デカルト積[X]のリレーションを設定します。

ターゲットのテーブルがあるレイアウトのヘッダーに
WEBビューアを設置
式:
If (  FilterValues ( Get ( システム IP アドレス ) ; Command::Target ) ; "Data:text/html," & Command::Source ; "" )

iPad(FileMaker Go)で、
フィールド:Target
値:操作したいPCのIPアドレス

フィールド:Source
値:

上記のようにすると、
フィールド:Target
または、
フィールド:Source
を書き換えるたびに、ターゲットのPCで「"fmp://$/{ファイル名}?script=receive&$argu=012345あいうえお"」が実行されます。

追記

フィールド:Source に

があるままだと、レコード移動やその他のタイミングで実行されるので、

テーブル:Command に フィールド:Code を追加。

送信側実行スクリプトは、

フィールド設定 [Command::Source; Command::Code]
フィールドへ移動 []

こうしておき、

受信側スクリプトでは、以下のようにして フィールド:Source を初期化する。

フィールド設定 [Command::Source; "(´・_・`)"]
フィールドへ移動 []