How to format clipboard text to paste as hyperlink? - hyperlink

How can I generate a rich text hyperlink on my clipboard using something like autohotkey?
Basically I want to create a paste as hyperlink shortcut. Currently I highlight some text and press ctrl+alt+k which sends ctrl+k (create hyperlink hotkey in many programs), then sends ctrl+v to paste in my location, and finally enter to confirm.
This works well enough but I was hoping to make it general enough to work anywhere that supports rich text, even if it doesn't have a ctrl+k shortcut available.
Thanks,
David

Simple code:
In this example I use Ctrl+Shift+v to paste a hyperlink in your format:
^+v::
Send, ^k %Clipboard% {Enter}
Return
or...
^+v::
StringReplace, ClipBoard, ClipBoard, http:// ; strip http://
StringReplace, ClipBoard, ClipBoard, https:// ; strip http://
Send, %ClipBoard%
Return

Related

How do I use AppleScript on Automator to concatenate copied text within page to current URL

I've been having some trouble with this. I'm new to Automator and I'm looking to make a Quick Service to: have a script that copies the selected text (on Safari), adds it to the end of the same URL the text is on, and then saves that new link to the clipboard with some additional characters. Example of what I'm looking for:
URL: https://en.wikipedia.org/wiki/Penny_Mordaunt
Selected Text: She used the word
Desired Result in Clipboard: https://en.wikipedia.org/wiki/Penny_Mordaunt#:~:text=She%20used%20the%20word
I dont have too much so far but what I do have is:
tell application "Safari"
set theURL to URL of current tab of window 1
set theName to theURL & "selected text"
end tell
The first line does get the URL of the tab. The part I'm having trouble in is getting the selected text and appending with the correct special characters in the right places.
This would be adding #:~:text= before and %20 before every consective word selected.
Any help would be great!
I ended up getting it! This worked for me:
property theURL : ""
tell application "Safari"
set theURL to URL of current tab of window 1
set theText to (do JavaScript "getSelection().toString()" in document 1)
set newURL to theURL & "#:~:text=" & theText
end tell

Autohotkey -- click link, alter link, launch link

I'm trying to create an .ahk script that will make life easier with Notion. My colleagues toss Notion links everywhere, and I'd like a script to force these links to open in the app and not in the browser.
I know that I need to somehow automatically alter the link from 'https' to 'notion', but my script doesn't work like I expected.
Can anyone help me avoid this extra step? Thanks in advance. Code below:
!LButton::
Send, ^c
Clipboard := StrReplace(Clipboard, "https", "notion", 1)
SendInput, %Clipboard%
return
Edit: I can add that the second part of the code works as I want if the link is already in the clipboard. I seem not to be able to correctly automate copying the link to the clipboard when I run this hot key script.
I don't know what Notion is, so I'll have a bit of trouble giving the best answer, but this advice will hopefully fix your problem:
Firstly, it's good to use ClipWait(docs) when sending ctrl+c and then working with the copied stuff.
Then you seem to be missing one arguments from the StrReplace()(docs) function. You're specifying 1 to the OutputVarCount parameter.
Then you should specify the text send mode for your send command to avoid problem with ^+!#{} characters.
Or a bit better, you could set the text to the clipboard and send ctrl+v.
Or even better, launch the app and pass the link in as an argument, assuming it supports that.
Code:
!LButton::
Clipboard := ""
SendInput, ^c
ClipWait
Clipboard := StrReplace(Clipboard, "https", "notion", , 1)
SendInput, % "{Text}" Clipboard ;send as input
SendInput, ^v ;or paste
Run, % "notion.exe """ Clipboard """" ;or pass in as commandline argument
return
EDIT:
Another approach
!LButton::
Clipboard := ""
Click, Right ;open right click menu
Sleep, 50 ;wait a bit so the menu opens
SendInput, e ;shortcut for "copy to clipboard"
ClipWait
Clipboard := StrReplace(Clipboard, "https", "notion", , 1)
MsgBox, % Clipboard
return

Why FormFeed Character in a txt File is rendered as Page Break by MS Word / WordPad but not by NotePad?

I have a .txt file and it has FormFeed character between para1 and para 2.
Para2 needs to be shown in next page on printing hence FormFeed is placed here.
sample txt file layout:
para1
formFeedCharacter
para2
expected layout on printing:
para1 is shown in 1st page and para 2 is shown in 2nd page as formFeed acts as page break.
When opened and printed with MS Word/WordPad:
expected layout is coming in 2 pages as expected.
When opened and printed with NotePad:
1)FormFeed is not acting as Page Break and all content is printed in 1 page only
2)FormFeed is displayed as unreadable Symbol
Final Printed layout when used Notepad:
para1
Unreadable symbol (caused by FormFeed)
para2
Why Notepad is unable to render FormFeed as pageBreak ?
Is it because NotePad is a text Editor While WordPad/MS Word is Word processor ?
Is there any way how we can make this work with NotePad ?
Notepad:
1)It is a text Editor program and cannot interpret Form Feed character as Page Break.
2) Hence there is no way we can make formFeed work as page break and print it by using NotePad.
WordPad/MS Word:
1) Both are Word Processor softwares and can interpret FormFeed correctly as Page Break.
Hence Unreadable symbol is not shown on opening txt file with them
2) We can also see the page Break by Print Preview feature in wordpad/NotePad.
This hyperLink provides additional information on this topic:
Additional Info
Also below hyperlink shows similar topic post asking for a universal solution for pageBreak Feature using txt file.
page Break in txt file Universal Solution

How to make TextEdit links clickable

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
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

Send an e-mail with rtf text in delphi

I would like to perform the following task: converting a TRichEdit content (an rtf text) into a not-plain-text e-mail message body.
MAPI doesn't support rtf, but is there a way to do it maybe with Indy?
The problem is that rtf is rtf and emails are plain text or HTML.
Can someone suggest a trick? Is it possible to convert rtf to text using TWebBrowser?
Basically the scenario is:
1) User writes email in a delphi form,
2) The email is then sent with MAPI to the default mail client (so a new email window is generated, and the message body is the same I had in delphi form)
3) User sends the email from mail client
Anyway MAPI accepts only plain text.
UPDATE:
Trying with Indy I wrote this but still it doesn't work, as I send a mail it to my gmail account I recieve a message with empty body and NONAME fake attachment.
uses IdMessageBuilder;
procedure SendMail;
var
MBuilder: TIdMessageBuilderRtf;
MyMemoryStream: TMemoryStream;
begin
try
MBuilder := TIdMessageBuilderRtf.Create;
MyMemoryStream := TMemoryStream.Create;
MBuilder.RtfType := idMsgBldrRtfRichtext;
// RichEdit1 has PlainText set to False
// at design time I pasted some formatted text onto it
RichEdit1.Lines.SaveToStream(MyMemoryStream);
MBuilder.Rtf.LoadFromStream(MyMemoryStream);
MBuilder.FillMessage(IdMessage1);
IdSMTP1.Connect;
IdSMTP1.Send(IdMessage1);
IdSMTP1.Disconnect;
finally
MyMemoryStream.Free;
MBuilder.Free;
end;
end;
Indy supports sending RTF emails. Send an email the same way you would send an HTML email, just use the "text/rtf", "text/enriched", or "text/richtext" Context-Type, and send the raw RTF codes that are generated by TRichEdit when its PlainText property is set to false. Also, if you are using Indy 10, look at its TIdMessageBuilderRtf class to set up the TIdMessage structure correctly.
Apparently (googled this myself, as I mail some from Delphi, but not in this case), the PR_RTF_COMPRESSED option of (extended) MAPI may help you here. Also look at this.
Is it possible to convert rtf to text using TWebBrowser?
You can convert RTF to Text using TRichEdit - but obviously this loses all formatting:
Using TRichEdit at runtime without defining a parent
2: You can find a number of RTF to HTML converters online - some free, some not. Like these:
http://wiki.delphi-jedi.org/wiki/JVCL_Help:TJvRichEditToHtml
https://www.habarisoft.com/scroogexhtml_delphi.html
http://www.easybyte.com/products/rtf2html.html
http://www.sautinsoft.com/products/rtf-to-html/index.php
3: You can rename the noname attachment as NONAME.MHT and it should then be openable with internet explorer.
However you might want to consider using an HTML edit control, rather than a TRichEdit. Then you have no conversion to worry about. Something like this question:-
WYSIWYG HTML Editor Component for Delphi

Resources