Hi, I’m trying to make AppleScript extract some of the text that is being displayed on a Safari web page.
I can make AppleScript extract text based on the font of the text. However I get an error message when I try to extract text based on the color of the text.
Here is the web page:
[code]
Red TextI wrote an AppleScript called Safari_courier_font_text.scpt. It extracts text whose font is courier. Here is the content of that AppleScript:
tell application "Safari"
activate
set courier_text to (characters of text of document 1 whose font is "Courier") & return
display dialog (courier_text) as string
end tell
I display the web page, and then run the AppleScript. That AppleScript works fine.
I also created a file called safari_test_color.scpt. Here is the script:
[code]tell application “Safari”
activate
display dialog (characters of text of document 1) as text
set redColor to {65535, 0, 0} as RGB color
set red_text to ((characters of text of document 1) whose color = redColor)
end tell[/code]
I display the web page, and then run the AppleScript.
The display dialog works fine. (The display dialog is before the check for the color, to make sure that the “(characters of text of document 1)” is correct.)
However after the display dialog, I get this message:
AppleScript Error
Safari got an error: Can’t make color into type
reference.
Also, these characters are highlighted in my script:
(characters of text of document 1) whose color = redColor
What should I do, to make AppleScript extract text from the web page, based on color?
I’m running
Mac OS X 10.5.6 (9G55)
Safari Version 3.2.1 (5525.27.1)
Script Editor Version 2.2.1 (100.1)
on an iMac G5.
Thank you.