title: Applescript to remove items from dock
body: <p>I'm trying to remove (all) items from the dock. I can remove them by name like so:</p>
  
  <pre><code>tell application "System Events"
      tell UI element "Launchpad" of list 1 of process "Dock"
          perform action "AXShowMenu"
          click menu item "Remove from Dock" of menu 1
      end tell
  end tell
  </code></pre>
  
  <p>But I'd like to pull the list of current items and iterate over them.
  <a href="https://stackoverflow.com/questions/14245301/can-applescript-list-all-the-applications-placed-in-the-dock">This stack overflow question</a> seems to cover how to get the list. What I'd like to do is tweak the above code to operate inside of a loop. I would guess that referencing the current item of the list inside the loop would be done with "thisRecord". I think I'm misunderstanding how to convert "thisRecord" into something I can reference within system events. </p>
  
  <pre><code>set plistpath to (path to preferences folder as text) &amp; "com.apple.dock.plist"
  
  tell application "System Events"
      set plistContents to contents of property list file plistpath
      set pListItems to value of plistContents
  end tell
  set persistentAppsList to |persistent-apps| of pListItems
  
  set dockAppsList to {}
  repeat with thisRecord in persistentAppsList
      set end of dockAppsList to |file-label| of |tile-data| of thisRecord
      tell application "System Events"
          tell UI element application thisRecord
              perform action "AXShowMenu"
              click menu item "Remove from Dock" of menu 1
          end tell
      end tell
  end repeat  
  </code></pre>