Skip to content

Scripting

This directory contains an example script for the Custom Event Script feature, which allows power users to run custom commands when download events occur.

Note: For most users, the Notifications page in the web UI is the recommended way to set up notifications. It provides a simple form-based interface for configuring Discord, Telegram, Slack, and many other services via Apprise.

  • custom.sh - Example script showing how to handle events

Custom scripts are useful when you need to:

  • Run post-processing commands (e.g., extract archives, convert files)
  • Integrate with systems not supported by Apprise
  • Implement complex conditional logic
  • Log events to a custom format or location
  • Trigger home automation actions

Modify scripts/custom.sh (or create your own script) to handle events:

#!/bin/bash
EVENT_TYPE="$1"
EVENT_JSON=$(cat)
if [ "$EVENT_TYPE" = "downloadFinished" ]; then
FILENAME=$(echo "$EVENT_JSON" | jq -r '.filename')
# Your custom logic here
echo "Download complete: $FILENAME"
fi
Terminal window
chmod +x scripts/custom.sh

Go to Settings → Custom Event Script:

  • Toggle “Enable Custom Event Script” to ON
  • Set the script path to scripts/custom.sh
  • Click “Test Script Path” to verify

When an event occurs, your script receives:

SourceDescription
$1 (first argument)Event type (e.g., downloadFinished)
Environment variablesCommon fields as individual variables
StdinFull event data as JSON
VariableDescription
EVENT_TYPEEvent type (same as $1)
EVENT_HASHDownload hash/ID
EVENT_FILENAMEFile name
EVENT_CLIENT_TYPEClient type (amule, qbittorrent, rtorrent)
EventTriggerAdditional JSON Fields
downloadAddedNew download startedsize
downloadFinishedDownload completedsize, downloaded, uploaded, ratio, trackerDomain
categoryChangedCategory changedoldCategory, newCategory
fileMovedFile movedsourcePath, destPath
fileDeletedFile deleteddeletedFromDisk
#!/bin/bash
EVENT_TYPE="$1"
EVENT_JSON=$(cat)
FILENAME=$(echo "$EVENT_JSON" | jq -r '.filename')
SIZE=$(echo "$EVENT_JSON" | jq -r '.size')
echo "[$EVENT_TYPE] $FILENAME ($SIZE bytes)"
#!/bin/bash
if [ "$1" = "downloadFinished" ]; then
FILENAME="$EVENT_FILENAME"
# Extract archives
case "$FILENAME" in
*.rar) unrar x "/downloads/$FILENAME" /extracted/ ;;
*.zip) unzip "/downloads/$FILENAME" -d /extracted/ ;;
esac
fi
#!/bin/bash
EVENT_JSON=$(cat)
curl -X POST "https://your-webhook.example.com/notify" \
-H "Content-Type: application/json" \
-d "$EVENT_JSON"
#!/bin/bash
echo "$(date -Iseconds) [$1] $EVENT_FILENAME" >> /var/log/downloads.log
Terminal window
echo '{"hash":"abc123","filename":"test.mkv","clientType":"qbittorrent"}' | \
./scripts/custom.sh downloadFinished

Use the “Test Script Path” button in Settings → Custom Event Script.

Script not executing:

  • Verify the script is executable: chmod +x scripts/custom.sh
  • Check the script path in Settings matches exactly
  • Look at application logs for [EventScript] messages

jq not found (non-Docker only):

  • Debian/Ubuntu: apt install jq
  • macOS: brew install jq
  • Alpine: apk add jq

Docker path issues:

  • The default path scripts/custom.sh is relative to the app directory
  • For custom locations, use absolute paths like /usr/src/app/scripts/my-script.sh