Power Automate Desktop無償版のフローを無限ループで自動実行させる方法
方法
1分ごとにチェックすることで毎日決まった時間やファイルの存在 5分ごとに動かすサンプルです
power automate desktop を常時起動しておく必要があります
コピペして使用してください
DateTime.GetCurrentDateTime.Local DateTimeFormat: DateTime.DateTimeFormat.DateAndTime CurrentDateTime=> CurrentDateTime
SET NewVar TO $'''22:00'''
DateTime.Add DateTime: CurrentDateTime TimeToAdd: 5 TimeUnit: DateTime.TimeUnit.Minutes ResultedDate=> ScheduledDateTime
LOOP LoopIndex FROM 1 TO 11 STEP 0
IF (File.IfFile.Exists File: $'''D:\\data2\\JIS.txt''') THEN
Display.ShowMessageDialog.ShowMessageWithTimeout Title: ScheduledDateTime Icon: Display.Icon.None Buttons: Display.Buttons.OK DefaultButton: Display.DefaultButton.Button1 IsTopMost: False Timeout: 3 ButtonPressed=> ButtonPressed
END
DateTime.GetCurrentDateTime.Local DateTimeFormat: DateTime.DateTimeFormat.DateAndTime CurrentDateTime=> CurrentDateTime
IF CurrentDateTime >= ScheduledDateTime THEN
Display.ShowMessageDialog.ShowMessageWithTimeout Title: ScheduledDateTime Message: ScheduledDateTime Icon: Display.Icon.None Buttons: Display.Buttons.OK DefaultButton: Display.DefaultButton.Button1 IsTopMost: False Timeout: 3 ButtonPressed=> ButtonPressed
@@flowname: 'n'
External.RunFlow FlowId: '14c583cb-d750-41d3-bc01-c87a6e7d1244' WaitToComplete: True
DateTime.Add DateTime: ScheduledDateTime TimeToAdd: 5 TimeUnit: DateTime.TimeUnit.Minutes ResultedDate=> ScheduledDateTime
END
Text.ConvertDateTimeToText.FromDateTime DateTime: CurrentDateTime StandardFormat: Text.WellKnownDateTimeFormat.ShortTime Result=> FormattedDateTime
IF NewVar = FormattedDateTime THEN
Display.ShowMessageDialog.ShowMessageWithTimeout Title: ScheduledDateTime Message: FormattedDateTime Icon: Display.Icon.None Buttons: Display.Buttons.OK DefaultButton: Display.DefaultButton.Button1 IsTopMost: False Timeout: 3 ButtonPressed=> ButtonPressed
END
WAIT 60
END
説明
- 現在日時を取得:
DateTime.GetCurrentDateTime.Local DateTimeFormat: DateTime.DateTimeFormat.DateAndTime CurrentDateTime => CurrentDateTime- 現在のローカル日時を取得し、変数
CurrentDateTimeに保存します。
- 現在のローカル日時を取得し、変数
- 新しい変数を設定:
SET NewVar TO $'''22:00'''- 文字列値
'22:00'を持つ新しい変数NewVarを設定します。
- 文字列値
- 現在日時に5分を追加:
DateTime.Add DateTime: CurrentDateTime TimeToAdd: 5 TimeUnit: DateTime.TimeUnit.Minutes ResultedDate => ScheduledDateTime- 現在日時 (
CurrentDateTime) に5分を追加し、その結果をScheduledDateTimeに保存します。
- 現在日時 (
- ループ処理:
LOOP LoopIndex FROM 1 TO 11 STEP 0LoopIndexが1から11までの範囲で、ステップ0(つまり、ループの終了条件に達するまで無限に実行)でループを開始します。
- 特定のファイルの存在チェック:
IF (File.IfFile.Exists File: $'''D:\\data2\\JIS.txt''') THEN Display.ShowMessageDialog.ShowMessageWithTimeout Title: ScheduledDateTime Icon: Display.Icon.None Buttons: Display.Buttons.OK DefaultButton: Display.DefaultButton.Button1 IsTopMost: False Timeout: 3 ButtonPressed => ButtonPressedENDD:\\data2\\JIS.txtファイルが存在するかどうかをチェックし、存在する場合はScheduledDateTimeをタイトルとするメッセージダイアログを表示します。このダイアログは3秒間表示されます。
- 現在日時の再取得:
DateTime.GetCurrentDateTime.Local DateTimeFormat: DateTime.DateTimeFormat.DateAndTime CurrentDateTime => CurrentDateTime- ループの各反復で、現在のローカル日時を再取得します。
- スケジュールされた日時のチェック:
IF CurrentDateTime >= ScheduledDateTime THENDisplay.ShowMessageDialog.ShowMessageWithTimeout Title: ScheduledDateTime Message: ScheduledDateTime Icon: Display.Icon.None Buttons: Display.Buttons.OK DefaultButton: Display.DefaultButton.Button1 IsTopMost: False Timeout: 3 ButtonPressed => ButtonPressed@@flowname: 'n' External.RunFlow FlowId: '14c583cb-d750-41d3-bc01-c87a6e7d1244' WaitToComplete: True DateTime.Add DateTime: ScheduledDateTime TimeToAdd: 5 TimeUnit: DateTime.TimeUnit.Minutes ResultedDate => ScheduledDateTimeEND - 現在日時の短時間形式の文字列変換:
Text.ConvertDateTimeToText.FromDateTime DateTime: CurrentDateTime StandardFormat: Text.WellKnownDateTimeFormat.ShortTime Result => FormattedDateTimeCurrentDateTimeを短時間形式(例:’22:00’)の文字列に変換し、その結果をFormattedDateTimeに保存します。
- 特定の時間のチェック:
IF NewVar = FormattedDateTime THENDisplay.ShowMessageDialog.ShowMessageWithTimeout Title: ScheduledDateTime Message: FormattedDateTime Icon: Display.Icon.None Buttons: Display.Buttons.OK DefaultButton: Display.DefaultButton.Button1 IsTopMost: False Timeout: 3 ButtonPressed => ButtonPressedENDFormattedDateTimeがNewVarと等しい場合、メッセージダイアログを表示します。
- ウェイト:
WAIT 60- ループの各反復で60秒間待機します。
このプログラムは、一定の間隔で現在の時間をチェックし、特定の条件が満たされた場合にメッセージを表示。また、特定のフローを実行するトリガーとしても機能します。







ディスカッション
コメント一覧
まだ、コメントがありません