6

I open a lot of tabs which are important for me. Isn't there an easier way to install something that creates a TextEdit file on my desktop with all URLs open at the time?

In the past I used Eelee's SafariTabsListDs but this doesn't seem work anymore.

Can you help me with something that I can use to reopen the tabs I want after closing them?

0

4 Answers 4

6

The following example AppleScript code will write the URL of every tab of every window of Safari to a file named MyURLs.txt on your Desktop:

set myURLs to {}
tell application "Safari" to set myURLs to the URL of every tab of every window
set text item delimiters to linefeed
set myURLs to myURLs as text
set text item delimiters to {}
if not myURLs is equal to "" then
    do shell script "echo " & myURLs's quoted form & "> $HOME/Desktop/MyURLs.txt"
end if

To open the URLs in, e.g., MyURLs.txt you can use, e.g.,:

set myURLs to {}
try
    set myURLs to paragraphs of (do shell script "cat $HOME/Desktop/MyURLs.txt")
end try
if not myURLs is equal to {} then
    repeat with thisURL in myURLs
        open location thisURL
    end repeat
end if
  • The example AppleScript code above assumes Safari is your default web browser.

Note: The example AppleScript code is just that and does not contain any additional error handling as may be appropriate. The onus is upon the user to add any error handling as may be appropriate, needed or wanted. Have a look at the try statement and error statement in the AppleScript Language Guide. See also, Working with Errors. Additionally, the use of the delay command may be necessary between events where appropriate, e.g. delay 0.5, with the value of the delay set appropriately.

0
6

List the URL of all tabs in the frontmost Safari window using the command line of the Terminal app:

osascript -e{'set text item delimiters to linefeed','tell app"safari"to(url of tabs of window 1)as text'}

List the URL of all tabs in all windows:

osascript -e{'set text item delimiters to linefeed','tell app"safari"to(url of tabs of windows)as text'}

List the URL and title of all tabs in the frontmost window:

osascript -e{'set o to""','tell app"safari"','repeat with t in tabs of window 1','set o to o&url of t&" "&name of t&"\n"',end,end,o}|sed \$d

To save the output of any of these three commands to a file called my_safari_session.txt in your home directory, append > ~/my_safari_session.txt to the end of the command; e.g.:

osascript -e{'set text item delimiters to linefeed','tell app"safari"to(url of tabs of window 1)as text'} > ~/my_safari_session.txt
0

You should first look at the available options that can do the required.

  • Simplest is the history: Hit command+Y you can get a list of visited sites that can be sorted by time. Also, if you select multiple sites, using shift+click or command+click, or shift + up/down arrow, you can open all of them in one go. You can also copy all the selected items, paste in a note in Notes app and you'll get links.
  • Bookmarks or reading list: Safari gives an option in Bookmarks menu to add all tabs in a window to be added to Bookmarks or reading list. You’ll need to clear them periodically though. But the good part is that you can export that too, using File menu > "export bookmarks" to an HTML file which is easy to click links through.

If you’re worried that you lose a session when you close Safari, you should do this: Open system preferences > General & uncheck “close windows when quitting an app“

enter image description here

Now you can Quit safari using command+Q & when you open it later all tabs and windows appear, including those in private mode.

An AppleScript can also store all open tabs' URL in all windows to a text file. A good starting point is:

0

I appreciate the answers on this page. I have added a dialog to allow user to select Safari's front window, or all windows. I hope this may be useful to someone. (I failed to get the date prefix working.)

    set currentDate to do shell script "date +%Y-%d-%m"
    --display dialog currentDate
    set theDialogText to "Write Safari tab URLs to a Desktop text file ...
    Select only the foremost window, or all windows"
    display dialog theDialogText buttons {"cancel", "window 1", "all windows"} default button "window 1" cancel button "cancel"
    set BUTTON_Returned to button returned of result
    set myURLs to {}
    if BUTTON_Returned is "window 1" then
        tell application "Safari" to set myURLs to the URL of every tab of (window 1)
    end if
    if BUTTON_Returned is "all windows" then
        tell application "Safari" to set myURLs to the URL of every tab of (windows)
    end if
    set text item delimiters to linefeed
    set myURLs to myURLs as text
    set text item delimiters to {}
    if not myURLs is equal to "" and BUTTON_Returned is "window 1" then
        do shell script "echo " & myURLs's quoted form & "> $HOME/Desktop/MyURLs.txt"
        --set filename of "~/Desktop/MyURLs.txt" to currentDate & " " & "myURLs.txt"
    end if
    if not myURLs is equal to "" and BUTTON_Returned is "all windows" then
        do shell script "echo " & myURLs's quoted form & "> $HOME/Desktop/MyURLs++.txt"
    end if

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .