Compress / Archive encrypted

Sharing and discussing custom actions for LaunchBar
Morrr
Posts: 2
Joined: Fri Aug 03, 2018 11:45 am

Compress / Archive encrypted

Postby Morrr » Fri Aug 03, 2018 12:02 pm

I'm currently trying to build a service via automator to just do a simple thing:
Compress / Archive files and folders into a zip with the MacOS system tools. I know that I could use something like

Code: Select all

zip -er archive.zip /path/to/directory/
in terminal. I don’t really want to switch to terminal in order to do so.
I love the built-in Compress (ZIP Archive) action in lauchbar and would like to have a similar one that does essentially the same but with a password prompt*.

At first I tryed the follwoing code for my Automator-Service:

Code: Select all

on run {input, parameters}
 set dialogResults to display dialog "Name for zipped file (no extension)" default answer "Archive" buttons {"OK", "Cancel"} default button "OK"
 if button returned of dialogResults is "OK" then
  set passwd to text returned of (display dialog "password for zipped file" default answer "password" buttons {"OK", "Cancel"} default button "OK")
 
  set archiveName to text returned of dialogResults
 
  tell application "Finder"
   set archiveFileName to archiveName & ".zip"
   -- Append on a number if file exists.
   set suffix to 1
   set theFileExists to true
   repeat while theFileExists
    try
     set archiveFile to ((container of (item 1 of input) as Unicode text) & archiveFileName)
     if exists file archiveFile then
      set archiveFileName to archiveName & suffix & ".zip"
      set suffix to suffix + 1
     else
      set theFileExists to false
     end if
    end try
   end repeat
  end tell
  set itemStr to ""
  repeat with thisItem in input
   set itemPath to quoted form of (POSIX path of thisItem)
   tell application "Finder"
    set parentFolder to POSIX path of (container of thisItem as alias)
   end tell
   set itemStr to itemStr & " " & itemPath
  end repeat
  set zipFile to quoted form of (parentFolder & archiveFileName)
  set cmd to "zip -P " & passwd & " -rj " & zipFile & " " & itemStr & " -x *.DS_Store"
  do shell script cmd
 end if
 return
end run


This almost works as expected but it’s completly removing any folder structures inside the archive. So after unzipping all files are on a top-level without any folder structure at all. I then just played around and removed the -rj in line 34. Now I have a folder structure but it’s the absolute path from User/… not the actual chosen folder.

Code: Select all

on run {input, parameters}
 set dialogResults to display dialog "Name for zipped file (no extension)" default answer "Archive" buttons {"OK", "Cancel"} default button "OK"
 if button returned of dialogResults is "OK" then
  set passwd to text returned of (display dialog "password for zipped file" default answer "password" buttons {"OK", "Cancel"} default button "OK")
 
  set archiveName to text returned of dialogResults
 
  tell application "Finder"
   set archiveFileName to archiveName & ".zip"
   -- Append on a number if file exists.
   set suffix to 1
   set theFileExists to true
   repeat while theFileExists
    try
     set archiveFile to ((container of (item 1 of input) as Unicode text) & archiveFileName)
     if exists file archiveFile then
      set archiveFileName to archiveName & suffix & ".zip"
      set suffix to suffix + 1
     else
      set theFileExists to false
     end if
    end try
   end repeat
  end tell
  set itemStr to ""
  repeat with thisItem in input
   set itemPath to quoted form of (POSIX path of thisItem)
   tell application "Finder"
    set parentFolder to POSIX path of (container of thisItem as alias)
   end tell
   set itemStr to itemStr & " " & itemPath
  end repeat
  set zipFile to quoted form of (parentFolder & archiveFileName)
  set cmd to "zip -P " & passwd & " " & zipFile & " " & itemStr & " -x *.DS_Store"
  do shell script cmd
 end if
 return
end run

Is there anyone around that could help me out with this? I don’t want to install a big chunk of software to do these tasks and I also would prefer to not switch zu terminal to do something simple like this.

Any help is appreciated!

veke71
Rank 2
Rank 2
Posts: 61
Joined: Sun Jul 03, 2011 10:14 pm

Re: Compress / Archive encrypted

Postby veke71 » Fri Aug 03, 2018 1:57 pm

There's a build in action for this. Just choose something press tab and then type "compress".


Update: Sorry. Now I read the whole post.

Morrr
Posts: 2
Joined: Fri Aug 03, 2018 11:45 am

Re: Compress / Archive encrypted

Postby Morrr » Mon Aug 06, 2018 9:09 am

I know the built in Action.
I’m looking for a simple way to replicate the built in one with a additional password prompt.

That would be superfine.


Return to “LaunchBar Actions”

Who is online

Users browsing this forum: No registered users and 0 guests