How to use Applescript app bundle as default browser in os x?

My goal is to ensure that links clicked on the same osx machine are loaded into safaris on the remote computer with apple events enabled. To do this, I am trying to create an applescript application, which then creates a default browser on the system.

My applicator looks like this:

on run argv set theurl to item 1 of argv set dest to "eppc://user: password@ipaddress " tell application "Safari" of machine dest activate open location theurl end tell end run 

In case argv is not a suitable method to use the url, I simplified the script to:

 tell application "Safari" activate open location "http://www.google.com" end tell 

Then I save it as an application and tell Safari that this application should be the default browser, but when I click the links in the applications, it completely ignores my applescript and loads the URL in Safari anyway (and not the URL I ' ve is the URL I clicked on).

Why is this? Do I need to do something special for my Applescript to act like a browser? If I run the applescript application by double-clicking on it, it will do exactly what it was supposed to do, but if I launch it using the "default browser" function, it does not start at all, and Safari takes over.

If there is something simple I am doing wrong or not doing, or if I go about it completely wrong, please let me know.

+4
source share
1 answer

You need to modify the Info.plist file of your AppleScript application to register itself as an application capable of handling URLs. You must add the key CFBundleURLTypes and CFBundleURLSchemes http.

Then you need to add the open location handler to your AppleScript:

 on open location theURL ... end open location 

Mac OS X does not automatically detect that the Info.plist application has changed. Therefore, you need to force update the LaunchService database in the terminal using the lsregister command:

 /System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -v -f /path/to/AppleScript.app 

Also see the next page for more information.

+5
source

All Articles