Skip to content

Instantly share code, notes, and snippets.

@andrewle
Created March 11, 2010 00:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewle/328631 to your computer and use it in GitHub Desktop.
Save andrewle/328631 to your computer and use it in GitHub Desktop.
#!/bin/sh
# Textmate command that uses AppleScript to switch to Firefox, reload
# the browser, and then switch back to Textmate
# I have this bound to Ctl-Opt-Command R
#
# Save: Nothing (or Current File is useful too)
# Input: None
# Output: Discard
#
{
osascript -e "
tell application \"Firefox\"
activate
end tell
tell application \"System Events\"
tell process \"Firefox\"
keystroke \"r\" using {command down}
end tell
end tell
delay 1
tell application \"Textmate\"
activate
end tell"
}
@lingtalfi
Copy link

Awesome, thanks!

@jasonm23
Copy link

jasonm23 commented Jul 9, 2022

Save yourself some escaped quoting and leverage osascript's ability to read from stdin. (HEREDOC if you want to mix interpreters with bash/sh.

#!/usr/bin/osascript

-- reload firefox using cmd + R

tell application "Firefox"
  activate
end tell

tell application "System Events"
  tell process "Firefox"
    keystroke "r" using {command down}
  end tell
end tell

-- no need to wait.

tell application "Textmate"
  activate
end tell

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