Have different options for set link_text to "text"

Hi

I would like to know if it’s possible to have different option for the applescript set link.text.

I have the following script:

set link_text to "abc"

but the page I running it from, something has different ways to write abc, for example it is “abc d” or “a bcd”, so I was wondering if there was a way to say:

set link_text to "abc" or "abc d" or "a bcd"

Thank you!

From one line of code it’s quite difficult to guess what you’re going to accomplish.
Assuming you want to compare something with link_text use a list

set link_text_list to {"abc", "abc d", "a bcd"}
if something is in link_text_list then doSomethingElse()

But if link_text represents only a partial string you have to compare each expression

if something contains "abc" or something contains "abc d" or something contains "a bcd" then doSomethingElse()

The ideal scenario would be this:


set link_text to "abc" 
if not found then set link_text to "abc d"
if not found then set link_text to "a bcd"

Hi Stefan,

This is the actual script which I am trying to modify:

set link_text to "abc"

tell application "Safari"
	activate
	-- wait until page loaded
	if my page_loaded(20) is false then error numner - 128
	-- get number of links
	set num_links to (do JavaScript "document.links.length" in document 1)
	-- find the link
	set c to num_links - 1
	set this_link to ""
	set f to false
	repeat with i from 0 to c
		set this_link to do JavaScript "document.links[" & i & "].text" in document 1
		if this_link is link_text then
			set f to true
			exit repeat
		end if
	end repeat
	if f then -- link text found
		-- get the url and open the link url
		set link_url to do JavaScript "document.links[" & i & "].href" in document 1
		open location link_url -- opens in new page
	else
		display dialog "Link \"" & link_text & "\" not found."
	end if
end tell
--
on page_loaded(timeout_value)
	delay 2
	repeat with i from 1 to the timeout_value
		tell application "Safari"
			if (do JavaScript "document.readyState" in document 1) is "complete" then
				return true
			else if i is the timeout_value then
				return false
			else
				delay 1
			end if
		end tell
	end repeat
	return false
end page_loaded

for this script you can use the list version


set link_text_list to {"abc", "abc d", "a bcd"}

tell application "Safari"
.
if this_link is in link_text_list then
.

Yep just tried and it works like a charm! Perfect!

Thank you very much!