I'm attempting to write an applescript for Apptivate to open the current Firefox 4 or Safari tab in Google Chrome. The Safari section works and the if statement steps in to Firefox but it doesn't copy the URL.
Here is my applescript and it doesn't work:
tell application "System Events"
set myApp to name of first application process whose frontmost is true
if myApp is "firefox-bin" then
tell application "Firefox" to set theURL to the «class curl» of frontmost of window 1
tell application "Google Chrome"
activate
tell application "System Events" to keystroke "t" using {command down}
set URL of last tab of window 1 to theURL
end tell
else if myApp is "Safari" then
tell application "Safari" to set theURL to the URL in document 1
tell application "Google Chrome"
activate
tell application "System Events" to keystroke "t" using {command down}
set URL of last tab of window 1 to theURL
end tell
end if
end tell
What am I missing?
This might be tricky, but you can use keyboard shortcuts to copy and open the URL you want in Chrome. Check the code:
This script will first save your current clipboard, then it will check which browser is open. You can define the priority of browsers by sorting the if statement.
This is the same as pressing cmd+L (select url) and cmd+C (copy) on your browser.
Also, you can adapt the code to support other browsers.
(ApplicationIsRunning function from: http://vgable.com/blog/2009/04/24/how-to-check-if-an-application-is-running-with-applescript/)