THIS PROJECT IS A PYTHON PROGRAM TO ENABLE CONVERSION OF EML FILES TO PDF FILES ON A MAC.
There are also instructions below about how to add a 'quick action' to your 'right mouse' menu. I use it every day, and it works great, but no liability taken.
===============================================
It was developed for Soferio Pty Ltd by a brilliant Upwork developer, and we are hereby open sourcing it. Pull requests are welcome.
This project use 3rd party libraries:
easygui
: let users select the input file from a dialogeml-parser
: parse the EML file for HTML and attachments filesweasyprint
: Convert HTML files and create PDF files with attachmentshtml5lib
: for editing HTML elementstinycss2
: for editing CSS stylesSend2Trash
: For moving EML file to trash bin.
On MacOs, please run this command to install dependencies for weasyprint
brew install python pango libffi
Please run this command to install python-tk
, a dependency of easygui
brew install python-tk
On Apple Silicon, there can be some difficulty with "gobject". If so, Then the symlinks here may help:
https://stackoverflow.com/questions/69097224/gobject-2-0-0-not-able-to-load-on-macbook
On MacOS Also sometimes need to Give Terminal and Finder full disk access
- Google how to to do this, but inside security/privacy
Then from the base directory of the project, please run this to create a virtual env:
python3 -m venv .venv
Activate the virtual env so we can start working in:
source .venv/bin/activate
Install dependencies libraries to the virtual env:
python3 -m pip install -r requirements.txt
Please run the following command from the base directory of the project:
python3 main.py
To create a shortcut to run the script in MacOs, first we need to grant the execute permission to the file start.command
by running:
chmod +x ./start.command
Then in Finder, please right click on start.command
file and select Make Alias
. Then we can copy the alias file anywhere (such as Desktop) or rename it to anything.
Double click on the alias file or the start.command
file will run the script in virtual environment.
The script will run inside a terminal windows. After finish running, if the terminal windows is not closed, then we can configure the terminal to close. To configure the terminal to close after finish running, we need to:
- Open Terminal
- Go to Menu Terminal -> Preferences...
- Then in tab Shell, in "When the shell exists:", we select "Close if the shell exited cleanly".
The console.py
is the command line version of main.py
. For a list of argument to run it, please type:
python console.py -h
A help message will appear like this:
usage: python console.py [-h] [-d] [-f] [-o] [-w directory] [eml_files ...]
Convert EML to PDF.
positional arguments:
eml_files EML filenames
options:
-h, --help show this help message and exit
-d, --delete Keep the EML files after conversion (default: NO)
-f, --force Overwrite existing PDF files (default: NO)
-o, --open Open the PDF files after conversion (default: NO)
-l, --log Store output to a log file (default: NO)
-w directory, --watch directory
Watch a directory and all subdirectories of it for EML files
- First we need to edit
watch.command
file to specify the directory we need to watch. Just replaceEML_DIRECTORY
with the path of your EML directory. Then we grant the execution permission on the filewatch.command
by running:
chmod +x ./watch.command
- Go to System Preferences -> "Users & Groups".
- Click on the Lock button on lower corner to change settings.
- Then click on the the Current User on the left panel. On the right panel, we click on
Login Items
tab. - In
Login Items
tab, click on the '+' button to add a new item to run when login. - Navigate to and select
watch.command
file.
- Open Automator. Select "New Document".
- Choose "Quick Action" as type for new document.
- In
Workflow receives current
box, we change tofiles or folders
- Then we drag
Run Shell Script
action from the left panel to the right panel (where we see the text "Drag actions or files here to build your workflow") - In the
Run Shell Script
, we changePass input
toas arguments
and place the content of the script (replace PATH_TO_EML_PDF_PROJECT with the real path)
cd PATH_TO_EML_PDF_PROJECT
source .venv/bin/activate
python3 console.py $@ -f -o -d
- Save the Quick Action and give it a name. Now it will be saved to
~/Library/Services
. - From now, in Finder, when we right click after select one or multiple EML files in Finder, a new menuitem (with the same name that we saved the workflow) will appear. Clicking on the menuitem will convert the selected files to PDF files. The script only converts EML files and ignore other files types.
- If we don't want to use the Quick Action more, we can delete it from
~/Library/Services
. After we delete it, it won't appear in Finder.