I am creating Automator Service to unzip selected files in the same folder they are located.

How can I get selected file absolute path in Automator, so I can pass it into my shell script ?

As you can see I am only passing filename for now, but its not unzipping in same folder.

I would like to change folder before unzip, and then execute unzip. I tried cd ~ but it unzips to my homefolder. I would like to unzip in same folder as selected files exists.

enter image description here

  • Add cd "$(dirname "$f")" before the unzip line.
    – fd0
    Jul 2, 2017 at 10:31
  • that is awesome, put it as answer pls and i mark it. thx a lot
    – To Kra
    Jul 2, 2017 at 10:41
  • I don't see why you need a script - I double-click on a zip file and it gets extracted into the same location with no other dialogue box or anything.
    – Solar Mike
    Jul 2, 2017 at 11:17
  • @SolarMike ArchiveUtility sometimes wont work for particular archive files and returning errors. Using unzip works as charm.
    – To Kra
    Jul 2, 2017 at 12:16

1 Answer 1


Add cd "$(dirname "$f")" before the unzip line.

for f in "$@"; do
    cd "$(dirname "$f")"
    unzip -o "$f"

or without changing to the directory, use the -d option

[-d exdir]
          An  optional  directory  to which to extract files.  By default, all files and subdirectories
          are recreated in the current directory; the -d  option  allows  extraction  in  an  arbitrary

for f in "$@"; do
    unzip "$f" -d "$(dirname "$f")"

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .