Add local file URL handling to Applescript Application

I am using a simple applescript application to open different URL schemes in different Fluid Apps.

By setting this app as the default browser, I can effectively parse out the URL scheme and open the appropriate stand-alone Fluid App as the browser.

Everything works perfectly, except the “share this folder…” option in Dropbox. This opens a local URL - file:///var/folders/…

This simply does not work. The default_browser application launches and then immediately closes.

Does anyone know how to update this script so that local file links will work?

on open location this_URL

if this_URL contains "docs.google.com" then
    tell application "/Applications/Fluids/Google Drive.app"
        activate
        open location this_URL
    end tell
else if this_URL contains "drive.google.com" then
    tell application "/Applications/Fluids/Google Drive.app"
        activate
        open location this_URL
    end tell
else if this_URL contains "mail.google.com" then
    tell application "/Applications/Fluids/Gmail.app"
        activate
        open location this_URL
    end tell
else if this_URL contains "gmail.com" then
    tell application "/Applications/Fluids/Gmail.app"
        activate
        open location this_URL
    end tell
    -- default browser here
else
    tell application "/Applications/Google Chrome.app"
        activate
        open location this_URL
    end tell
end if
end open location

This script currently works with every link except the Dropbox “share this folder…” option - which opens the default browser app (above), which then closes immediately.

I assume you want to open those local files to open in their default app? If so, this should work:

set TIDs to text item delimiters
set text item delimiters to "//"
set pathPOSIX to text item 2 of this_URL
set pathHFS to POSIX file pathPOSIX
set text item delimiters to TIDs

tell application "Finder" to open pathHFS

Thanks - I’ll give that a try. The file Dropbox uses is an HTML file stashed away in the depths of the ~user folder. It would previously (before adding this handler app) open Chrome. Now it opens this app and does nothing.

Hopefully this will fix the issue! I’ll update.

T

Hi - I can’t seem to get this to work. I think the issue is two fold.

  1. I don’t know where to put the code above within my code
  2. I’m not sure what logic to use to run this code “if” the URL is a file path

Here’s what I have currently. It’s still not working…

on open location this_URL
	
	set TIDs to text item delimiters
	set text item delimiters to "//"
	set pathPOSIX to text item 2 of this_URL
	set pathHFS to POSIX file pathPOSIX
	set text item delimiters to TIDs
	
	if this_URL contains "docs.google.com" then
		tell application "/Applications/Fluids/Google Drive.app"
			activate
			open location this_URL
		end tell
	else if this_URL contains "drive.google.com" then
		tell application "/Applications/Fluids/Google Drive.app"
			activate
			open location this_URL
		end tell
	else if this_URL contains "mail.google.com" then
		tell application "/Applications/Fluids/Gmail.app"
			activate
			open location this_URL
		end tell
	else if this_URL contains "gmail.com" then
		tell application "/Applications/Fluids/Gmail.app"
			activate
			open location this_URL
		end tell
	else if this_URL contains "dropbox.com" then
		tell application "/Applications/Google Chrome.app"
			activate
			open location this_URL
		end tell
	else if this_URL contains "file:" then
		tell application "/Applications/Google Chrome.app"
			activate
			open pathHFS
		end tell
	else
		-- default browser here
		tell application "/Applications/Google Chrome.app"
			activate
			open location this_URL
		end tell
	end if
end open location

Well…
You’re right with #1 :wink: - you’ve mixed old and new, so to speak.
When you want to open a file you tell Finder to do it, and Finder will see to it that the file opens in the default app. You have given a Finder file reference to Chrome, which it does not know how to handle.
Replace all code within the above if-then block with what I gave you. Sorry for not making that clear sooner.
Also, I think all those activate commands are unnecessary - the open cmd should make the app come to the front.