Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Applications > Scripting Safari: How to get it to open links of a page in tabs

Scripting Safari: How to get it to open links of a page in tabs
Thread Tools
Posting Junkie
Join Date: Nov 2000
Location: in front of my Mac
Status: Offline
Reply With Quote
Feb 13, 2004, 02:52 AM
 
Short version: I have a html file full of links. I want Safari to open the links of that page in a separate tab each.
Is there a way to script Safari or any app that will let me do this automatically?


Long version: You get emails from macnn when new posts arrive in threads you've subscribed to. Now, when you've been away for a while there can be very many of those emails waiting. What do you do? Select all of them, open them, click on the link to let Safari open it, switch back to Mail.app, delete that email, click on the link of the next email, etc. No way! Much too much hassle.

So, I wanted to do it automatically. I wrote a little shell script that gets the URLs out of the macnn emails, puts them in a file, adds html tags to the URLs, opens Safari and displays the list of links.

Code:
grep 'newpost' /Users/simon/Library/Mail/pop/INBOX.mbox/mbox > /tmp/new.txt awk '{print "<a href=\"" $1 "\">" $1 "</a><br>"}' /tmp/new.txt > /tmp/new.html open -a /Applications/Safari.app /tmp/new.html sleep 2 rm /tmp/new.txt rm /tmp/new.html
Now I can ctrl-click all of these links in Safari to get them to open in new tabs each, but that's still too much work.

But if I could pipe that file to an AppleScript I could have the script open up each URL in a new tab.

Any ideas how to do that?
     
Simon  (op)
Posting Junkie
Join Date: Nov 2000
Location: in front of my Mac
Status: Offline
Reply With Quote
Feb 13, 2004, 04:09 AM
 
OK, in the mean time I figured it out. AppleScript documentation sucks, but there is a nice website for scripting: http://macscripter.net/scriptbuilders/ It has a Safari section which led me to a script that I adapted for this situation.

For those interested, here is the final result. It's a little shell script that makes an AppleScript and executes it.

Code:
#!/bin/bash # grep 'newpost' ~/Library/Mail/pop/INBOX.mbox/mbox > /tmp/tmp.txt echo "tell application \"Safari\" " > /tmp/tmp.script echo "activate" >> /tmp/tmp.script awk '{print "open location \"" $1 "\""}' /tmp/tmp.txt >> /tmp/tmp.script echo "end tell" >> /tmp/tmp.script osascript /tmp/tmp.script sleep 2 rm /tmp/tmp.script /tmp/tmp.txt
     
Junior Member
Join Date: Sep 2000
Location: San Francisco, CA
Status: Offline
Reply With Quote
Feb 13, 2004, 05:46 PM
 
Originally posted by Simon:
Short version: I have a html file full of links. I want Safari to open the links of that page in a separate tab each.
Is there a way to script Safari or any app that will let me do this automatically?
there's some commentary on that here: (buried in a review of Omniweb5)

http://daringfireball.net/2004/02/omniweb_5_public_beta
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 10:26 AM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2