How to unzip ZIP files protected with a password and containing files with ä, ö, ü in their names?

With Unzip I can unzip ZIP files protected with a password, that do not contain any files with ä, ö, ü in file names.

With Ditto I can unpack ZIP filled protected with a password and containing files with ä, ö, ü in file names. But Ditto doesn't allow me to pass the password via a Shell action.

As a matter of fact, even this doesn't work for me (I'm not prompted to insert the PW):

So I guess there's no way to unzip password protected ZIP files that contain files with Umlauts in their names, via a macro. Right?

Hey Hans,

This works for me on macOS 10.14.6 Mojave with Keyboard Maestro 10.2.

# This works in Keyboard Maestro...

cd '/Users/chris/test_directory/Keyboard_Maestro_Test_Folder/DITTO_TESTS/test'

unzip -P 'YourPassword' Tëst_Ä

Note that the archive file name contains umlauts, and at least one file name within the archive contains umlauts.

There might be a way to echo a password into the ditto command, but since this works I'm not going to spend the time.

Note also that you can use the macOS Archive utility for this task if you have to.



It's a trifle clunky, but it works.


1 Like

Hi Chris,

Thanks for looking into this. I get:

Last login: Wed Nov 23 14:50:57 on ttys000
hl@Hanss-iMac ~ % cd desktop
hl@Hanss-iMac desktop % unzip -P Landall exä
Archive:  exä
   creating: P-220931_an_Landall_tr/
  inflating: P-220931_an_Landall_tr/251562_89401212 ; 000400 ; nlNL ; BA ; v1.sdlppx  
  inflating: P-220931_an_Landall_tr/P-220931_1_Landall, Hans_DE-NL.pdf  
   creating: P-220931_an_Landall_tr/Referenzdateien/
error:  cannot create P-220931_an_Landall_tr/Referenzdateien/Erg?nzung zur bestehenden Betriebsanleitung, 1, de_DE.pdf
        Illegal byte sequence
error:  cannot create P-220931_an_Landall_tr/Referenzdateien/Erg?nzung zur bestehenden Betriebsanleitung, 1, nl_NL.pdf
        Illegal byte sequence
hl@Hanss-iMac desktop % 

The question mark stands for a "ä".

Are these zips you've created or are they from elsewhere, like a Windows user?

Otherwise, grab a copy of Stuffit Expander (free), which will cope with almost anything you throw at it. You can then call it in your macro with an AppleScript action:

tell application "StuffIt Expander"
	expand myFile password "myPass0rd"
end tell

...and you can pass the file and password form KM in the usual way. Much easier (and more secure) than trying to use the expect utility to feed a password to ditto in a shell script.

1 Like

Alas, Stuffit won't open the ZIP files, that indeed were created by a Windows user:

Screen Shot 2022-11-24 at 14.20.29

I found that the Archive Utility actually opens the ZIP files. A 'ä' in a file name is converted to a curly quotation mark, but I can fix that via a macro.

The question is:

  • Can the Archive Utility be controlled by Keyboard Maestro, even when a password needs to be passed?

This is sounding more and more like a Unicode character issue. Out of interest, if you extract the files then open Terminal and type ls (there's a space after the s), drag a file with and accented name on to the Terminal window, type | hexdump -C (there's a space before the "pipe" character) and hit Return -- what's the output? Then try the same for a file with a different accented character.

The worry is that all the "odd" characters will be ?, so it won't be a "simple" S'n'R if you want to preserve file names...


If you refer to my post #2 you'll see the password dialog.

  • You have to wait for the app to open.
  • Wait for the password dialog to open.
  • Paste the password into the dialog.
  • Hit the OK button.

A typical Keyboard Maestro macro...

I unzipped the ZIP with Windows 10's default unzip tool. Here's a screenshot of the action you suggested:

Hey Chris,

How do I tell the Archive Utility to find the ZIP at my Desktop?

Thank you in advance!

Would have been easier in a code block, but you can see on the second line

00000010  70 2f 45 72 67  61 cc 88 6e...

...where 61 is a, 6e is n, leaving the cc 88 in-between. Looking up 0xCC 0x88 gives us U+0308 which you can see is the "Combining Diaeresis" and is fine on the Mac.

But it's probable that unzipping on Windows then transferring to the Mac is also allowing character conversion at one point or another. I should have been more clear -- you need to unpack the password-protected zip with Archive Utility then hexdump the name, so we can see why it is giving you ? rather than ä.

Thanks for your follow up!

Last login: Fri Nov 25 11:45:20 on ttys000
hl@Hanss-iMac ~ % ls /Users/hl/Desktop/Erg„nzung\ zur\ bestehenden\ Betriebsanleitung\,\ 1\,\ de_DE.pdf | hexdump -C
00000000  2f 55 73 65 72 73 2f 68  6c 2f 44 65 73 6b 74 6f  |/Users/hl/Deskto|
00000010  70 2f 45 72 67 e2 80 9e  6e 7a 75 6e 67 20 7a 75  |p/Erg...nzung zu|
00000020  72 20 62 65 73 74 65 68  65 6e 64 65 6e 20 42 65  |r bestehenden Be|
00000030  74 72 69 65 62 73 61 6e  6c 65 69 74 75 6e 67 2c  |triebsanleitung,|
00000040  20 31 2c 20 64 65 5f 44  45 2e 70 64 66 0a        | 1, de_DE.pdf.|
hl@Hanss-iMac ~ % 

Doing the same as before, 67 is g, 6e is n so the bits in-between are your accented u -- e2 80 9e. Looking up that triplet will get you U+201E, the "Double Low-9 Quotation Mark" -- which is what you are seeing.

I'm guessing it's Windows character encoding that is handled cleanly when you transfer the unzipped file from PC to Mac, but not when you unzip it directly on the Mac. You might be able to build a table that you can use to convert the "odd" characters back to what you want with KM search-and-replace actions...

But, if using expect to drive ditto is what's required then here's something that will:

  1. Prompt you for a file
  2. Prompt you for a password (I've used a Local variable because I don't think Password variables are available in an "Execute Shell Script" action...)
  3. Unzips the source to the same directory, suffixing the result with -unzipped. So ~/Desktop/ unzips as ~/Desktop/test-unzipped

Everything is passed into the shell script from KM variables, so things should be easy to change with KM (rather than shell) knowledge.

Ditto with Password.kmmacros (4.0 KB)


1 Like

The usual suspects...

Archive Utilitiy ⇢ Unarchive A Password Protected Zip File v1.00.kmmacros (7.7 KB)
Keyboard Maestro Export

NOTE – you may get better performance out of The Unarchiver than from the macOS Archive Utility. I haven't tested it in a while, but I used it in preference to the AU for many years and may go back to it when I have system hardware with more space again.

1 Like

Thanks, Chris!

BTW: I had to change the button here from OK to Cancel: