Power Automate Desktop †

更新日2024-11-08 (金) 11:24:35
作成日:2024年11月7日
↑

インストール †

既に入っているので、power automateでアプリを検索する

以下からPower Automate インストーラーをダウンロードしてインストールする。

↑

起動 †

起動するとMSアカウントでログインを求められるので、ログインする。

起動すると以下のような画面にになる

起動.png

自分のフローに移動して、「新しいフロー」を選択する。

起動2.png

フローを作成する画面で、フロー名を入力して作成ボタンを押す。

起動3.png

以下の作成画面が開く

&ref(): File not found: "起動4.png" at page "Windows_Router Memo/Power Automate Desktop";

左ペインのアクションから中央のペインのMainのペインにドラックして並べていく

起動5.png

↑

サンプル作成 †

↑

アクション内容 †

以下の手順でアプリケーションを起動させ、起動画面を表示させる。

  1. 目的のアプリケーションを起動
  2. 所定の画面が表示するまで待機
  3. メニューバーから目的のメニュ−を選択(階層になっているため、1階層づつ選択個所を指定)
  4. 所定の画面が表示するまで待機
  5. 矢印キーを2つ押して、Enterキーを入力
  6. テキストフィールドにファーカスをあてる
  7. テキストフィールドに文字列を入力して、Enterキーを入力
  8. 二つ目のテキストフィールドに文字列を入力して、Enterキーを入力
↑

アクション内容入力 †

アプリケーションの実行.png

Window待機1.png

メニュー選択.png

キー入力.png

テキストボックス入力.png

↑

ショートカット作成 †

# Power Automate for desktopのフローを実行するPowerShellスクリプト
#   @param [string] $flowName 実行するフロー名
#   @param [bool] $flgExit PAD終了フラグ
#
# 動作確認:バージョン 2.40.157.24023 (インストーラー版)
#

Param(
  
  [bool]$flgExit = $false
)

#Power Automate for desktop起動
Start-Process -FilePath "ms-powerautomate://"

#UI Automation
Add-Type -AssemblyName "UIAutomationClient"
Add-Type -AssemblyName "UIAutomationTypes"
$uiAuto = [System.Windows.Automation.AutomationElement]
$pcdn = [System.Windows.Automation.PropertyCondition]
$acdn = [System.Windows.Automation.AndCondition]
$tree = [System.Windows.Automation.TreeScope]
$iptn = [System.Windows.Automation.InvokePattern]::Pattern
$wptn = [System.Windows.Automation.WindowPattern]::Pattern
$icptn = [System.Windows.Automation.ItemContainerPattern]::Pattern
$siptn = [System.Windows.Automation.ScrollItemPattern]::Pattern
$selptn = [System.Windows.Automation.SelectionItemPattern]::Pattern
$root = $uiAuto::RootElement

#Power Automate for desktopウィンドウ取得
$cndPadWindowId = New-Object $pcdn($uiAuto::AutomationIdProperty, "ConsoleMainWindow")
$cndPadWindowClassName = New-Object $pcdn($uiAuto::ClassNameProperty, "WinAutomationWindow")
$cndPadWindow = New-Object $acdn($cndPadWindowId, $cndPadWindowClassName)
do{
  Start-Sleep -m 200
  $elmPadWindow = $root.FindFirst($tree::Children, $cndPadWindow)
}while($elmPadWindow -eq $null)

#タブ取得
$cndTab = New-Object $pcdn($uiAuto::AutomationIdProperty, "ProcessesTabControl")
$elmTab = $elmPadWindow.FindFirst($tree::Subtree, $cndTab)

#タブ項目取得・選択
if($elmTab -ne $null){
  $cndTabItem = New-Object $pcdn($uiAuto::AutomationIdProperty, "MyFlowsTab")
  $elmTabItem = $elmTab.FindFirst($tree::Children, $cndTabItem)
  if($elmTabItem -ne $null){
    $selTabItem = $elmTabItem.GetCurrentPattern($selptn)
    $selTabItem.Select()
  }
}

#データグリッド取得
if($elmPadWindow -ne $null){
  $cndDataGrid = New-Object $pcdn($uiAuto::AutomationIdProperty, "MyFlowsListGrid")
  $elmDataGrid = $elmPadWindow.FindFirst($tree::Subtree, $cndDataGrid)
}

#データ項目取得・選択
if($elmDataGrid -ne $null){
  $icDataGrid = $elmDataGrid.GetCurrentPattern($icptn)
  $elmDataItem = $icDataGrid.FindItemByProperty($null, $uiAuto::NameProperty, "KpacsStart") #←ここに名前を入れる。ただし必ず半角
  if($elmDataItem -ne $null){
    $siDataItem = $elmDataItem.GetCurrentPattern($siptn)
    $siDataItem.ScrollIntoView()
    $selDataItem = $elmDataItem.GetCurrentPattern($selptn)
    $selDataItem.Select()
  }
}

#実行ボタン取得・押下
if($elmDataItem -ne $null){
  $cndStartButton = New-Object $pcdn($uiAuto::AutomationIdProperty, "StartFlowButton")
  $elmStartButton = $elmDataItem.FindFirst($tree::Subtree, $cndStartButton)
  if($elmStartButton -ne $null){
    $ivkStartButton = $elmStartButton.GetCurrentPattern($iptn)
    $ivkStartButton.Invoke()
  }
}

if($flgExit){
  #フロー終了待ち
  if($elmStartButton -ne $null){
    do{
      Start-Sleep -m 800
    }while($elmStartButton.GetCurrentPropertyValue($uiAuto::IsEnabledProperty) -eq $false)
  }

  #Power Automate for desktop終了
  $winPadWindow = $elmPadWindow.GetCurrentPattern($wptn)
  $winPadWindow.Close()
}

さらに、以下のようなバッチを作成してそのショートカットを作成する

powershell -ExecutionPolicy Bypass -File "kidou.ps1"
↑

参考(ショートカット) †


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