1

This script is supposed to open a series of web pages in a new browser window, and then open TextEdit with predetermined text and links.
Safari does what it is supposed to.
Text edit opens and pastes the text I want, but the links are not clickable.
I know I could just right click and choose Substitutions> Add Links> myself, but I am trying to automate the entire process.
I appreciate your time and efforts on my behalf! Thank you!

OpenWebPages()  
OpenTextEditPage()  

to OpenTextEditPage()  
-- Create a variable for text  
set docText to ""  
tell application "TextEdit"  
    activate  
    make new document  
    -- Define the text to be pasted into TextEdit   
    set docText to docText & "Some text to show in TextEdit." & linefeed & "    
    My favorite site about coding is http://stackoverflow.com/   
    My favorite site for paper modeling is http://www.ss42.com/toys.html   
    My favorite site for inventing is  http://www.instructables.com/howto/bubble+machine/   
    " & linefeed & "Click the links above to improve your mind!" as string  
    -- Past the above text and links into TextEdit  
    set the text of the front document to docText & "" as string  
    tell application "System Events"  
        tell process "TextEdit"  
            -- highlight all text  
            keystroke "a" using command down  

            -- Think of a clever way to right click and choose Substitutions> Add Links>   
            -- Or think of another clever way to turn all URLs into links please.  

        end tell  
    end tell  
end tell  
end OpenTextEditPage  

to OpenWebPages()  
-- Start new Safari window  
tell application "Safari"  
    --      activate Safari and open the StackOverflow AppleScript page  
    make new document with properties {URL:"http://stackoverflow.com/search?q=applescript"}  
    -- Yoda is watching you  
    open location "http://www.ss42.com/pt/Yoda/YodaGallery/yoda-gallery.html"  
    -- Indoor boomerang   
    open location "http://www.ss42.com/pt/paperang/paperang.html"  
    --  Are you a Human ?  
    open location "http://stackoverflow.com/nocaptcha?s=f5c92674-b080-4cea-9ff2-4fdf1d6d19de"  
end tell  
end OpenWebPages  
Frankenpaper
  • 53
  • 1
  • 5

1 Answers1

0

According to this question I built this little handler. It takes a path to your rtf-file like makeURLsHyper((path to desktop folder as string) & "TestDoc.rtf") and worked quite fine in my little tests. But it doesn't care about text formatting at this point.

on makeURLsHyper(pathOfRtfFile)
    -- converting the given path to a posix path (quoted for later use)
    set myRtfPosixPath to quoted form of (POSIX path of pathOfRtfFile)
    -- RTF Hyperlink start
    set rtfLinkStart to "{\\\\field{\\\\*\\\\fldinst HYPERLINK \""
    -- RTF Hyperlink middle
    set rtfMiddlePart to "\"}{\\\\fldrslt "
    -- RTF Hyperlink end
    set rtfLinkEnd to "}}"
    -- use sed to convert http-strings to rtf hyperlinks
    set newFileContent to (do shell script "sed -i bak -e 's#\\(http[^[:space:]]*\\)#" & rtfLinkStart & "\\1" & rtfMiddlePart & "\\1" & rtfLinkEnd & "#g'  " & myRtfPosixPath)
end makeURLsHyper

Have a nice day, Michael / Hamburg

Community
  • 1
  • 1
ShooTerKo
  • 2,242
  • 1
  • 13
  • 18
  • I have tried, but I just don't understand this answer. Perhaps I should have specified that I am looking for an AppleScript solution. I know even less about shell scripts so I don't know how to treat this to work in my script. Thanks for your help though! – Frankenpaper Jul 19 '15 at 07:22
  • I do want to mention that the TextEdit is never a saved file. It is created for this single use, and will be closed by the user once it has served it's purpose. – Frankenpaper Jul 19 '15 at 08:25