Skip to content

Instantly share code, notes, and snippets.

@michal-majchrzycki
Created May 2, 2018 20:13
Show Gist options
  • Save michal-majchrzycki/cff035170540919dcbc736a050f0d717 to your computer and use it in GitHub Desktop.
Save michal-majchrzycki/cff035170540919dcbc736a050f0d717 to your computer and use it in GitHub Desktop.
on run {input, parameters}
set foldersList to {"DerivedData", "Archives", "iOS DeviceSupport", "CoreSimulator", "com.apple.dt.Xcode", "Backup"}
set choseFoldersToDelete to (choose from list foldersList with title "Pick Xcode folders to delete" with prompt "Automator will remove files from selected folders to Trash" default items "None" OK button name "Next" cancel button name "Cancel" with multiple selections allowed)
if choseFoldersToDelete is false then error number -128
set theAlertText to "You've picked files from folders:"
set saveTID to text item delimiters
set text item delimiters to ", "
set theAlertMessage to choseFoldersToDelete as text
set text item delimiters to saveTID
display alert theAlertText message theAlertMessage as critical buttons {"Cancel", "Delete files!"} default button "Delete files!" cancel button "Cancel"
if theAlertText is false then error number -128
tell application "Finder"
repeat with a from 1 to length of choseFoldersToDelete
set pickedItem to item a of choseFoldersToDelete
if pickedItem is "DerivedData" then move every item of "~/Library/Developer/Xcode/DerivedData" to trash
if pickedItem is "Archives" then move every item of "~/Library/Developer/Xcode/Archives" to trash
if pickedItem is "iOS DeviceSupport" then move every item of "~/Library/Developer/Xcode/iOS DeviceSupport" to trash
if pickedItem is "CoreSimulator" then move every item of "~/Library/Developer/CoreSimulator" to trash
if pickedItem is "com.apple.dt.Xcode" then move every item of "~/Library/Caches/com.apple.dt.Xcode" to trash
if pickedItem is "Backup" then move every item of "~/Library/Application Support/MobileSync/Backup" to trash
end repeat
end tell
return input
end run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment