This project demonstrates how to create a macOS application that can be launched from web links. Through custom URL Schemes (such as myprotocol://), when users click on special links in web pages, it can automatically launch the specified macOS application.
Utilizes macOS's URL Scheme mechanism. When the system detects a URL with a specific protocol, it automatically launches the application registered for that protocol.
- Reference 1: http://www.macosxautomation.com/applescript/linktrigger/
- Reference 2: http://hublog.hubmed.org/archives/001154.html
- Use Platypus to create
test.app - Place
test.appin the/Applications/folder - Add URL Scheme configuration to
Info.plist
test.app/
└── Contents/
├── Info.plist
├── MacOS/
│ └── test
└── Resources/
├── AppSettings.plist
├── MainMenu.nib
├── appIcon.icns
└── script
Add the following configuration to Info.plist:
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>My Protocol</string>
<key>CFBundleURLSchemes</key>
<array>
<string>myprotocol</string>
</array>
</dict>
</array>
<key>NSUIElement</key>
<true/>CFBundleURLSchemes: Defines the custom protocol name (in this example:myprotocol)NSUIElement: Set totrueto run the application in the background without appearing in the Dock
Use Platypus tool to create the application based on the test.platypus configuration file.
Open the test.html file and click the link inside:
<a href='myprotocol://.'>test</a>- Click the
myprotocol://link in the web page - macOS system automatically recognizes the protocol and launches the corresponding application
- The application executes the default script actions
test.html: Test web page containing links that trigger custom protocolstest.platypus: Platypus project configuration filetest.sh: Execution script (can customize application behavior when launched)test.app/: Final generated macOS application
- The application must be placed in the
/Applications/directory to be properly recognized by the system - If using
window.opento open links, remember to add thewindow.open("", "_self")parameter - Setting
NSUIElementtotrueallows the application to run in the background, suitable for this type of utility tool
- Quickly launch local applications from web pages
- Create a bridge mechanism between web pages and desktop applications
- Implement one-click installation or configuration features