Skip to content

Instantly share code, notes, and snippets.

@andyfowler
Created July 8, 2010 19:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andyfowler/468446 to your computer and use it in GitHub Desktop.
Save andyfowler/468446 to your computer and use it in GitHub Desktop.
# ideal for textmate bundle, reloads the current tab's CSS
# JS via http://david.dojotoolkit.org/recss.html
refreshScript=`cat <<'JAVASCRIPT'
void(function(){var i,a,s;a=document.getElementsByTagName('link');for(i=0;i<a.length;i++){s=a[i];if(s.rel.toLowerCase().indexOf('stylesheet')>=0&&s.href) {var h=s.href.replace(/(&|\\\?)forceReload=\\\d+/,'');s.href=h+(h.indexOf('?')>=0?'&':'?')+'forceReload='+(new Date().valueOf())}}})();
JAVASCRIPT
`
# Check if Safari is running, if so refresh CSS
ps -xc|grep -sq Safari && osascript <<APPLESCRIPT
tell app "Safari"
activate
do JavaScript "$refreshScript" in document 1
end tell
APPLESCRIPT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment