Skip to content

Instantly share code, notes, and snippets.

@wolph
Forked from dennyweiss/reload_chrome.sh
Last active February 5, 2018 12:52
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wolph/3c1b65217aa7b923f609 to your computer and use it in GitHub Desktop.
Save wolph/3c1b65217aa7b923f609 to your computer and use it in GitHub Desktop.
#!/bin/sh
exec <"$0" || exit; read v; read v; exec /usr/bin/osascript - "$@"; exit
-- the above is some shell trickery that lets us write the rest of
-- the file in plain applescript
-- Usage:
-- For a simple reload and nothing else:
-- # sh reload_chrome.sh
-- For a reload with activating a different app after (iTerm in this case):
-- # sh reload_chrome.sh iTerm
-- For a reload with activating iTerm and sleeping for 0.5 seconds (in case of a busy computer)
-- # sh reload_chrome.sh iTerm 0.5
-- Enable reading argv for commandline arguments
on run argv
-- If we have 2 arguments, the second will be the delay
if (count of argv) > 1 then
set delayInSeconds to item 2 of argv
else
set delayInSeconds to 0.1
end if
tell application "Google Chrome"
activate
tell application "System Events"
tell process "Google Chrome"
-- A little bit of delay since OS X takes some time to switch applications
delay delayInSeconds
keystroke "r" using {command down, shift down}
delay delayInSeconds
end tell
end tell
end tell
-- If we have 1 or more arguments, the first will be the application to activate after reloading
if (count of argv) > 0 then
set targetApp to item 1 of argv
tell application targetApp to activate
end if
end run
@wolph
Copy link
Author

wolph commented Feb 12, 2015

Usage:

  • For a simple reload and nothing else:

    sh reload_chrome.sh
    
  • For a reload with activating a different app after (iTerm in this case):

    sh reload_chrome.sh iTerm
    
  • For a reload with activating iTerm and sleeping for 0.5 seconds (in case of a busy computer)

    sh reload_chrome.sh iTerm 0.5
    

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment