|
#1
| |||
| |||
| Applescript for Safari and Firefox Anyone hove good knowledge of Applescript? I want to create a simple Applescript that involves transferring an active URL from Safari to Firefox and back. I'd like to correspond with someone. |
|
#2
| ||||
| ||||
| Going from Safari to Firefox is trivially easy: Code: tell application "Safari" set the_url to the URL of document 1 tell application "Firefox" activate Get URL the_url end tell end tell Code: tell application "Firefox" activate tell application "System Events" keystroke "l" using command down keystroke "c" using command down end tell tell application "Safari" activate set the URL of document 1 to (the clipboard) as text end tell end tell Hope this helps. |
|
#3
| |||
| |||
| Thanks for the scripts. They work great. Here is why I wanted them. Sometimes a site will not render properly in one of the browsers. This script allows me to quickly switch browsers without having to type in the URL. You should publish them somewhere. Neal |
|
#4
| ||||
| ||||
| If you enable the Debug menu in Safari, there is an option (almost at the bottom) to open the page in any other browser you might have installed. No scripts needed. You can also copy the url, activate Quicksilver, type . then paste the url, tab, select Open With, tab, select the browser of your choice, enter. Sounds like a lot of work, but it works and I did that faster than using Safari's Debug menu ...
__________________ This is not a signature (but I could be wrong). 15" MacBook Pro C2D@2.4 GHz | 2 GB RAM | Mac OS 10.5.4 | Website | LinkedIn | Publications GP/O d-(+)@ s: a->? C++(+++) U* P+ L+>++ !E---- W+++ N o? K? w--- O? M++ V? PS+++ PE-- Y+ PGP t 5? X- R !tv b++++ DI+(++)@ D+(++) G++(+++) e+++$>++++$$ h--->---- r+++ y++++@ |
|
#5
| ||||
| ||||
| If you have both browsers open, you could also just drag the URL icon to the other open browser window.
__________________ |
|
#6
| ||||
| ||||
| 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 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. |
|
#7
| ||||
| ||||
| For some reason I can't edit my last post, so I have to make a new post. There's a bug with some versions of Firefox that makes it do weird things when you run my script when it's not yet loaded. To fix it, move the "activate" line after the "get url..." line in my above script. Then it works just fine. Well...at least for the versions I've tested. Firefox is so inconsistent.... |
|
#8
| |||
| |||
| how do I disable debug in safari? |
![]() |
| Thread Tools | |
|
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Switch from safari to firefox | sum_ifx_i | Mac OS X System & Mac Software | 37 | August 1st, 2005 08:35 AM |
| Should Apple Ride the FireFox Wave? | jeb1138 | Apple News, Rumors & Discussion | 18 | March 2nd, 2005 04:32 PM |
| different result in safari and firefox | j2603 | Design & Media | 1 | November 19th, 2004 03:31 PM |
| Firefox Security Update | bobw | Mac OS X System & Mac Software | 2 | October 2nd, 2004 07:10 PM |