I've developed a Powershell script that can resize Pushover notification attachments before they are sent.
NEW EDIT (9/8/2024 12:00p): Added new runtime arguments for Pushover notification customization, plus other changes - zip attachment updated to v2.0
EDIT (7/12/23 3:00p): fixed Pushover -Priority argument bug; reworked function 'PurgeOldFile()' - zip attachment updated to v1.9
EDIT (6/4/23 10:00a): Added options to tune image resizing, plus other changes - zip attachment updated to v1.8
EDIT (5/31/23 10:00a): Fixed bugs & clarified user settings comments for posting messages to the Blue Iris logfile (more) - zip attachment updated to v1.7
EDIT (5/30/23 3:30p): Moved USER SETTINGS code to a separate configuration file, plus other changes - zip attachment updated to v1.6
EDIT (5/28/23 2:30p): Added named commandline arguments, plus other changes - zip attachment updated to v1.5
EDIT (5/27/23 9:00a): Changed attachment argument requirement to optional; script now requires only message argument (more) - zip attachment updated to v1.4
EDIT (5/26/23 9:00a): Added ExecutionPolicy info & alert's filename to the background messaging - zip attachment updated to v1.3
EDIT (5/25/23 9:00a): Added user setting for background messaging - zip attachment updated to v1.2
EDIT (5/24/23 5:40p): Found a bug - zip attachment updated to v1.1
The script
pushover_resize.ps1 enables sending Pushover notifications with large attachments (exceeding 2.5MB) that would otherwise result in the rejection of the notification by the Pushover API.
"Each message may only include one attachment, and attachments are currently limited to 2,621,440 bytes (2.5 megabytes). Attempting to send attachments larger than this size will be rejected with an API error (or server error for extremely large file attempts). Any resizing of images to fit under this limit must be done on the sending side before making the API request."
The script accepts user customization for both 1) the level of compression of the attachment, and 2) the Pushover notification parameters. All user customizations may be edited by opening the script in a text editor and navigating to the code section labeled
USER SETTINGS...
The script also automatically logs its activity to a CSV file, recording the attachment's size (KB) and WxH before/after resizing, and script processing time (msec) for 1) the attachment resizing, 2) sending the Pushover notification.
No external components are required.
The script can be
executed from a Blue Iris action set action as follows.
Here's the full entry in the
Parameters field...
Code:
-File "C:\ps_scripts\pushover_resize.ps1" -Msg "<b>&CAM</b> &MEMO <a href='&WAN/alerts/&ALERT_DB?fulljpeg'>Hi-Res</a> <a href='&WAN/ui3.htm?rec=&ALERT_DB'>UI3</a>" -Priority 2 -AttachFile "D:\Blue Iris\Alerts\&ALERT_PATH"
If you receive messages regarding execution policy issues, you can use the following to run the script without changing the ExecutionPolicy for the whole system...
Code:
-ExecutionPolicy Bypass -File "C:\ps_scripts\pushover_resize.ps1" -Msg "<b>&CAM</b> &MEMO <a href='&WAN/alerts/&ALERT_DB?fulljpeg'>Hi-Res</a> <a href='&WAN/ui3.htm?rec=&ALERT_DB'>UI3</a>" -Priority 2 -AttachFile "D:\Blue Iris\Alerts\&ALERT_PATH"
=====
Using/Testing the PowerShell Script
To experiment with this script:
1. Extract the *.ps1 file from the attached zip file to your desktop, or scripts folder. The folder used must be in your PC's environment path.
2. Create a folder for the resized files. To use the folder, you must edit the setting
$img_path
in the script's USER SETTINGS section
3. For testing, run the script from an Admin PowerShell window.
e.g.
pushover_resize.ps1 -Msg "test msg" -AttachFile "D:\Blue Iris\Alerts\DW1.20230521_160000.3076088.17-0.jpg"
(be sure to use an alert file that actually exists in your Blue Iris alerts folder.)
The script can also be executed from an Admin cmd.exe window using a command like powershell.exe "C:\ps_scripts\{scriptname}.ps1 args"
4. For use in Blue Iris action set ‘run a program’ actions, see the screenshot above.
NOTE: If you've never used PowerShell on your Blue Iris PC, you may first to need to change its default security policy.
Open PowerShell in Administrator mode, and type the following, then hit the Enter key
Set-ExecutionPolicy RemoteSigned
(click <
here> for a nice beginner's tutorial to using PowerShell).
=====
Caveats
1. I initially struggled to get the script to run in the background. It currently works quite well on my machine, but this is an N=1 sample size. Please let me know if you encounter difficulties.
2. Be sure to run the Blue Iris service with your own user account. See the Blue Iris help PDF section 'Testing the Action Set' to learn more.