AppleScript Repeat

[repeat] 基本

【スクリプトエディタで開く】|

repeat
  ####終了条件を入れないと無限ループ
  exit repeat
end repeat

【スクリプトエディタで開く】|

####今の時間
set dateNow to my (current date)
log dateNow
###指定の時間は10秒後
set dateEndTime to dateNow + 10
log dateEndTime

repeat
  ##時間を取って
  set dateNow to my (current date)
  ##同じか 経過したら
  if dateEndTime ≤ dateNow then
    ###リピートを終わる
    exit repeat
  end if
  delay 1
end repeat

【スクリプトエディタで開く】|

repeat 10 times
  ###回数指定
end repeat

【スクリプトエディタで開く】|

set numRepatTime to 20 as integer
repeat numRepatTime times
  
  set dateNow to my (current date)
  
  delay 1
end repeat

【スクリプトエディタで開く】|

set numCntNo to 0 as integer
###TUREになったら終了
repeat until (numCntNo = 10)
  set numCntNo to numCntNo + 1 as integer
  log numCntNo
  delay 1
end repeat

【スクリプトエディタで開く】|

set numCntNo to 0 as integer
###FALSEになったら終了
repeat while (numCntNo < 10)
  set numCntNo to numCntNo + 1 as integer
  log numCntNo
  
  delay 1
end repeat

|

[repeat] repeat with in (リストのアイテムを順番にリピート内の処理に渡す)


set listArray to {1, 3, 5, 7, 9, 11}


repeat with objectListItem in listArray
log objectListItem
end repeat

|

[repeat] repeat with from to (渡す数値を指定)

リピート内の処理に渡す数値を指定できる=リピートを抜ける回数を指定出来る

##全て
repeat with numNo from 0 to 10
log numNo
end repeat

###偶数のみ
repeat with numNo from 2 to 10 by 2
log numNo
end repeat

###奇数のみ
repeat with numNo from 1 to 10 by 2
log numNo
end repeat

|

[repeat] repeat while (条件が必要 〜になるまで繰り返す)

repeat while -->条件式
-->条件が必要
end repeat

tell application "Terminal"
launch
activate
set objWindowID to (do script "\n\n")

do script "\n\n" in objWindowID
set boolTabStatus to busy of objWindowID as boolean
end tell

(*
objWindowIDWindowIDTabIDが入っているので
objWindowIDに対してbusyを確認する事で
処理が終わっているか?がわかる
*)
-->busyの間は繰り返す=falseになったら抜ける
repeat while boolTabStatus is true
tell application "Terminal"
-->busyステータスを確認
set boolTabStatus to busy of objWindowID as boolean
log boolTabStatus
end tell
delay 1
end repeat

|

[repeat]repeat times (繰り返す回数を指定)

最初から繰り返す回数を指定



set numRepatTime to 5 as integer
repeat numRepatTime times
-->指定回数のみ繰り返す
end repeat



サンプルは『最大で5回』=5秒待つ その前にbusyがfalseになれば抜ける

tell application "Terminal"
launch
activate
set objWindowID to (do script "\n\n")

do script "\n\n" in objWindowID
end tell

(*
objWindowIDWindowIDTabIDが入っているので
objWindowIDに対してbusyを確認する事で
処理が終わっているか?がわかる
*)
-->5回繰り返す
set numRepatTime to 5 as integer
repeat numRepatTime times
tell application "Terminal"
-->busyステータスを確認
set boolTabStatus to busy of objWindowID as boolean
log boolTabStatus
end tell
if boolTabStatus is false then
exit repeat
--->このリピートを抜けて次の処理へ
else if boolTabStatus is true then
delay 1
--->busyなのであと1秒まつ
end if
delay 1
end repeat

|

[repeat] repeat until (条件が必要 〜になるまで繰り返す)

true または falseになる条件が必要



repeat until booleanStatement
-->true または falseになる条件が必要
end repeat



tell application "Terminal"
launch
activate
set objWindowID to (do script "\n\n")
delay 2
do script "\n" in objWindowID
-->ここではboolTabStatusTrueになる
set boolTabStatus to busy of objWindowID
log boolTabStatus
end tell

(*
objWindowIDWindowIDTabIDが入っているので
objWindowIDに対してbusyを確認する事で
処理が終わっているか?がわかる
*)
-->busyFlase=処理が終わっているになったら抜ける
repeat until boolTabStatus is false
tell application "Terminal"
-->busyステータスを確認
set boolTabStatus to busy of objWindowID as boolean
log boolTabStatus
end tell
delay 3
end repeat

|

[repeat] repeat (exit repeat 条件が必要)

永遠にリピートしちゃうので
exit repeat 条件-->リピートを終了する条件が必要



repeat
-->exit repeat 条件が必要
end repeat



tell application "Terminal"
launch
activate
set objWindowID to (do script "\n\n")
delay 2
do script "\n" in objWindowID
end tell

(*
objWindowIDWindowIDTabIDが入っているので
objWindowIDに対してbusyを確認する事で
処理が終わっているか?がわかる
*)

repeat
tell application "Terminal"
set boolTabStatus to busy of objWindowID
end tell
if boolTabStatus is false then
exit repeat
--->このリピートを抜けて次の処理へ
else if boolTabStatus is true then
delay 3
--->busyなのであと3秒まつ
end if
end repeat

|

その他のカテゴリー

Acrobat Acrobat Annotation Acrobat Dialog Acrobat Form Acrobat JS Acrobat Open Acrobat Plugin Acrobat python Acrobat Reader Acrobat Sequ Acrobat Stamps Admin Admin Account Admin Apachectl Admin configCode Admin Device Management Admin LaunchServices Admin Locationd Admin loginitem Admin Maintenance Admin Permission Admin Pkg Admin Power Management Admin Printer Admin SetUp Admin SMB Admin System Information Admin Tools Admin Users Admin Volumes Adobe Apple AppleScript AppleScript Guide AppleScript Accessibility AppleScript AppKit AppleScript Applications AppleScript AppStore AppleScript Archive AppleScript Attributes AppleScript Automator AppleScript AVAsset AppleScript AVconvert AppleScript AVFoundation AppleScript AVURLAsset AppleScript BackUp AppleScript Barcode AppleScript Bash AppleScript Basic AppleScript Basic Path AppleScript Bluetooth AppleScript BOX AppleScript Browser AppleScript Calendar AppleScript CD/DVD AppleScript Choose AppleScript Chrome AppleScript CIImage AppleScript CloudStorage AppleScript Color AppleScript com.apple.LaunchServices.OpenWith AppleScript Console AppleScript Contacts AppleScript CotEditor AppleScript CURL AppleScript current application AppleScript Date&Time AppleScript delimiters AppleScript Desktop AppleScript Device AppleScript Disk AppleScript do shell script AppleScript Dock AppleScript DropBox AppleScript eMail AppleScript Encode Decode AppleScript Error AppleScript EXIFData AppleScript ffmpeg AppleScript File AppleScript Finder AppleScript Firefox AppleScript Folder AppleScript Fonts AppleScript GIF AppleScript HTML AppleScript Icon AppleScript Illustrator AppleScript Image Events AppleScript Image2PDF AppleScript ImageOptim Applescript iWork AppleScript Javascript AppleScript Jedit AppleScript Json AppleScript Label AppleScript List AppleScript locationd AppleScript LRC AppleScript LSSharedFileList AppleScript m3u8 AppleScript MakePDF AppleScript Map AppleScript Math AppleScript Microsoft AppleScript Microsoft Edge AppleScript Microsoft Excel AppleScript Mobileconfig AppleScript Mouse AppleScript Movie AppleScript Music AppleScript NetWork AppleScript Notes AppleScript NSArray AppleScript NSBitmapImageRep AppleScript NSBundle AppleScript NSCFBoolean AppleScript NSCharacterSet AppleScript NSColor AppleScript NSColorList AppleScript NSData AppleScript NSDictionary AppleScript NSError AppleScript NSEvent AppleScript NSFileAttributes AppleScript NSFileManager AppleScript NSFont AppleScript NSFontManager AppleScript NSImage AppleScript NSIndex AppleScript NSKeyedArchiver AppleScript NSKeyedUnarchiver AppleScript NSLocale AppleScript NSMutableArray AppleScript NSMutableDictionary AppleScript NSMutableString AppleScript NSNotFound AppleScript NSNumber AppleScript NSOpenPanel AppleScript NSPasteboard AppleScript NSPDFImageRep AppleScript NSpoint AppleScript NSPredicate AppleScript NSRange AppleScript NSRegularExpression AppleScript NSRunningApplication AppleScript NSScreen AppleScript NSSize AppleScript NSString AppleScript NSStringCompareOptions AppleScript NSTask AppleScript NSTimeZone AppleScript NSURL AppleScript NSURL File AppleScript NSURLBookmark AppleScript NSURLComponents AppleScript NSURLResourceKey AppleScript NSUserDefaults AppleScript NSUUID AppleScript NSView AppleScript NSWorkspace AppleScript Numbers AppleScript OAuth AppleScript ObjC AppleScript OneDrive AppleScript Osax AppleScript PDF AppleScript PDFAnnotationWidget AppleScript PDFContext AppleScript PDFDisplayBox AppleScript PDFDocumentPermissions AppleScript PDFKit AppleScript PDFnUP AppleScript PDFOutline AppleScript Photos AppleScript Photoshop AppleScript Plist System Events AppleScript PostScript AppleScript prefPane AppleScript Preview AppleScript Python AppleScript QR AppleScript QR Decode AppleScript QuickLook AppleScript QuickTime AppleScript record AppleScript Regular Expression AppleScript Reminders AppleScript ReName AppleScript Repeat AppleScript RTF AppleScript Safari AppleScript SaveFile AppleScript ScreenCapture AppleScript ScreenSaver AppleScript Script Editor AppleScript Script Menu AppleScript Shortcuts AppleScript Shortcuts Events AppleScript Sort AppleScript Sound AppleScript Spotlight AppleScript SRT AppleScript StandardAdditions AppleScript stringByApplyingTransform AppleScript System Events AppleScript System Settings AppleScript TemporaryItems AppleScript Terminal AppleScript Text AppleScript Text CSV AppleScript Text TSV AppleScript TextEdit AppleScript Translate AppleScript Trash AppleScript Twitter AppleScript UI AppleScript Unit Conversion AppleScript UTType AppleScript valueForKeyPath AppleScript Video AppleScript VisionKit AppleScript Visual Studio Code AppleScript webarchive AppleScript webp AppleScript Wifi AppleScript XML AppleScript XML EPUB AppleScript XML OPML AppleScript XML Plist AppleScript XML RSS AppleScript XML SVG AppleScript XML TTML AppleScript XML webloc AppleScript YouTube AppleScript Zero Suppress Applications Barcode OnLine Tools CityCode Design iPhone List Logs lsappinfo Memo Music perl PlistBuddy pluginkit postalcode ReadMe SF Symbols character id SF Symbols Entity sips Skype Slack sqlite TCC Tools Typography Video Wacom zoom