您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Rewrites all magnet: links to openmagnet:// URLs for handling via a custom macOS Automator or Parallels app
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.
<a href="magnet:...">
links are converted to openmagnet://?url=ENCODED_MAGNET_LINK
openmagnet://
as a custom protocol and launches your designated Automator apptarget="_self"
to prevent popup blocker issues#!/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"
APP_PATH
to match your actual Parallels shared application pathOpenMagnetInParallels.app
in your Applications folderRun 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"
Links not being rewritten?
Automator app not launching?
APP_PATH
in your shell script is correctopen "openmagnet://?url=test"
in TerminalqBittorrent not receiving the magnet link?
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.