Processing Ajax...

Title

Message

Confirm

Confirm

Confirm

Confirm

Are you sure you want to delete this item?

Confirm

Are you sure you want to delete this item?

Confirm

Are you sure?

User Image
UWK-87
166 discussion posts
Hi Keith,

Can you help with a creation of a small macro. This Macro should copy the selected text, do a check if it's a URL and finally open it in a browser.

Sorry for the trouble.

Thanks.
Sep 13, 2017 (modified Sep 14, 2017)  • #1
User Image
UWK-87
166 discussion posts
I was wondering if these two additional scenario can also be catered in the same macro, though it will make it a little complicated.

Scenario 1: There is a whole paragraph in which there is a URL for example like below:
Quote:
This is a sample paragraph to explain the scenario for the macro. The HTTP page/URL for this awesome software is https://www.clipboardfusion.com/ or http://www.clipboardfusion.com/discussions.

In this scenario, we run the macro by selecting the whole paragraph (auto-copy). The macro extracts the URL i.e. the string beginning with http:// or https:// till a "space" " " occurs as a URL cannot contain space and open it in browser. If there is more than one, then open all in the browser provided they are not the same links.

Scenario 2: You copy a text that has hyperlink and when you run the macro it open the links from the hyperlink.

I am sorry if it's too much to ask :)
Sep 13, 2017 (modified Sep 13, 2017)  • #2
Keith Lammers (BFS)'s profile on WallpaperFusion.com
That would be beyond my meager skills, but I will send this over to Thomas and see if he can do up a macro for you :)
Sep 14, 2017  • #3
User Image
UWK-87
166 discussion posts
Hey Keith,

You mentioning your skill are meager when compared to the requirements of the macro must mean I have asked for too much. I apologize for the trouble. Can you also convey my thanks in advance to Thomas, for the trouble :)
Sep 14, 2017  • #4
Keith Lammers (BFS)'s profile on WallpaperFusion.com
No worries. I could probably write something up given enough time, but Thomas can likely bang it out in 10 minutes :)
Sep 14, 2017  • #5
User Image
Dmiitry
71 discussion posts
This is a macro that would open URLs extracted from a text fragment:

// extract URLs from text fragment and open them in default browser
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Diagnostics;

public static class ClipboardFusionHelper
{
public static string ProcessText(string text)
{
string urlRegEx = @"(http|ftp|https)://([\w_-]+(?:(?:\.[\w_-]+)+))([\w.,@?^=%&:/~+#-]*[\w@?^=%&/~+#-])?";

foreach(Match currentMatch in Regex.Matches(text, urlRegEx))
{
Process.Start(currentMatch.Value);
}

return null;
}
}

It works for your test case, but might break for more complex scenarios. Also find attached .cfmacro file which you can import
• Attachment: Extract and Open URLs.cfmacro [7,202 bytes]
Sep 15, 2017 (modified Sep 15, 2017)  • #6
User Image
UWK-87
166 discussion posts
Quote:

It works for your test case, but might break for more complex scenarios. Also find attached .cfmacro file which you can import


Hi Dmiitry,

The macro worked like a charm for scenario 1 (minus the disregard the same URL if it occurs twice or more).

Thanks alot! :)
Sep 15, 2017  • #7
Keith Lammers (BFS)'s profile on WallpaperFusion.com
Thanks Dmiitry!
Sep 15, 2017  • #8
User Image
UWK-87
166 discussion posts
Hey Keith,

Any luck with getting Thomas to look into the configuration for second scenario? And optimizing the current macro/script (which Dmiitry graciously provided) for the identical URL check in scenario 1? :)

Thanks
Sep 15, 2017  • #9
User Image
Dmiitry
71 discussion posts
Hi UWK-87

Find attached updated macro, it now removes duplicate URLs. For me it works even in cases like "https://www.clipboardfusion.com/ and in www.clipboardfusion.com" and opens mentioned URL only once. Please test.

Can you clarify Scenario 2? Do you want macro to navigate to a URL from the text and then to navigate to other URLs mentioned on that page? Include test case similar to Scenario 1.

-----

Hi Keith, thanks for a powerful ClipboardFusion, pleasure to work with it!
• Attachment: Extract and Open URLs.cfmacro [6,618 bytes]
Sep 18, 2017  • #10
User Image
UWK-87
166 discussion posts
Quote:
Hi UWK-87

Find attached updated macro, it now removes duplicate URLs. For me it works even in cases like "https://www.clipboardfusion.com/ and in www.clipboardfusion.com" and opens mentioned URL only once. Please test.


Thanks alot Dmiitry. Your coding skills are absolutely fantastic! It works beautifully :)

Let me explain the second scenario.

Quote:

This is a sample paragraph to explain the second scenario for the macro. The HTTP page/URL instead of being directly listed will be listed as hyperlink text for example you can visit >>>>>ClipboardFusion<<<<< to get this awesome software or you can visit to see the discussions >>>>>CF-Discussions<<<<<


So in this scenario instead of having links that are right there in the open they are embedded as clickable hyperlinks. So just like scenario 1 it opens all these hyperlinks.

I am not even sure if the CF API even allows this but text scrubbing gave the idea that it might be possible as it removes these tags.

Thanks again Dmiitry for taking the time to help out :)
Sep 18, 2017 (modified Sep 18, 2017)  • #11
User Image
Dmiitry
71 discussion posts
Hi UWK-87

Find attached new macro that includes functionality from the first one + ability to open links in HTML fragment. If I copy both of your test cases in one fragment to clipboard and run the macro, it opens new browser window with 3 tabs in it (can you figure out why 3? :-) )

There is one important limitation: hidden links would be opened only if they are currently selected in the system clipboard. If you attempt to run the macro against entry in your History older than the first one, only surface links would be opened (similar to the first macro). It is because ClipboardFusion keeps in History only surface text, not full HTML content that is available from the clipboard.

Usage:
1) Navigate to any web page and select content with hyperlinks, e.g. newspaper article with links to other articles;
2) Ctrl + C to move to clipboard. ClipboardFusion History would display only surface text for this entry, but don't worry - your hidden links are still preserved in the system clipboard;
3) Run my macro, either against that first entry in History or using hot key.
Expected result: new browser window opens with multiple tags, one for each URL mentioned in your selected fragment either explicitly or as HTML links.

Let me know if you find any bugs
• Attachment: Navigate to URLs.cfmacro [11,602 bytes]
Sep 19, 2017  • #12
User Image
UWK-87
166 discussion posts
Hi Dmiitry,

The new macro worked beautifully even when handling the hyperlinks.

As you mentioned it does indeed open three new URL tabs, after couple of testing by changing and adding new links. I noticed that the hypertext links (for e.g >>>>>CF-Discussions<<<<<) do not do a check against the simple URL and vice versa i.e. SIMPLE URL check for duplication in their own ranks and the HYPERLINK check for duplication in their own ranks. Is that the case you have noticed as well?

Other than this, this macro is an amazing piece of work Dmiitry.

Thank you so much.
Sep 19, 2017 (modified Sep 19, 2017)  • #13
User Image
UWK-87
166 discussion posts
Just went through the code and that is indeed the case, as you are initially storing distinct links in the simple text first to the listindex and then running the same function on href-links to the same indexlist and feeding it to the for loop at the end :D

I wonder if we can add another snippet that runs the distint() function on the final list as that will sort out the issue
Sep 19, 2017 (modified Sep 19, 2017)  • #14
User Image
Dmiitry
71 discussion posts
The macro does have a final Distinct() call before loading into browser, see line 25. It opens 3 URLs in your test case because it makes distinction between 'http' and 'https', see attached screenshot for details
• Attachment: ClipboardFusion_NavigateURLs_TestCase.png [76,407 bytes]
ClipboardFusion_NavigateURLs_TestCase.png
ClipboardFusion_NavigateURLs_TestCase.png
Sep 20, 2017  • #15
User Image
UWK-87
166 discussion posts
You are right, I seem to have missed you doing a merger to a new list at line 25. The second reason I arrived this opinion is because of this test case:

Quote:

Find attached updated macro, it now removes duplicate URLs. For me it works even in cases like "https://www.clipboardfusion.com/ and in www.clipboardfusion.com" and opens mentioned URL only once. Please test. http://www.clipboardfusion.com

This is a sample paragraph to explain the second scenario for the macro. The HTTP page/URL instead of being directly listed will be listed as hyperlink text for example you can visit >>>>>ClipboardFusion<<<<< to get this awesome software or you can visit to see the discussions >>>>>CF-Discussions<<<<<


Kindly note in this test case the URLs are as below:

1. https://www.clipboardfusion.com/
2. www.clipboardfusion.com
3. http://www.clipboardfusion.com
4. >>>>>ClipboardFusion<<<<< = http://www.clipboardfusion.com
5. >>>>>CF-Discussions<<<<< = HTTP://www.clipboardfusion.com/discussions

In the above links the distinct links are as below:

1. https://www.clipboardfusion.com/
2. http://www.clipboardfusion.com [OR www.clipboardfusion.com OR >>>>>ClipboardFusion<<<<< ]
3. >>>>>CF-Discussions<<<<< = HTTP://www.clipboardfusion.com/discussions

However if you copy the above quoted text and run it through the macro, it will open 4 links that made me believe that both scenarios are catered separately (even though that is not the case hmmm).

Thanks Dmiitry
Sep 20, 2017 (modified Sep 20, 2017)  • #16
User Image
Dmiitry
71 discussion posts
Good analysis and test case! Yes, it opens 4 instead of 3 URLs.

The problem was a trailing "/" in one entry, which made code to believe they are not the same. I fixed that and have also made some other changes, find attached new version.

Until new feature to store HTML instead of plain text (that you have requested in other post) is available, there is no point to execute this macro against historical entries - use first version of the macro to open only plain text URLs if you need. This macro has full strength only if you execute it against content in your system clipboard.

With this consideration in mind, I have slightly redesigned the macro. Now you don't need to copy to clipboard selected content, the macro will do it for you. This way you save yourself trouble of remembering to copy before running the macro.

Intended usage:
1) Select some content in web browser;
Do not press Ctrl+C, nor copy to clipboard any other way. Macro will do it for you automatically.

2) Press designated hot key for the macro.
Result: new browser window opens with multiple tabs for each hyperlink in your selected fragment. See attached diagram for illustration

This is a convenient and streamlined way to open many hyperlinks, instead of clicking on each one individually.

If you want to explicitly copy content to clipboard before running the macro (as it was before), remove 2 lines in the code which I have marked.

Please test new macro. Your idea for this kind of macro was very good! Now saves me a lot of clicks :-)
• Attachment: ClipboardFusion_NavigateURLs_Usage.png [58,219 bytes]
ClipboardFusion_NavigateURLs_Usage.png
ClipboardFusion_NavigateURLs_Usage.png
• Attachment: Navigate to URLs.cfmacro [13,898 bytes]
Sep 21, 2017 (modified Sep 21, 2017)  • #17
User Image
UWK-87
166 discussion posts
Works beautifully now!

Regarding the auto-copy, that's what I added to your previous version as soon as I got the macro hehehe ( First line - text = BFS.Clipboard.CopyText(); )

Saves me hell lot of clicks as well, especially when I am reading and browsing articles that link to other articles. Now I can copy the data and open links at the same time and even if you don't wanna copy the multiple clicks required was a hassle :D

Post this in the Premade macros (https://www.clipboardfusion.com/Macros/), it says at the bottom you need to email it in.

Thanks again buddy!
Sep 21, 2017 (modified Sep 21, 2017)  • #18
User Image
Dmiitry
71 discussion posts
Good that it works for you!

I have slightly updated the macro: now it adds new 'Hyperlinks' section at the bottom of the text fragment stored in the History and in system clipboard after you ran the macro. This section contains all links found in the HTML fragment, both simple and hyperlinks. This way it is possible to run the other macro, the one I've originally developed for Scenario 1, against entry in the History menu and it would open these URLs in browser. See attached diagram for illustration.

Find attached new version of the 'Navigate to URLs' macro and streamlined version of the macro for Scenario 1. Hope they are able to work in tandem seamlessly.
• Attachment: ClipboardFusion_NavigateURLs_StoreHyperlinks.png [92,891 bytes]
ClipboardFusion_NavigateURLs_StoreHyperlinks.png
ClipboardFusion_NavigateURLs_StoreHyperlinks.png
• Attachment: Extract and Open URLs.cfmacro [8,258 bytes]
• Attachment: Navigate to URLs.cfmacro [16,602 bytes]
Sep 22, 2017  • #19
User Image
UWK-87
166 discussion posts
Hi Dmiitry,

This version seems to have have a small bug. For example if you have the setting "Show Clipboard Changes done by ClipboardFusion" under the Clipboard History tab un-ticked, this will cause the macro to delete it's own entry from CF manager.

Overall, this is an awesome idea to bypass the HTML preservation limitation of old CF data :D

Thanks :)
• Attachment: Clipboard Picture (2017.09.23 15.08.36).png [39,204 bytes]
Clipboard Picture (2017.09.23 15.08.36).png
Clipboard Picture (2017.09.23 15.08.36).png
Sep 23, 2017  • #20
User Image
Dmiitry
71 discussion posts
Yes, if you clear "Show Clipboard Changes done by ClipboardFusion" checkbox it won't show an entry in the History. The macro makes changes to the original content of the system clipboard by adding "Hyperlink:" section. Obviously, if you don't allow entries generated by ClipboardFusion to be shown, you will see nothing.

I delete original entry in the History and insert new one with "Hyperlinks:". Otherwise, you will end up with 2 entries, original from system clipboard and generated by CF. To my taste, it looks like litter. If you do want this kind of behavior, remove call to RemoveHistoryItem() on line 37

Hope you'll find this macro useful until ClipboardFusion is able to store original HTML content
Sep 25, 2017  • #21
User Image
UWK-87
166 discussion posts
Hey Dimiitry,

Yes, I already removed that line to bypass that issue. Thank you so much for taking the time to create this macro.

I have another idea for a macro, I wonder if you would be up for it? And if the API will allow for it.

The idea goes like this:

When you are browsing a webpage and need to take screenshot of the whole page instead of just the visible page i.e. scroll till the bottom, take screenshot along the way and then stitch them up in one complete picture. This can be valid for any scrolling application, be it Adobe etc etc.

Thanks!
Sep 26, 2017  • #22
User Image
Dmiitry
71 discussion posts
For auto-scrolling screen capture, use excellent Snagit - download from https://www.techsmith.com/screen-capture.html. It has multiple modes to do so depending on your needs, including Panoramic Scrolling Capture. I use it daily
Sep 27, 2017  • #23
Subscribe to this discussion topic using RSS
Was this helpful?  Login to Vote(1)  Login to Vote(-)