9 Replies Latest reply: Jul 22, 2014 9:03 AM by Ted Fitzpatrick
Apple_Student Level 1 (0 points)

Hi I want to make an Applescrit which unzip a file (which is located in the Applescript-Application).The file should be unzipped to the right side of the Application Dock (not to the folder side). ( If there's also Terminal programmation needed it should hide terminal) The name of the app  is install.app and one of the zip-file is install1.zip

Applescript-Editor, Applescript
  • Camelot Level 8 (46,580 points)

    You need to provide a little more detail, please.


    For example, you say the .zip file "... is located in the AppleScript Application". I assume you mean it's inside the Contents/Resources folder of the application package (e.g. if the application is at /Applications/install.app then the zip file is at /Applications/install.app/Contents/Resources/install1.zip)


    Secondly, where do you want to extract the file to? You cannot unzip a file to the Dock. The Dock doesn't contain files, it just contains pointers to other files on the disk. Therefore you have to unzip the file somewhere, and then tell the Dock to add a link to that file.


    So, given the above, you can unzip your file using something like:


    set zipFile to (path to resource "install1.zip")

    set zipFilePath to POSIX path of zipFile

    do shell script "/usr/bin/unzip -d /var/tmp " & quoted form of zipFilePath


    This will unzip the file and put the contents into /var/tmp (edit this to put the files wherever you like).

    This also assumes the zip file is in the Contents/Resources directory, otherwise you'll have to do a little more work to locate the file.


    Once the file is unzipped, you can add it to the Dock via something like:


    set dockFile to "/var/tmp/Install.app"


    do shell script "defaults write com.apple.dock persistent-apps -array-add '<dict><key>tile-data</key><dict><key>file-data</key><dict><key>_CFURLString</k ey><string>" & dockFile & "</string><key>_CFURLStringType</key><integer>0</integer></dict></dict></dict>' "


    do shell script "killall -HUP Dock"


    Change the first line, of course, to reflect where you actually unzip the file to. It's not a good idea to add files from /var/tmp to the dock since the user can't usually get to this location in the Finder

  • Ted Fitzpatrick Level 1 (10 points)

    Hi Master Camelot,


    When I try to use an AppleScript to unzip an file testName.ibooks, well it doesn't work. I don't see any arguments in unzip's man page about how to replace mime type, and actually I don't think that I even want to. Interestingly, I can unzip the ibooks file via Terminal, just not via the AppleScript do shell script.


    Thoughts? Thanks, Ted


    set shellScript to "/usr/bin/unzip " & quoted form of zipFilePath


      do shell script shellScript with administrator privileges -- creates Finder password dialog


    fails with console message:


    error "Finder got an error: replace mimetype? [y]es, [n]o, [A]ll, [N]one, [r]ename:  NULL

    (assuming [N]one)" number 1



  • VikingOSX Level 6 (14,305 points)

    This works without administrator privileges, or having to know anything about mime-types.


    set zipDir to "~/Desktop/Testdir"

    set zipFile to "~/Desktop/foo.ibooks"

    set zipLog to "~/Desktop/unzip.log"

    -- unzip the ibooks document into specified directory

    -- verbosity of the unzip process is written into the log file

    set unzipcmd to "/usr/bin/unzip -d " & zipDir & space & zipFile & " &>" & zipLog


    do shell script unzipcmd

  • Tony T1 Level 6 (8,955 points)

    To keep a running log, use: >>" & zipLog

    (extra ">")

  • VikingOSX Level 6 (14,305 points)

    Just personal taste to not append, as multiple unzip will create log eyestrain.

  • Tony T1 Level 6 (8,955 points)

    Just giving the OP the choice.

  • MrHoffman Level 6 (13,975 points)

    Camelot wrote:


    do shell script "/usr/bin/unzip -d /var/tmp " & quoted form of zipFilePath



    FWIW, the included unzip version 5.52 within OS X is old, and only works correctly on zip files of ~2 GB or smaller.  If you're dealing with larger zip archives, you'll want and need to download unzip 6.0 separately.

  • VikingOSX Level 6 (14,305 points)

    Homebrew (brew) package manager will install unzip v6.0 into /usr/local/bin. OS X 10.9.4 probably has the same Feb. 2005 v5.52 that shipped with Tiger.

  • Ted Fitzpatrick Level 1 (10 points)

    Thanks Viking. Yes that works. Seems that the key is specifying a different output directory than the original containing folder of the ibooks file. Wish I had more time to sleuth out why I can use terminal to unzip into the original parent folder, but not via my AppleScript's shell command (even with admin priv). Moving on ... to re-zipping! :-) Ted