I just wrapped my two script snippets from before into a single script, if anyone's interested. If Safari is the active app, it'll take its URL and load it into Firefox. If Firefox is the active app, it'll do the reverse. I'm using it with iKey so I can easily go from one to another with the same shortcut.
Keep in mind that because of the hacky way I get Firefox's URL (by simulating command-L and command-C), if you have any modifer keys besides Command pressed when the script activates, it won't be able to get Firefox's URL. Kind of a bummer, but I don't know of any way to work around it. I personally have command-F1 set to trigger the script (when one of the browsers is in the front).
Here's the new script:
Code:
tell application "System Events"
set the_list to the displayed name of every process whose frontmost is true
if (the_list contains "Firefox") then
tell me to firefox_to_safari(0)
else if the_list contains "Safari" then
tell me to safari_to_firefox(0)
end if
end tell
on safari_to_firefox(x)
tell application "Safari"
set the_url to the URL of document 1
tell application "Firefox"
activate
Get URL the_url
end tell
end tell
end safari_to_firefox
on firefox_to_safari(x)
tell application "Firefox" to activate
tell application "System Events"
--WARNING: THIS OVERWRITES THE CLIPBOARD CONTENTS!
keystroke "l" using command down
keystroke "c" using command down
end tell
tell application "Safari"
activate
if the number of documents is 0 then make new document
set the URL of document 1 to (the clipboard) as text
end tell
end firefox_to_safari
I'm not quite sure why I need to have a parameter in my custom methods, but it gives me errors if I don't, so I'm passing in 0 to make it happy. *shrug*
Oh, and I also tried to make it save and restore the clipboard contents, like I mentioned before, but I couldn't get it working. It worked with plain text, but not styled text. So I decided not to bother. If it's not going to work for all clipboard contents, it's probably best that it doesn't work for any. Don't want to lull anyone into a false sense of security.
If anyone feels compelled to host and distribute this script, feel free.