Skip to content

Instantly share code, notes, and snippets.

@cmittendorf
Created June 20, 2014 07:08
Show Gist options
  • Save cmittendorf/dafc953b3425f523a8a7 to your computer and use it in GitHub Desktop.
Save cmittendorf/dafc953b3425f523a8a7 to your computer and use it in GitHub Desktop.
Retrieve the text content of the current web page from Safari
#!/usr/bin/env bash
# prepared for Yosemite (10.10)
# osascript -l JavaScript -e "Application('Safari').documents()[0].text()"
CONTENT=$(osascript -ss << EOF
tell application "Safari"
tell its first document
get its text
end tell
end tell
EOF)
# remove the first character
CONTENT="${CONTENT:1}"
# remove the last character
CONTENT="${CONTENT%?}"
echo "${CONTENT}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment