Wednesday, October 03, 2012

How to delete all Extended Attributes in HFS+ (OS X)

Here’s a little AppleScript Droplet to clear all Extended Attributes in OS X. This is useful to delete the famous com.apple.quarantine attribute.

  • Create a new script in AppleScript Editor
  • Copy and paste the code
  • Save as an application under the name Clear-Extended-Attributes.app

Then, you can simply drag an drop files or folders on the application.

(*

------------------------------------------------------------------------

 

C L E A R   E X T E N D E D   A T T R I B U T E S

 

Delete all extended attributes from one or many files

under OS X

 

Author : Jean-Pierre.Paradis@fsa.ulval.ca

Date : 2 octobre 2012

Version : 1.00

Language : AppleScript (Droplet)

------------------------------------------------------------------------

*)

 

tell application "Finder" to display alert "Please drop file(s) or folder(s) on this application to delete all extended attributes" as informational

 

on open Dropped_Things

      repeat with Item_index from 1 to the count of Dropped_Things

             set Dropped_Item to item Item_index of Dropped_Things

             set Dropped_Item_Info to info for Dropped_Item

             if folder of the Dropped_Item_Info is true then

                   Process_Folder(Dropped_Item)

             else

                   Process_File(Dropped_Item)

             end if

      end repeat

end open

 

-- this sub-routine processes files

on Process_File(File_Item)

      set File_POSIX_path to POSIX path of File_Item

      set File_Item_Info to info for File_Item

      display dialog "Processing '" & (name of File_Item_Info) & "' ..." with icon note buttons {"Ok"} with title "Clear Extended Attributes" giving up after 1

      do shell script "xattr -c '" & File_POSIX_path & "'"

end Process_File

 

-- this sub-routine processes folders

on Process_Folder(Folder_Item)

      set Folder_Content to list folder Folder_Item without invisibles

      repeat with Item_index from 1 to the count of Folder_Content

             set Folder_Content_Item to alias ((Folder_Item as Unicode text) & (item Item_index of Folder_Content))

             set Folder_Content_Item_Info to info for Folder_Content_Item

             if folder of Folder_Content_Item_Info is true then

                   Process_Folder(Folder_Content_Item)

             else

                   Process_File(Folder_Content_Item)

             end if

      end repeat

end Process_Folder