Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'An improved 'Combine Windows' AppleScript for Safari' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
An improved 'Combine Windows' AppleScript for Safari
Authored by: itsajeepthing111 on May 14, '06 01:22:24AM

I was having problems with all of the applescript codes written above, don't know why, but I was. Thus, I wrote my own bassically from scratch. I am somewhat of beginner with applescript so feel free to point out errors or suggestions.
It consolidates all the open windows & tabs into a single new window with tabs, and gets rid of all duplicate pages including those on the frontmost window (i.e. the window selected when the applescript was activated). Only tested on Tiger. Hope this helps some ppl out.

set url_list to {}

tell application "Safari"
activate
try

--Goes Through Each Window--
repeat while (window 1 exists) and (document 1 exists)
set first_URl to the URL of document 1
set first_timeD to 1

--Goes Throught Each Tab--
repeat while ((the URL of document 1 is not equal to first_URl) or (first_timeD is equal to 1))
if first_timeD is equal to 1 then
set first_timeD to 0
end if
set this_URL to the URL of document 1
if url_list does not contain this_URL then
set url_list to url_list & this_URL
end if
tell application "System Events" to keystroke "}" using command down

--Reduce Beeping Noise--
delay 0.2

--End Tab Loop--
end repeat

close window 1

--End Window Loop--
end repeat

--Creates New Window to Consolidate Pages--
tell application "System Events" to keystroke "n" using command down
set the URL of document 1 to item 1 of url_list
repeat with w from 2 to (count of url_list)
my new_tab()
set the URL of document 1 to item w of url_list
end repeat

on error the error_message number the error_number
display dialog the error_message buttons {"OK"} default button 1
end try
end tell

on new_tab()
tell application "Safari" to activate
tell application "System Events"
tell process "Safari"
click menu item "New Tab" of menu "File" of menu bar 1
end tell
end tell
end new_tab



[ Reply to This | # ]
An improved 'Combine Windows' AppleScript for Safari
Authored by: itsajeepthing111 on May 14, '06 07:07:06PM

Here's an updated version, realized beeping noise was due to an invalid key press not because script was running to fast. Here it is:

set url_list to {}

tell application "Safari"
activate
try

--Goes Through Each Window--
repeat while (window 1 exists) and (document 1 exists)
set first_URl to the URL of document 1
set first_timeD to 1

--Goes Throught Each Tab--
repeat while ((the URL of document 1 is not equal to first_URl) or (first_timeD is equal to 1))
if first_timeD is equal to 1 then
set first_timeD to 0
end if
set this_URL to the URL of document 1
if url_list does not contain this_URL then
set url_list to url_list & this_URL
end if

--Checks to Make Sure There is Another Tab to selcet (Therfore Negating Beep Noise From Invalid Key Press)
tell application "System Events"
tell application process "Safari"
set selectNextEnabled to enabled of menu item "Select Next Tab" of menu "Window" of menu bar 1
end tell
end tell
if selectNextEnabled is true then
tell application "System Events" to keystroke "}" using command down
end if

--End Tab Loop--
end repeat

close window 1

--End Window Loop--
end repeat

--Creates New Window to Consolidate Pages--
tell application "System Events" to keystroke "n" using command down
set the URL of document 1 to item 1 of url_list
repeat with w from 2 to (count of url_list)
my new_tab()
set the URL of document 1 to item w of url_list
end repeat

on error the error_message number the error_number
display dialog the error_message buttons {"OK"} default button 1
end try
end tell

on new_tab()
tell application "Safari" to activate
tell application "System Events"
tell process "Safari"
click menu item "New Tab" of menu "File" of menu bar 1
end tell
end tell
end new_tab



[ Reply to This | # ]