#!/bin/tcsh -f
#(ie run the tshell on this but don't read the .cshrc or .tcshrc)
echo version = 1.08 of browse 2020 Jun 01
# 2020 Jun 01, 1.08: fix internal documentation
# 2020 Jun 01, 1.07: switching to FireFox, to allow gose to work
# I got:
# firefox prevented this page from automatically redirecting to another page
# https://support.mozilla.org/bm/questions/985227
# How do you turn off "Firefox prevented this page from automatically reloading"
# google that
# https://support.mozilla.org/bm/questions/985227 FAIL - old info
# https://support.mozilla.org/en-US/questions/1178877
#
# Hi, the Options page was reorganized in Firefox 56 and that checkbox
# is no longer included. There is another way to change the setting:
#
# (1) In a new tab, type or paste about:config in the address bar and
# press Enter/Return. Click the button promising to be careful or
# accepting the risk.
#
# (2) In the search box above the list, type or paste access and pause
# while the list is filtered
#
# (3) If the accessibility.blockautorefresh preference is bolded and
# "modified" or "user set" to true, double-click it to restore the
# default value of false
#
# 2014 Dec 06, 1.06: use ish to launch browser remotely
# 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.'
echo
echo 'If your Firefox says:'
echo -n "firefox prevented this page from automatically"
echo " redirecting to another page"
echo "see:"
echo 'https://support.mozilla.org/en-US/questions/1178877'
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
if (`ish`) then
echo "transfer file for remote opening:"
echo "$tmp1"
xf "$tmp1"
else
echo "opening file:"
echo "$tmp1"
open "$tmp1"
endif
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