(* Load Tab in New Window 1.0 by Jim DeVona http://anoved.net/load_tab_in_new_window.html 19 December 2006 Close the frontmost Safari tab and reload it in a new window. Requirements: UI Scripting Developed with Safari 2.0.4 on Mac OS X 10.4.8 Suggested installation location: ~/Library/Scripts/Applications/Safari/ You can invoke this script with the standard Mac OS X Script Menu or any one of many excellent third party utilities that allow keyboard shortcuts to be assigned to scripts. Issues: - UI scripting in close_tab() often hangs on my G4; too bad Safari's tabs weren't scritable directly: http://daringfireball.net/2003/05/safaris_unscriptable_tabs.html - Ideally the page would just be "moved" to a new window without reloading it. *) tell application "Safari" -- identify the current page try set theURL to URL of front document set title to name of front document on error -- no document return end try -- test whether the URL is defined try theURL on error -- blank document return end try -- try to close the current tab set closeResult to my close_tab() -- stop if it is already the only tab or if tabbed browsing is disabled if closeResult is equal to 1 then display alert "\"" & title & "\" is already the only tab in this window." as informational giving up after 60 return else if closeResult is equal to 2 then display alert "Tabbed browsing or UI scripting is not enabled." message "Check \"Enable Tabbed Browsing\" in the Tabs preference pane. Check \"Enable access for assistive devices\" in the Universal Access System Preferences pane to enable UI scripting." as warning giving up after 60 return end if -- load the URL in a new window make new document with properties {URL:theURL} end tell on close_tab() tell application "Safari" to activate tell application "System Events" tell process "Safari" try -- sporadic lag here on my G4 set closeCmd to menu item "Close Tab" of menu "File" of menu bar item "File" of menu bar 1 on error -- no such command (tabbed browsing off) or no UI scripting in general return 2 end try if enabled of closeCmd is false then -- disabled because it is the only tab (could Close Window instead) return 1 else click closeCmd return 0 end if end tell end tell end close_tab