views:

23

answers:

1

My goal is to make it so that links clicked on one osx machine are loaded into safari on a remote computer with apple events enabled. To do this, I am trying to create an applescript application which i then make the default browser on the system.

My applescript 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 the appropriate method to use to capture the url, I've simplified the script right down to:

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

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

Why is this ? Do I need to do something special for my Applescript to act as a browser ? If I run my applescript application by double clicking on it, it does exactly what it's supposed to do, but if I launch it via the "default browser" feature, it doesn't run at all and instead Safari takes over.

If there's something simple I'm doing wrong or not doing or if I'm going about it totally the wrong way please let me know.

+1  A: 

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

Then you have to add an open location handler to your AppleScript:

on open location theURL
 ...
end open location

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

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

Also see the following page for more information.

sakra
Thank you, this worked great !
Pawz Lion