Reputation: 26
I am trying to automate the process of opening specific links that are sent by email.
The email has multiple links in it including one to unsubscribe from the service, so opening the correct link and not all links is important.
The process flow would be:
This is what I have that is not working correctly:
using terms from application "Mail"
on perform mail action with messages theMessages for rule theRule
repeat with eachMessage in theMessages
tell application "Mail" to set t to paragraphs of the content of eachMessage
repeat with i in t
if i starts with "http://www.website.com/specific/link" then tell application "Safari" to open location i
end repeat
end repeat
end perform mail action with messages
end using terms from
Any suggestion on what I can do to make this process work?
Upvotes: 0
Views: 493
Reputation: 1878
You should get AppleScript paragraphs instead of Mail.app paragraphs:
using terms from application "Mail"
on perform mail action with messages theMessages for rule theRule
repeat with eachMessage in theMessages
tell application "Mail" to set t to (content of eachMessage) as string -- EDITED
set t to paragraphs of t -- ADDED
repeat with i in t
if i starts with "https://stackoverflow.com/questions/67909907/open-links-sent-in-email-using-applescript" then openLocation(i)
end repeat
end repeat
end perform mail action with messages
end using terms from
on openLocation(theURL)
tell application "Safari" to open location theURL
end openLocation
Upvotes: 0