MacOS – Add urls to a list via Automator

automatorgoogle-chromemacossafari

What is the simplest way to append a list of urls with a selected URL when browsing either chrome or safari. I tried to do this with automator and it was easy to achieve by creating a service with a Write Text to File action (from an add on package). But it does not add a new line after each entry. It doesn't even write a space after an entry. So you end up with a file like

http://example./Ahttp://example.com/Bhttp://example.com/Chttp://example.com/Dhttp://example.com/Ehttp://example.com/F

My next attempt to use a Split Text action somehow resulted in 100 new files being created, each containing a single URL. (>_<)

What I'm trying to achieve is:

  • Select a URL in the browser's (chrome or safari) address bar
  • Right click the highlighted URL to get to the services menu
  • Click on the created service (we'll call it Add to List)
  • Add the selected URL to text file in the Home folder followed by a new line.

The desired output being:

http://example.com/A
http://example.com/B
http://example.com/C
http://example.com/D
http://example.com/E
http://example.com/F

Any help would be very much appreciated.

Thank you.

Best Answer

This seems like an effective solution. A single Automator Run AppleScript action with the following script:

set text item delimiters to linefeed
set my_list to "/Users/username/Documents/URL_list.txt"
tell application "Google_Chrome" to set new_items to (get the URL of the active tab in window 1) as string
do shell script "echo  " & quoted form of new_items & " >>  " & quoted form of my_list

display dialog new_items with title "Added to the list"
  • Save as a service
  • Service receives selected URLs
  • Input is only URLs (probably doesn't matter)
  • Tested and working in both Safari and Google Chrome
    • If using Safari change the get the URL of the active tab in window 1 to get the URL of the current tab in window 1. Just to clarify: use active tab for Chrome and use current tab for Safari.
    • If you have several windows and tabs open and want to grab every URL to populate a list: tell application "Google_Chrome" to set new_items to (get the URL of the tabs in every window) as string

enter image description here