Advertisement
falsie

AppleScript recursion test

Aug 17th, 2012
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. global stack --スタック
  2. global stackP --スタックポインタ
  3.  
  4. on run
  5.     set stack to {} ---スタックを初期化---
  6.     set stackP to 1 ------------------------
  7.     exposeUIElements(application "System Events")
  8. end run
  9.  
  10. on exposeUIElements(source)
  11.     tell application "System Events"
  12.         set stack to stack & {source} --引数をスタックに追加
  13.        
  14.         set uiList to UI elements of source
  15.        
  16.         if (count uiList) is 0 then
  17.             display dialog "No UI Elements."
  18.             return source
  19.         end if
  20.        
  21.         -- choose from listに表示する文字列リストを作成
  22.         set nameList to {}
  23.         repeat with i from 1 to count uiList
  24.             set elem to item i of uiList
  25.             if i < 10 then -- iが一桁のとき頭に0つけてるだけ
  26.                 set num to "0" & i as string
  27.             else
  28.                 set num to i as string
  29.             end if
  30.             set nameList to nameList & (num & ": " & "[" & class of elem & "]" & space & name of elem & " (" & ((count (UI elements of elem)) as string) & " item)")
  31.         end repeat
  32.        
  33.         -- choose from listを表示、次のオブジェクトを決定、スタックポインタを変更
  34.         tell application "Finder" to choose from list nameList with title ("(" & (class of source) & ") " & (name of source)) with prompt "Expose UI Elements in selected object."
  35.         if result is not false then
  36.             set target to (word 1 of item 1 of result) as number
  37.             set next to item target of uiList
  38.             set stackP to stackP + 1
  39.         else
  40.             set stackP to stackP - 1
  41.             if stackP is 0 then
  42.                 return false
  43.             end if
  44.            
  45.             set stack to items 1 thru stackP of stack
  46.             set next to last item of stack
  47.         end if
  48.        
  49.         -- 再帰
  50.         my exposeUIElements(next)
  51.     end tell
  52. end exposeUIElements
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement