Monthly Archives: November 2020

Zip droplet

This has been some hot garbage since I posted it. This is now actually not bad, but I can’t help but feel it’s clumsier than it could be. *meh*

Quick and dirty AppleScript droplet to zip files in the Finder.

-- http://strawhousepig.net/

-- Default location to save the .zip file.
property def_loc : path to desktop

-- This script will not send files beginning with '.' (dot) to be zipped.
(*
If you're going to be sending zip archives to a location other than
a file-system domain (directories which the system has a 'nickname' for)
 I believe the above syntax would be:
  path to file "My HD:My Folder Daryl:My Other Folder Daryl:"
Or using POSIX style path
  path to POSIX file "/My HD/My Folder Daryl/My Other Folder Daryl/"
Although I am not sure about that. Another alternative would be to add an
if clause in the zip_it function to check for the "same" setting and then
use the container of item 1 of the files list "_it" as the default location.
*)

-- Not quite sure how to use this, in the AS routines or 'zip -x' or screw it and drop files beginning with a dot?
--property no_can_zip : {".DS_Store", ".fseventsd", ".Spotlight-V100"}

on run
  tell application "Finder"
    set _it to selection as list
  end tell
  my zip_it(_it)
end run

on open _it
  zip_it(_it)
end open

on zip_it(_it)
  set _f to ""
  tell application "Finder" to set _dir to container of ((item 1 of _it) as alias)
  set my text item delimiters to {POSIX path of (_dir as alias)}
  repeat with i in _it
    if first character of name of (info for (i as alias)) is not "." then
      set _f to _f & " " & quoted form of text item 2 of (POSIX path of (i as alias))
    end if
  end repeat
  set the_c to count of _it
  if the_c > 1 then
    set z_name to (displayed name of (info for (item 1 of _it as alias))) & " + " & (the_c - 1) & " items.zip"
  else
    set z_name to (displayed name of (info for (item 1 of _it as alias))) & ".zip"
  end if
  set _z to (choose file name with prompt (the_c as string) & " file(s) to zip." default name z_name default location def_loc)
  do shell script "cd " & quoted form of POSIX path of (_dir as alias) & " && zip  -ry " & quoted form of POSIX path of _z & _f
end zip_it