#!/bin/tcsh -f #(ie run the tshell on this but don't read the .cshrc or .tcshrc) echo version = 1.05 of browse 2011 Sep 07 # 2011 Sep 07, 1.05: applescript for browser choice # 2011 Sep 05, 1.04: thinking about passing args - how to specify browser? # 2011 Sep 04, 1.03: improve documentation # 2009 Nov 04, 1.02: document/cleanup # 2009 Nov 04, 1.01: functional # 2009 Nov 04, 1.00: origin from browser (full rewrite) if ($#argv == 0) then echo 'usage: browse [url] [browser]' echo 'This script opens the default browser to the given url.' echo 'The method is to create a web page in /tmp' echo 'that causes your browser to jump to the desired url.' echo 'If a brower is specified, use apple script to launch it.' exit endif set url = "$1" set tmp1 = /tmp/`whoami`-browse.html if ("$url" == '') then echo "No url given" endif if ($#argv == 1) then echo '' > $tmp1 echo '> $tmp1 echo '">' >> $tmp1 echo '> $tmp1 echo "$url" |tr -d '\n' >> $tmp1 echo '"' >> $tmp1 echo '>'"$url"'' >> $tmp1 echo '' >> $tmp1 echo "opening file:" echo "$tmp1" open "$tmp1" else set browser = "$2" # Launch the given $browser to the $url ls /Applications | grep -i $browser set browserapp = `ls /Applications | grep -i $browser|sed 's/\.app//'` echo browserapp $browserapp if !(-e "/Applications/${browserapp}.app") then echo "can't find a browser named $browser in /Applications" exit endif echo "browser: ${browserapp}" # google: # open safari to url echo "url: $url" # https://discussions.apple.com/thread/2770617?start=0&tstart=0 exec osascript << EOF >> /dev/null set theURL to "$url" tell application "$browserapp" activate try open location theURL end try end tell EOF endif exit ******************************************************************************** # how to get args?? # --args $#argv # # --args # All remaining arguments are passed to the opened application in the # argv parameter to main(). These arguments are not opened or inter- # preted by the open tool. THIS WORKS: # https://discussions.apple.com/thread/2770617?start=0&tstart=0 exec osascript << EOF >> /dev/null set theURL to "http://www.apple.com" tell application "Safari" activate try tell window 1 to set current tab to make new tab with properties {URL:theURL} on error open location theURL end try end tell EOF That fails to repeat. Simplify: # https://discussions.apple.com/thread/2770617?start=0&tstart=0 exec osascript << EOF >> /dev/null set theURL to "http://www.apple.com" tell application "Safari" activate try open location theURL end try end tell EOF