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


Click here to return to the 'Save selected text from Safari to a text file' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Save selected text from Safari to a text file
Authored by: Lankhmart on Feb 23, '04 12:31:41PM
You can grab the selection in Safari without using UI Scripting or the clipboard with a "do JavaScript" command like this (also eliminating the 2 second delay):

tell application "Safari"
	activate
	set myURL to URL of document 1
	set myData to do JavaScript "getSelection();" in document 1
end tell

set myDate to current date
set fPath to path to desktop
set fName to (do shell script "date \"+%Y-%m-%d\"") & ".txt"
set myFile to open for access file ((fPath as string) & fName) ¬
	with write permission
write "=== " & return & "Date: " & myDate & return & ¬
	"Text from: " & myURL & return & return & myData to myFile starting at eof
close access myFile


[ Reply to This | # ]
OmniWeb version of save selected text
Authored by: Krioni on Feb 23, '04 03:18:32PM
To do this in OmniWeb: (in place of the tell app "Safari"...end tell part)

tell application "OmniWeb"
	set myURL to address of browser 1
	set myData to do script "getSelection();" window browser 1
end tell

Then add in the rest of the parent poster's script.

[ Reply to This | # ]

Save selected text from Safari to a text file
Authored by: orpy on Feb 24, '04 03:00:38PM

Thanks for the javascript tip.

I use javascript all the time to control Photoshop from AppleScript - didn't even give it a thought with Safari...

The script has been updated in the week or so since posting it here. I'd adapted it so that it would copy the whole page as text if nothing was selected.

You can find a more up to date version here:

http://prometheus.idea-digital.com/phpbb2/viewtopic.php?t=164

Regards

--
Martin



[ Reply to This | # ]