Monthly Archives: November 2020

Zip droplet

Published / by Kevin / Leave a Comment

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


property def_loc : path to desktop

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.

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

on open _it
end open

on zip_it(_it)
  set _f to ""
  repeat with i in _it
    set _f to _f & " " & quoted form of POSIX path of (i as alias)
  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) & ""
    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 "zip --junk-paths -r " & quoted form of (POSIX path of _z) & _f
end zip_it