SHARE
TWEET

Hazel logic compression script

letterama Mar 1st, 2019 (edited) 153 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. on hazelProcessFile(theFile)
  2.    
  3.     set theProjectFiles to {}
  4.     set thisFile to {}
  5.     set theBigScript to ""
  6.     tell application "Finder"      
  7.         set file_list to entire contents of theFile
  8.     end tell
  9.    
  10.     repeat with anItem in file_list
  11.         set thisFile to getPath(anItem)
  12.         if (item 3 of thisFile) contains "logic" then
  13.             set end of theProjectFiles to (anItem as alias)
  14.            
  15.         else if (item 3 of thisFile contains "wav") or (item 3 of thisFile contains "aif") or (item 3 of thisFile contains "aiff") then
  16.            
  17.             set theBigScript to (theBigScript & "/usr/local/bin/flac -s -f -V --lax --best --delete-input-file '" & (POSIX path of (anItem as alias)) & "' -o '" & (POSIX path of (item 1 of thisFile)) & (item 2 of thisFile) & "." & (item 3 of thisFile) & ".flac' ; ")
  18.            
  19.         end if
  20.        
  21.     end repeat
  22.    
  23.     repeat with theProject in theProjectFiles
  24.         set thisFile to getPath(theProject)
  25.        
  26.         tell application "Finder" to set theContainer to container of theProject
  27.        
  28.         do shell script ("mv '" & (POSIX path of (theProject as alias)) & "' '" & (POSIX path of (theContainer as alias)) & (item 2 of thisFile) & "." & (item 3 of thisFile) & ".compressed'")
  29.     end repeat
  30.    
  31.     do shell script theBigScript
  32.    
  33. end hazelProcessFile
  34.  
  35. on getPath(input)
  36.    
  37.     -- this subroutine accepts an alias as input and returns an array with three items, a file path (as string), a filename stripped of extensions, and a file extension
  38.    
  39.     set filePath to (input as string)
  40.    
  41.     try
  42.         set oldDelims to AppleScript's text item delimiters -- save their current state
  43.         set AppleScript's text item delimiters to {":"} -- declare new delimiters
  44.         set theFileName to (last text item of filePath)
  45.         set AppleScript's text item delimiters to oldDelims -- restore them
  46.     on error
  47.         set AppleScript's text item delimiters to oldDelims -- restore them in case something went wrong
  48.         beep
  49.     end try
  50.    
  51.     set strippedPath to (characters 1 thru ((offset of theFileName in filePath) - 1) of filePath) as string
  52.    
  53.    
  54.     tell application "System Events" to tell disk item (filePath as text) to set {fileString, fileExtension} to {name, name extension}
  55.     if fileExtension is not "" then set fileString to text 1 thru -((count fileExtension) + 2) of fileString -- the name part
  56.    
  57.     return {strippedPath, fileString, fileExtension}
  58.    
  59. end getPath
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top