Advertisement
MichalMMac

Zipper

Jul 26th, 2013
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. on extensionSplitter(file_name)
  2.     set savedDelimiters to AppleScript's text item delimiters
  3.     set AppleScript's text item delimiters to "."
  4.    
  5.     set splitted_text to every text item of file_name
  6.    
  7.     if (count of items of splitted_text) is greater than 1 then
  8.         set my_result to {fname:items 1 through -2 of splitted_text as text, extension:last item of splitted_text}
  9.     else
  10.         set my_result to {fname:splitted_text as text, extension:missing value}
  11.     end if
  12.    
  13.     set AppleScript's text item delimiters to savedDelimiters
  14.     return my_result
  15.    
  16. end extensionSplitter
  17.  
  18. -- + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
  19.  
  20. on zipIt(path_one, path_two, archive_name)
  21.     do shell script "zip -j " & archive_name & ".zip " & path_one & " " & path_two
  22. end zipIt
  23.  
  24. -- + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
  25.  
  26. on run
  27.     -- Config
  28.     set first_extension to {"jpg", "jpeg"}
  29.     set secondExtension to "eps"
  30.    
  31.     tell application "Finder"
  32.        
  33.         set the_folder to (choose folder with prompt "Vyber složku se soubory")
  34.         set all_files to every file of the_folder where name extension is in first_extension
  35.        
  36.         repeat with ifile in all_files
  37.             set first_file_breakdown to my extensionSplitter(name of ifile)
  38.             set second_file_name to fname of first_file_breakdown & "." & secondExtension
  39.            
  40.            
  41.             if second_file_name is in (name of every file of the_folder) then
  42.                 set ipath to POSIX path of the_folder
  43.                 my zipIt(ipath & name of ifile, ipath & second_file_name, ipath & fname of first_file_breakdown)
  44.             end if
  45.            
  46.         end repeat
  47.        
  48.     end tell
  49. end run
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement