revDAVE

Q: help zipping a file w applescript

Hi,

 

I have simple applescript to zip a folder - but it's not working...

 

when I run it - it creates the zip - but when I unzip - instead of just the zippiest folder and contents - it created folders in folders of the path like:

 

Users>me>Desktop>ziptest

 

and the zippiest folder is empty!

 

Q: how do I get this working so it works like right click and archive does in the finder?

 

------

 

-- zippiest is a folder with a few items in it

 

do shell script "zip '/Users/me/Desktop/test.zip'  '/Users/me/Desktop/ziptest'"

MacBook Pro, OS X El Capitan (10.11.5), null

Posted on May 30, 2016 9:51 AM

Close

Q: help zipping a file w applescript

  • All replies
  • Helpful answers

  • by red_menace,

    red_menace red_menace May 30, 2016 10:40 AM in response to revDAVE
    Level 6 (15,541 points)
    Desktops
    May 30, 2016 10:40 AM in response to revDAVE

    Zip has a bunch of options (see the man page).  The -j option will store just the file name, not the directory names.

  • by Jacques Rioux,

    Jacques Rioux Jacques Rioux May 30, 2016 10:56 AM in response to revDAVE
    Level 4 (3,418 points)
    Mac OS X
    May 30, 2016 10:56 AM in response to revDAVE

    Hi,

     

    You must use the -r option to compress a folder

     

    do shell script "zip -r '/Users/me/Desktop/test.zip'  '/Users/me/Desktop/ziptest'"

  • by revDAVE,

    revDAVE revDAVE May 30, 2016 1:10 PM in response to revDAVE
    Level 2 (270 points)
    iPhone
    May 30, 2016 1:10 PM in response to revDAVE

    Thanks so much Jacques Rioux & red_menace  - I am getting there...

     

    if I use red_menace addition to add -j - then the folder result says nothing to do... (maybe this is just for a file not folder?)


    Jacques Rioux...

    one problem I having  with :

    do shell script "zip -r '/Users/me/Desktop/ziptest.zip'  '/Users/me/Desktop/ziptest'"

    is it zipped the folder but still keeps the path folders


    Q: so how do I also use red_menace addition to add -j so the folder

     

    when I try below I get errors....

     

    do shell script "zip -rj ....

    do shell script "zip -r -j ....

    do shell script "zip -r j ....

     

    Thanks in advance

  • by Jacques Rioux,Helpful

    Jacques Rioux Jacques Rioux Jun 7, 2016 1:51 PM in response to revDAVE
    Level 4 (3,418 points)
    Mac OS X
    Jun 7, 2016 1:51 PM in response to revDAVE

    Hi,

     

    revDAVE wrote:

     

    one problem I having  with :

    do shell script "zip -r '/Users/me/Desktop/ziptest.zip'  '/Users/me/Desktop/ziptest'"

    is it zipped the folder but still keeps the path folders

     

    You must use the cd command with the parent folder of your folder to skip all parent folders

     

    Example with the "/Users/me/Desktop/ziptest" folder :

    So, the parent folder is "/Users/me/Desktop/"

    The parameters of the zip command must be:  -r (because it's a folder), the name of the archive and the name of the folder

    ---

    do shell script "cd "/Users/me/Desktop/" && zip -r 'ziptest.zip' 'ziptest'" -- this create an archive  on the desktop

    ---

  • by Pierre L.,Helpful

    Pierre L. Pierre L. Jun 7, 2016 1:51 PM in response to revDAVE
    Level 5 (4,484 points)
    Jun 7, 2016 1:51 PM in response to revDAVE

    Q: how do I get this working so it works like right click and archive does in the finder?

     

    You might also try this:

     

    tell application "Finder"

         activate

         select (choose folder)

    end tell

     

    tell application "System Events"

         click (menu item 1 of menu 1 of menu bar item "File" of menu bar 1 of process "Finder" whose name starts with "Compress")

    end tell

  • by revDAVE,

    revDAVE revDAVE Jun 7, 2016 1:52 PM in response to revDAVE
    Level 2 (270 points)
    iPhone
    Jun 7, 2016 1:52 PM in response to revDAVE

    Thanks Jacques & Pierre - I will try these!