Results 1 to 8 of 8

Thread: Script to open all Reading List items in Safari and then import to EagleFiler

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1

    Default Script to open all Reading List items in Safari and then import to EagleFiler

    Hello all,
    I have assembled an AppleScript to help automate the process of importing links from Safari's Reading List to EagleFiler. I would appreciate feedback and any suggestions for improvement--it hasn't failed on me yet, but I am especially interested in code or strategies to make it more robust.

    Background: I often save dozens if not hundreds of links to the Reading List in Safari (mostly on iOS) over the course of a few months. To get these links into my archive library in EagleFiler, I then periodically open 10-20 in Safari tabs at a time and use the standard "Import Safari Tabs" AppleScript. This is a slow and rather labor intensive process. At various times, I have tried opening 30, 40, 50, ..., 100 tabs at a time, but for me these large imports have not been uniformly successful (I haven't looked into the problem in detail to know why the large import fails).

    Assumptions: The script is saved in the EagleFiler script folder, Safari is open but all windows are closed***, EagleFiler is open and is the active application.

    ***This script works only on visible Safari windows, so if you have open windows that you do not want to import then just minimize them to the dock.

    Workflow for this script:
    1. EagleFiler -> AppleScript menu item -> Import Safari Reading List (or whatever you named it)
    2. Safari will be selected as the active application and windows will start opening each with 12 tabs (if there are less then 12 links in the Reading List then that number of tabs will open in only one window)
    3. A dialog box will open and ask that you wait for all of the tabs to finish loading. This is also where you can review and close any unwanted tabs. Click "Continue" when you are ready to proceed.
    4. EagleFiler is selected as the active application. The script will loop through each window and import up to 12 tabs at a time. You can open the activity window to monitor the progress.

    Additional steps: Unfortunately, this script does not clean up after itself. You will still need to close all of the Safari windows (this should be trivial, but I didn't fit it in today). You will also need to open the Reading List in Safari and "Clear All Items ..." (this seems much less trivial based on needing to edit the plist file?).

    Citation links to the material that I used to assemble this script can be found in the header.

    -- import-safari-reading-list
    -- Modified From:
    -- Last Modified: 2017-02-06
    -- Sets tfile to look at Safari's bookmarks file, which contains the Reading List
    set tfile to (path to library folder from user domain as text) & "Safari:bookmarks.plist"
    -- Creats a blank list, which will later have Reading List items added to it.
    set theURLs to {}
    -- System Events lets you access the content of a plist
    tell application "System Events"
    	-- Check each item in the Safari bookmarks file 
    	repeat with i in (property list items of property list item "Children" of property list file tfile)
    		tell i to try
    			-- Check the item to see if it is a part of the Reading List
    			if value of property list item "Title" = "" then
    				repeat with thisDict in (get value of property list item "Children")
    					-- Add item to list of URLs to open
    					tell thisDict to set end of theURLs to its URLString
    				end repeat
    				exit repeat
    			end if
    		end try
    	end repeat
    end tell
    -- Get the length of the URL list
    set listSize to count of theURLs
    -- Script switches to Safari
    activate application "Safari"
    tell application "Safari"
    	-- This is the main loop
    	-- Loop opens as many new windows each with 12 tabs as necessary
    	-- Found that importing more than 12 tabs in EagleFiler can sometimes fail unexpectedly
    	set i to 1
    	repeat until i is greater than listSize
    		if i is greater than listSize then
    			exit repeat
    			-- Opens a new window with one URL
    			set {firstURL} to {item i of theURLs}
    			make new document at end of documents with properties {URL:firstURL}
    			set i to i + 1
    		end if
    		repeat with j from 1 to 11
    			if i is greater than listSize then
    				exit repeat
    				-- Opens additional tabs (up to total of 12) in the new Window
    				tell window 1
    					set {theURL} to {item i of theURLs}
    					make new tab at end of tabs with properties {URL:theURL}
    				end tell
    				set i to i + 1
    			end if
    		end repeat
    	end repeat
    end tell
    -- Open a dialog box to allow tab trimming before import
    -- Also acts as a delay to allow URLs to open
    set answer to ""
    repeat while answer is equal to ""
    	display dialog "Check that all Safari tabs have loaded. Close any tabs that you do not want to import." buttons {"Continue"} default button 1
    	set answer to button returned of result
    end repeat
    activate application "EagleFiler"
    -- Import to EagleFiler one window at a time
    tell application "Safari"
    	set windowList to (every window whose visible is true)
    	repeat with windowVariable in windowList
    		set _urls to URL of every tab of windowVariable
    		tell application "EagleFiler"
    			import URLs _urls
    		end tell
    	end repeat
    end tell
    Attached Files Attached Files

Similar Threads

  1. Reading emails in EagleFiler
    By Phoebe in forum EagleFiler
    Replies: 3
    Last Post: 06-15-2012, 09:13 PM
  2. All open Safari tabs to EF?
    By soulbarn in forum EagleFiler
    Replies: 1
    Last Post: 08-31-2011, 02:09 PM
  3. Replies: 2
    Last Post: 08-09-2010, 02:54 PM
  4. How to import web page via Reader in Safari 5?
    By Josef in forum EagleFiler
    Replies: 2
    Last Post: 07-02-2010, 11:04 AM
  5. Script for the items in subfolders?
    By sooinlee1 in forum EagleFiler
    Replies: 4
    Last Post: 03-07-2010, 03:02 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts