Most web browsers provide an option to export all credentials to a text file, in order to make it easier to switch to another browser. Unfortunately, as of macOS 11, Safari does not include this feature.
This script uses the accessibility features built into macOS to grab all usernames and passwords from Safari's Preferences window. It generates a csv file with three columns: url, username and password.
The script is provided in two forms:
- the source code as a text file,
- a signed and notarized standalone application for ease of use.
On first launch, the application will ask for permission to control the computer through the Accessibility interface. If this permission is not granted, it will not be able to access the passwords in Safari's preferences.
Afterwards it is possible to revoke or grant this permission in the Security & Privacy pane of System Preferences (Privacy tab, Accessibility option).
Tha application will ask for a location for the csv file (by default: "Safari Passwords.csv" on the Desktop). Then it will bring Safari to the front and display the Passwords tab from the Preferences window. Your password is required in this window. The export starts as soon as you type your password. A notification is displayed when the export is done.
The csv file generated by the script contains all passwords in clear text. Therefore it is strongly advised to enable FileVault on your system before generating the csv, and to destroy it after importing its contents into another browser or password manager.
Alternatively, for improved security, it is possible to create a writable encrypted disk image with Disk Utility, and to generate the csv into it.
This script has been tested with Safari 14.1 on macOS 11.4. Hopefully a future version of Safari or macOS (wink) will provide this feature natively and thus render this script obsolete.