Force Magnet Link Redirect to Parallels
Description
This userscript automatically rewrites all magnet:
links on any webpage into openmagnet://
links, which are handled by a custom Automator app on macOS. This allows you to seamlessly forward torrent downloads to qBittorrent or any other torrent client running inside a Parallels virtual machine.
How It Works
- Automatic Link Rewriting: All
<a href="magnet:...">
links are converted to openmagnet://?url=ENCODED_MAGNET_LINK
- Custom URL Scheme: macOS recognizes
openmagnet://
as a custom protocol and launches your designated Automator app
- Dynamic Detection: Uses MutationObserver to catch magnet links that are added to the page after initial load
- No Popup Interference: Sets
target="_self"
to prevent popup blocker issues
Features
- Works on all websites automatically
- Handles dynamically loaded content
- Lightweight and fast
- No elevated privileges required
- Compatible with Tampermonkey, Violentmonkey, and Greasemonkey
macOS Setup Instructions
Step 1: Create the Automator App
- Open Automator on macOS
- Create a new Application
- Add a Run Shell Script action
- Set "Pass input" to as arguments
- Replace the default script with:
#!/bin/bash
# Extract magnet link from the custom URL scheme
MAGNET_URL="$1"
MAGNET=$(echo "$MAGNET_URL" | sed -E 's/^.*url=//' | python3 -c 'import sys, urllib.parse as u; print(u.unquote(sys.stdin.read()))')
# Path to your Parallels-based torrent app (update this path!)
APP_PATH="/Applications/Parallels Desktop.app/Contents/SharedApplications/qBittorrent.app"
# Launch the torrent app with the magnet link
open -a "$APP_PATH" --args "$MAGNET"
- Important: Update
APP_PATH
to match your actual Parallels shared application path
- Save the app as
OpenMagnetInParallels.app
in your Applications folder
Step 2: Register the URL Scheme Handler
Run these commands in Terminal to register your Automator app as the handler for openmagnet://
URLs:
# Set variables
APP="/Applications/OpenMagnetInParallels.app"
PLIST="$APP/Contents/Info.plist"
# Configure the app bundle
/usr/libexec/PlistBuddy -c "Set :CFBundleIdentifier com.example.OpenMagnet" "$PLIST"
# Remove existing URL types and add our custom scheme
sudo /usr/libexec/PlistBuddy -c "Delete :CFBundleURLTypes" "$PLIST" 2>/dev/null
/usr/libexec/PlistBuddy -c "Add :CFBundleURLTypes array" "$PLIST"
/usr/libexec/PlistBuddy -c "Add :CFBundleURLTypes:0 dict" "$PLIST"
/usr/libexec/PlistBuddy -c "Add :CFBundleURLTypes:0:CFBundleURLName string Magnet Redirect" "$PLIST"
/usr/libexec/PlistBuddy -c "Add :CFBundleURLTypes:0:CFBundleURLSchemes array" "$PLIST"
/usr/libexec/PlistBuddy -c "Add :CFBundleURLTypes:0:CFBundleURLSchemes:0 string openmagnet" "$PLIST"
# Register the app with Launch Services
/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -f "$APP"
Step 3: Test the Setup
- Install this userscript in Tampermonkey/Violentmonkey
- Visit any torrent site with magnet links
- Click a magnet link - it should automatically open your Parallels-based torrent client!
Troubleshooting
Links not being rewritten?
- Check the browser console for script errors
- Ensure the userscript is enabled and running on the target site
Automator app not launching?
- Verify the
APP_PATH
in your shell script is correct
- Test the URL scheme by running
open "openmagnet://?url=test"
in Terminal
qBittorrent not receiving the magnet link?
- Ensure qBittorrent is set as the default magnet handler within your Parallels VM
- Check that the Parallels shared applications are properly configured
Technical Details
The script uses a MutationObserver
to monitor DOM changes and automatically converts any new magnet links that appear on the page. This ensures compatibility with modern single-page applications and dynamically loaded content.
The custom openmagnet://
protocol provides a clean bridge between your browser and the Parallels environment, avoiding the need for complex browser extensions or native messaging hosts.