Step 1: In the AppleScript, add an "on open location the_url" section. This will allow the AppleScript to open the URL when you load it in Safari. The "the_url" identifier is the actual URL that is passed to the AppleScript. If you need information from the URL, you will need to parse it.
Step 2: Once you've added the open location handler, you need to save your script as an Application Bundle. To do this, hit Cmd-Shift-S, name your script, and set the File Format to "Application Bundle".
Step 3: Go to the newly saved script in Finder. Right click on the app and select "Show Package Contents" from the contextual menu. In the resulting Finder window, open ./Contents/Resources/info.plist in TextEdit.
Step 4: Scroll down to the bottom of the info.plist file and add the following code right above the "</dict>" line.
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>AppleScript Example URL</string>
<key>CFBundleURLSchemes</key>
<array>
<string>myscript</string>
</array>
<key>LSIsAppleDefaultForScheme</key>
<true/>
</dict>
</array>
Step 5: Edit the "<string>AppleScript Example URL</string>" and "<string>myscript</string>" lines. The first is just a description line, the second is what you put at the beginning of the URL. So, in this example, you would use: "myscript://urlcontent" to run the script.
Step 6: Save the info.plist file using Cmd-S.
Step 7: Assuming that everything went smoothly, you should now be able to go to your preferred web browser and visit the URL you set up. This will launch the AppleScript and perform the actions you outlined in the "open location" handler.
If your URL doesn't work, you might want to try resetting LaunchServices. To do this, run the following terminal command:
/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -kill -r -domain local -domain system -domain user
3 comments: