#!/bin/csh -f # o # ----------------------------------------------------------------------------- # Shell script to open the specified file, via the open command, defaulting # to a browser at my home page. # ----------------------------------------------------------------------------- if ($#argv < 1) then # No args. Default to my home page. (set echo; open http://bristle.com/~fred/) else if ($#argv > 1) then # Multiple args. No logic in place yet to loop through them. Just do # default open. (set echo; unquarantine $*:q) (set echo; open $*:q) else if (-e $*:q) then # File exists. Open it. (set echo; unquarantine $*:q) # 3/9/2019: Weird quirk: Sometimes opening the file sets the quarantine # attribute again. Huh? Confirmed manually via dir, unquarantine, dir, # open, dir. # So far, only certain for PNG file: # - ~/Desktop/2019-03-05_MikeKristyEmilyAmandaStevens.png # but I seem to have more quarantined files around lately than usual. # When did this start happening? # Caused by being on Desktop? No, still happens after I moved it to: # - ~/pictures/Pictures/1011King/Neighbors/ # 2019-03-05_MikeKristyEmilyAmandaStevens.png # # 4/12/2021: # Now happening very consistently. Preview always sets the # com.apple.quarantine xattr. To see the effect: # ls -l@ a.jpg ; pause ; unquarantine a.jpg ; ls -l@ a.jpg ; pause ; \ # open a.jpg ; sloop ls -l@ a.jpg # See my unquarantine script for how to clear the xattr, and notes on # how it may be possible to stop files from ever being quarantined: # (set echo; open $*:q) else # File doesn't exist locally. We'll try it as a URL instead. # Calling open doesn't work when the arg contains an embedded space. # Perhaps open checks its arg for spaces and refuses to treat it as a URL? # Reports messages like: # The file /Users/fred/http:/google.com/search?q=a b does not exist. # Translate all spaces (" ") to plus signs ("+"). #?? Better yet, urlencode the string! See how in my tweet script. set url = "`echo '$*:q' | tr ' ' '+'`" if (`echo $url:q | cut -c 1-7` == "http://") then # Arg starts with "http://". Open it. (set echo; open $url:q) else if (`echo $url:q | cut -c 1-8` == "https://") then # Arg starts with "https://". Open it. (set echo; open $url:q) else # No such file. Try "http://" prefix. (set echo; open http://$url:q) endif endif