Refresh Chrome from the Mac Terminal using AppleScript

With the code below, I'm able to refresh the current tab in Chrome from the terminal. Focus remains in terminal :) ie. $ chromerefresh

First, create a file, make sure it's executable: ~/scripts/chromerefresh.sh
#!/bin/sh
exec <"$0" || exit; read v; read v; exec /usr/bin/osascript - "$@"; exit
# The line above allows the rest of the file to be written in plain AppleScript.
 
tell application "Google Chrome"
  activate
  tell application "System Events"
    tell process "Google Chrome"
      keystroke "r" using {command down, shift down}
    end tell
  end tell
end tell
 
tell application "Terminal" to activate
Then, in ~/.bash_profile , add this line:
alias chromerefresh="~/scripts/chromerefresh.sh"

Tags

Article Type

General