Sunday, August 20, 2017

#1 2005-10-12 07:11:23 am

julifos
Administrator
From:: Malasaña, Madrid
Registered: 2002-11-20
Posts: 2014

How can I copy the text displayed in a web page (not the HTML code)?

If you use Safari, you can use this simple code:

Applescript:

tell application "Safari"
   text of document 1
end tell

If you will use a different browser which doesn�t support such methods, you can use UI Scripting (System Events 1.2.1 is built-in in Panther, and there is a previous beta version available for Jaguar).

The concept is very simple: use the common menu items "Select all" and "Copy", then pick your stuff from the clipboard. You may adjust this code depending on your browser:

Applescript:

tell application "System Events"
   tell process "Safari"
       set frontmost to true --> bring app to the foreground
       click menu item 8 of menu 1 of menu bar item 4 of menu bar 1 --> select all
       click menu item 5 of menu 1 of menu bar item 4 of menu bar 1 --> copy        
   end tell
end tell
set theText to the clipboard

You can find here some tools to help you developing UI scripts.


Filed under: safari, System

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)