Äskeiset muutokset - Haku:

Homekoti

Tuomas Rosberg

pmwiki.org

edit SideBar

Mac /

StripResources

 (*
 StripResources

 Strip HFS resource fork from image files.
 The file types accepted to be stripped are gif, jpeg, jpeg2000 and png.
 Usually the resource fork of an image file contains a custom icon.
 The resource fork is useless, if an image file is sended outside the Mac platform.
 Most image manipulation apps can be set not to save anything into resource fork.
 If you still have images with resources which need to be stripped, this script does it.

 Author Tuomas Rosberg 2005
 Public domain. No warranty of any kind. 
 The author is not responsible for any damages the user causes to her files with this script.
 Written and tested on Mac OS X 10.3. Requires Mac OS X BSD subsystem (is in default installation).
 Functionality is based on BSD copy command (cp). It does not copy resource fork or HFS file type or creator.

 Paste into a Script Editor window. Save as an application, without opening screen.
 *)

 -- Script run from Finder or Script menu.
 on run
   tell application "Finder"
     set theItems to selection
     if (count of theItems) is 0 then
       my aDialog() -- Help text
     else if (count of theItems) is 1 then -- Is it the application file of this process?
       if (first item of theItems as alias) is (path to me) then -- Yes it was.
         my aDialog()
       else -- No it wasn't.
         my stripResources(theItems)
       end if
     else -- There more than one items in the selection
       my stripResources(theItems)
     end if
   end tell
 end run

 ------------ Or ------------

 -- Items dropped onto the script app.
 on open theItems
   my stripResources(theItems)
 end open

 ------------ The main functionality ------------

 on stripResources(theItems)
   repeat with anItem in theItems 
     set anItem to anItem as alias -- stupid AppleScript
     if fileTest(anItem) is true then
       set aString to random number from 10000 to 99999
       tell application "Finder"
         set parentFolder to container of anItem as alias
         set filePath to "\"" & POSIX path of anItem & "\""
         set temp to filePath
         set parentFolder to POSIX path of parentFolder
         set newName to "\"" & parentFolder & (aString as string) & "\""
       end tell
       try
         do shell script "mv -f " & temp & " " & newName & " | cp " & newName & " " & filePath & "| rm  -f " & newName 
       end try
     end if
   end repeat
 end stripResources

 ------------ Utility handlers ------------


 -- Test if a Finder item is not a folder or application but an image file of accepted type.
 on fileTest(anItem)
   ignoring case -- to accept both "JPG" and "jpg"
     set oldDelimiters to AppleScript's text item delimiters
     set AppleScript's text item delimiters to "." -- to get file extension part of file name
     tell application "Finder"
       set aName to name of anItem
       if class of item anItem is document file then -- not a folder etc.
         if locked of anItem is false then -- to honour HFS locked attribute if set
           if file type of anItem is in {"JPEG", "GIFf", "jp2 ", "JPX ", "PNGf", "PNG "} then -- file types  acceptable 
             return true
           else if last text item of aName is in {"jpg", "gif", "jpeg", "jp2", "png"} then -- file  extensions acceptable 
             return true
           else
             return false -- file is not an image in one of these Internet formats.
           end if
         else -- file is locked
           return false
         end if
       else -- file is not a document file
         return false
       end if
     end tell
     set AppleScript's text item delimiters to oldDelimiters
   end ignoring
 end fileTest


 -- Help text
 on aDialog()
   display dialog ¬
     "Pudota skriptin päälle kuvatiedostoja " & return & ¬
     "joiden resurssihaaran tahdot poistaa." & return & return & ¬
     "Voit myös valita kohteet Finderissa ja" & return & ¬
     " ajaa skriptin Skriptivalikosta." buttons "OK" with icon note default button 1
 end aDialog

 (*
 If it is more convenient, the dialog text in English:
 "If you want to the resource forks of 
 some picture files, drag 'n drop them 
 on this script application. Or select  
 the files in the Finder and run this 
 script from Script menu."  
 *)
Muokkaa - Historia - Tulosta - Äskeiset muutokset - Haku
Sivua on viimeksi muokattu 06.11.2009, 05:42