2021年3月22日月曜日

【メモ】jsonから名前(キー)を取得, json 集計等 |PowerShell

 $ERROR.Clear();

$records=ConvertFrom-Json '

[

{"101":"","102":"12000","103":"12000"},{"101":"","102":"12000","103":"12000"},{"101":"","102":"12000","103":"12000"},

{"101":"","102":"12000","103":"12000"},{"101":"","102":"12000","103":"12000"},{"101":"","102":"12000","103":"12000"},

{"101":"","102":"12000","103":"12000"},{"101":"","102":"12000","103":"12000"},{"101":"","102":"12000","103":"12000","104":999}

]

'

#json 集計等

$sum=$records|Measure-Object -Property "*" -Sum ;


ConvertTo-Json $sum


#jsonから名前(キー)を取得

$records | ForEach-Object{$_| Get-Member -MemberType Properties | Select-Object -ExpandProperty Name}| Sort-Object -Unique

2021年3月15日月曜日

Power Automate Desktop のフローを「バッチファイル」「ショートカット」「FileMaker」などから実行

2022/12/01 追記
Power Automate バージョン:226.139.22312(あたり) 以降は、最下部の修正を適用してください。

Power Automate Desktop のフローを実行

コマンドプロンプト
バッチファイル
ショートカット
FileMaker などから実行するための PowerShellスクリプト

動作検証
Wiundows 10
Power Automate Desktop 2.5.39.21056
PowerShell 5.1・7.1.3

ファイルダウンロード ¥0
PAD_aid.zip
https://fm-aid.stores.jp/items/604f73e6243860052a8c9134


準備

WinAppDriver をインストール
WindowsApplicationDriver_1.2.1.msi(2021/03/15現在)をダウンロードしてインストール

-
WinAppDriver を利用するには、「開発者モード」にする必要があります。
「設定」- 更新とセキュリティー」-「開発者向け」



KickPADFlow.ps1 の設定・確認


6行目 Power Automate Desktop のコンソールウインドウの名前を確認。
違う場合は合わせてください。
$PADWindowName='Power Automate Desktop (プレビュー)'


7行目 PAD.Console.Host.exe のパスの確認。異なる場合は修正
$PADConsoleHostExePath="C:\Program Files (x86)\Power Automate Desktop\PAD.Console.Host.exe";

8行目 WinAppDriver.exe のパスの確認。異なる場合は修正
$WinAppDriverExePath='C:\Program Files (x86)\Windows Application Driver\WinAppDriver.exe';WinAppDriver.exe

9行目 ポートが競合しエラーになる場合は、変更してください
$WinAppDriverPort=4727;

19行目 WinAppDriver.exe のコンソールを隠したい場合、
-windowstyle を Minimized や、Hidden に設定
Start-Process -windowstyle 'Normal' -FilePath $WinAppDriverExePath -ArgumentList $WinAppDriverPort;  



実行方法

ダウンロードしたファイルを任意のフォルダへ展開


2021年2月22日月曜日

【解決】 WEBビューアが印刷できない。プレビューモードで表示されない。- FIleMaker

WEBビューアが印刷できない。プレビューモードで表示されない。- FIleMaker

Windows, macOS 対応。iOS(FileMaker Go)は、非対応。

Chart.js が印刷できないとか、Google Map が印刷できないとか、
WEBビューアをキャプチャして画像として保存したい場合に使用。

GoogleChrome でWEBビューアに表示されている内容をキャプチャして印刷で使用する。

WebViewerCaptureChrome.fmp12
動作検証:
FileMaker:16,17,18,19
Windows 10, macOS:10.15.6, 10.13.6
Windows:Powershell使用(Windows標準インストール)
macOS:AppleScript使用(macOS標準インストール)

サンプルファイル

※サンプルファイルは、高解像度キャプチャ対応
https://fm-aid.stores.jp/items/60327a4e2438607fc668027c

使用方法

WebViewerCaptureChrome.fmp12 を開く

画面右上の[⚙(歯車)]アイコンをクリック。
Google Chrome のパスを設定。(Chromeのインストール先を変更していなければそのままでOK)
※Google Chrome のパスは、アドレスバーに chrome://version/ と入力で確認できます。
例:
Windows:
C:\Program Files (x86)\Google\Chrome\Application\chrome.exe
macOS:
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome

-

ExampleWebViewerCaptureChrome.fmp12 を開く


「WebViewer DATA or SOURCE」に URL または、HTML を入力。

「capture[object]」ボタンでキャプチャしたpng画像(実データ)が取得できます。

「capture[path]」ボタンでキャプチャしたpng画像をファイルパスが取得できます。
※png画像はテンポラリフォルダに保存されています。

WEBビューアの式 例:

プレビュー・印刷モードの時は、キャプチャした画像を表示。
キャプチャした画像は、パスがあればその画像を優先、なければオブジェクトフィールドの画像を表示。 となっています。
詳しくは、サンプルファイル:ExampleWebViewerCaptureChrome.fmp12 を参照

/*
フィールド値が、URL,file,<HTML>どれでも表示
プレビュー・印刷モードの時は、キャプチャした画像を表示
キャプチャした画像は、パスがあればその画像を優先、なければオブジェクトフィールドの画像を表示
*/
Let([
¢mode=Get (ウインドウモード)
;¢DATA=Let(
¢source=Trim(WVCaptureChrome::WebViewerDATAorSOURCE)
;
Case ( Left ( ¢source ; 1 ) = "<" ; "data:text/html;charset=utf-8,"; "" ) & ¢source
)
;¢CPath=WVCaptureChrome::CapturePath
;¢CObj=WVCaptureChrome::CaptureObj
;¢html=
"data:text/html,
<html>
<head>
<meta charset='UTF-8'>
<meta http-equiv='X-UA-Compatible' content='IE=edge'>
<meta name='viewport' content='initial-scale=1.0' />
<style>
* {border:0; margin:0px; padding:0px;overflow:hidden;}
img {
object-fit: cover;
}
</style>
</head>
<body>
<img src='{src}' onLoad='this.style[this.width>this.height?\"width\":\"height\"]=\"100%\"'>
</body>
</html>"
];
Case ( ¢mode=2 or ¢mode=3 ;
Case (
not IsEmpty ( ¢CPath ) ; Substitute ( ¢html ; "{src}" ; "file://" & ¢CPath );
not IsEmpty ( ¢CObj ) ; Substitute ( ¢html ; "{src}" ; "data:image/png;base64," & Base64Encode ( ¢CObj ) );
¢DATA
);
¢DATA
)
)


既存ファイルからの利用方法

外部データソースに「WebViewerCaptureChrome.fmp12」を登録。

ファイル -> 管理 -> 外部データソース


新規 をクリックし「WebViewerCaptureChrome.fmp12」を選択

[OK]をクリックで登録完了。


スクリプト例: キャプチャした画像を取得

スクリプト名:Capture[object]

#{"source":"https://fm-aid.com/bbs2/viewforum.php?id=2","width":"300","height":"300"}
変数を設定 [ $source; 値:WVCaptureChrome::WebViewerDATAorSOURCE ]
変数を設定 [ $width; 値:GetLayoutObjectAttribute ( "WEB01" ; "width" ) ]
変数を設定 [ $height; 値:GetLayoutObjectAttribute ( "WEB01" ; "height" ) ]
変数を設定 [ $json; 値:Let([¢json="" ;¢json=JSONSetElement ( ¢json ; "source" ; $source ; 1 ) ;¢json=JSONSetElement ( ¢json ; "width" ; $width ; 1 ) ;¢json=JSONSetElement ( ¢json ; "height" ; $height ; 1 ) ]; ¢json ) ]
スクリプト実行 [ 「Capture(json)」 , ファイル: 「WebViewerCaptureChrome」; 引数: $json ]
フィールド設定 [ WVCaptureChrome::CaptureObj; Get(スクリプトの結果) ]

引数(json)を作成し、「WebViewerCaptureChrome.fmp12」のスクリプト:Capture(json) を実行

引数:
{
"source":"HTML または、URL",
"width":"キャプチャする横幅",
"height":"キャプチャする縦の長さ"
}

例:
{
"source":"https://fm-aid.com/bbs2/viewforum.php?id=2",
"width":"300",
"height":"300"
}