This repository contains a demo application to add actions to the context menu (right-click menu on macOS Finder or Windows explorer).
The application takes paths as inputs and creates a copy of images resized by a factor of 0.5 by default. Resizing the images is made using the Pillow package.
Usage:
The CLI arguments are the resizing factor (0.5 by default) and the paths of the files like in the following command:
ResizeImagesContextMenu [-h] [-f FACTOR] files [files ...]
Once installed, it can be used via the context menu (right-click menu. On macOS the action is available in the "Quick Actions" Finder menu, on windows it is available in the Explorer menu, like on the following pictures:
On macOS: macOS picture
On Windows: macOS picture
It features:
- Logging with platform detection to put the logs in an appropriate folder
- Checks the filetype using MIME types to detect images
- Checks if an image with the expected filename exists and if so checks if it has the expected dimensions after resizing in order to avoid resizing images if not needed
The macOS app is built using the package py2app. The script to build the application is build_app.sh. It creates a python virtualenv and installs the depencies from macos.txt. Then it builds the application by using a setup.py file, and it deletes the virtualenv.
The script to build the pkg is build_pkg.sh. It generates two pkg files, one for the app and one for the context menu action. Then using the distribution.xml file it creates the complete pkg file. The built pkg file is then available in the builds
directory.
To make the process of building the application
The script uninstall.sh is available to uninstall all the installed files by the pkg and the logs created by the app. It uses the command pkgutil --forget
to delete the package ids created at the installation of the app.
Note: It must be run with administrative privileges (e.g. sudo)
Note: The .env file contains shared variables to both build_pkg.sh and uninstall.sh scripts, therefore is useful to reduce human errors while editing the scripts.
The windows app is built using the package py2installer.