• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
saving displayed text on a web page as rtf
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

saving displayed text on a web page as rtf


  • Subject: saving displayed text on a web page as rtf
  • From: 2551 <email@hidden>
  • Date: Thu, 04 Jul 2013 17:18:26 +0700


Friends, I have a headache.

I’m trying to get some text displayed on a web page into a .rtf document that I can save locally. The text I’m trying to get cannot be got from the page source - it’s all done server side and delivered on loading. Looking at the document source it’s all just _javascript_ code. Still...selecting the text displayed on the page manually via Cmd-A and Cmd-C and Cmd-V into a TextEdit document works perfectly. However, trying to automate that has proven...painful, to say the least.

This is clumsy I know, but I’m just trying to get proof-of-concept before tidying this up into decent code. Half the time, I get the result I want. And the other half I either get a blank .rtf doc, a crash or no doc at all. The Delay’s seem to help a little, but there must be a better way to do this? Any thoughts much appreciated My head hurts from wrestling with this over two days, and I’ve been through every post on macscripter and other sites to no avail. 


In the following code, assume the tab with the desired data is already loaded and frontmost in Safari when Safari is activated:


set _filename to "Reports"
set _dateStamp to (do shell script "date +_%Y-%m-%d_%H.%M.%S")
set _newFile to (path to desktop as string) & _filename & _dateStamp & ".rtf"


tell application "Safari" to activate
tell application "System Events"
tell application 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

delay 0.5

tell application "Safari" to close current tab of window 1

tell application "TextEdit"
activate
set f to make new document
end tell

tell application "System Events"
tell application process "TextEdit"
click menu item "Paste" of menu "Edit" of menu bar 1
end tell
end tell

tell application "TextEdit"
save f in file _newFile
close window 1
quit
end tell

 


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Re: saving displayed text on a web page as rtf
      • From: KOENIG Yvan <email@hidden>
    • Re: saving displayed text on a web page as rtf
      • From: Kaydell Leavitt <email@hidden>
    • Re: saving displayed text on a web page as rtf
      • From: Brian Christmas <email@hidden>
    • Re: saving displayed text on a web page as rtf
      • From: Paul Fidler <email@hidden>
  • Prev by Date: Re: UNIX bounce command
  • Next by Date: Re: saving displayed text on a web page as rtf
  • Previous by thread: Re: UNIX bounce command
  • Next by thread: Re: saving displayed text on a web page as rtf
  • Index(es):
    • Date
    • Thread