Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Save selected browser text via AppleScript' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Save selected browser text via AppleScript
Authored by: bluedogranch on Feb 18, '08 10:33:41AM

Made progress on the learning curve to use BBEdit instead of the default text editor while also borrowing from other scripts in this thread, so this might be of use to others.

I will use this mostly to copy and save the "printer friendly" pages of news sites, as I save articles for research. Like the other scripts, this script gives me the date and the URL for future reference. At the end, I bring the new BBedit window forward so I can delete extra text and then save the file with my own title and/or date, depending on what I need for each research project.

This script selects all of the text in the front most Safari window or tab, converts the text to Unciode, and then makes a new BBedit document and pastes the clipboard, along with the date (from a shell script) and URL.

(Future enhancements might be adding "zap gremlins" to clean text or calling PlainClip to convert the clipboard to plain text before pasting.)


tell application "Safari"
activate
tell application "System Events"
tell process "Safari"
click menu item "Select All" of menu "Edit" of menu bar 1
click menu item "Copy" of menu "Edit" of menu bar 1
end tell
end tell
end tell

tell application "Safari"
set textclip to (the clipboard)
set theURL to (get URL of document 1)
end tell

try
set the clipboard to Unicode text of (the clipboard as record)
end try

set dat to (do shell script "date '+%m/%d/%y'") as text

tell application "BBEdit"
activate
make new document
set text of front document to (dat & return & return & (theURL) & return & return & textclip & return)
select insertion point 1 of contents of front document
end tell



[ # ]