Force Magnet Link Redirect to Parallels

Rewrites all magnet: links to openmagnet:// URLs for handling via a custom macOS Automator or Parallels app

Penulis
sharmanhall
Pemasangan harian
0
Total pemasangan
0
Nilai
0 0 0
Versi
1.1
Dibuat
17 Juni 2025
Diperbarui
17 Juni 2025
Size
3,02 KB
Lisensi
MIT
Berlaku untuk
Semua situs

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

  1. Open Automator on macOS
  2. Create a new Application
  3. Add a Run Shell Script action
  4. Set "Pass input" to as arguments
  5. 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"
  1. Important: Update APP_PATH to match your actual Parallels shared application path
  2. 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

  1. Install this userscript in Tampermonkey/Violentmonkey
  2. Visit any torrent site with magnet links
  3. 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.