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
luc comeau
1 discussion post
Anyone has a macro to grab a clipped URL and process it through a Bit.ly account (i.e. my Bit.ly account as opposed to the public one)

Thanks!
May 6, 2019  • #1
PabloMartinez's profile on WallpaperFusion.com
Like this. Get your token from here: https://bitly.is/accesstoken

Code

using System;
using System.IO;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

public static class ClipboardFusionHelper
{
    // Paste your access token here. You can get it here https://bitly.is/accesstoken
    private static readonly string bitlyToken = "YOUR TOKEN";
    
    public static string ProcessText(string text)
    {
        if (CheckURLValid(text))
        {
            var shortenUrl = Shorten(text).Result;
            return shortenUrl;
        }
        else
            BFS.Dialog.ShowMessageInfo("It's not a url, or url not valid");
        
        return null;
    }
    
    public static bool CheckURLValid(string url)
    {
        Uri uriResult;
        return Uri.TryCreate(url, UriKind.Absolute, out uriResult) && (uriResult.Scheme == Uri.UriSchemeHttp || uriResult.Scheme == Uri.UriSchemeHttps);
    }
    
    public static async Task<string> Shorten(string url)
    {
        var post = "{\"long_url\": \"" + url + "\"}";
        
        var request = (HttpWebRequest) WebRequest.Create("https://api-ssl.bitly.com/v4/shorten");

        try
        {
            request.Method = "POST";
            request.ContentType = "application/json";
            request.Headers.Add("Cache-Control", "no-cache");
            request.Host = "api-ssl.bitly.com";
            request.Headers.Add("Authorization", "Bearer " + bitlyToken);
            
            using (var requestStream = request.GetRequestStream())
            {
                var postBuffer = Encoding.UTF8.GetBytes(post);
                requestStream.Write(postBuffer, 0, postBuffer.Length);
            }
            
            var response = await request.GetResponseAsync();
            
            using (var responseStream = response.GetResponseStream())
            {
                var responseReader = new StreamReader(responseStream, Encoding.UTF8);
                var json = responseReader.ReadToEnd();
                var shortenUrl = Regex.Match(json, @"""link"": ?""(?<link>[^,;]+)""").Groups["link"].Value;
                
                return shortenUrl;
            }
        }
        
        catch (WebException ex)
        {
            throw;
        }
    }
}

Of course, it was possible to make a lot simpler, but then it would be needed external references(Newtonsoft Json, RestSharp). So I decided to stop at this option.
May 11, 2019  • #2
User Image
Luc Comeau77712
1 discussion post
thanks Pablo!!!

Again very much appreciated.
May 11, 2019 (modified May 11, 2019)  • #3
Keith Lammers (BFS)'s profile on WallpaperFusion.com
Thanks for the macro, Pablo! We've added it to the repository as well.
May 13, 2019  • #4
User Image
Edgar RAMEL
6 discussion posts
Hello,

I start with clipboard fusion, it seems interesting and we find some concepts of Fusion Display.

The notion of triggers is a bit confused for me.
I thought I could use triggers with keyboard shortcuts and for some applications, but that's not how it works at a priori.
You have to go through the macros, and there the problems for the non-programmer I'm starting.

Fortunately, we can benefit from the good work of knowledgeable users.
I found the macro of @Pablomartinez to generate the shortcuts bit.ly, it's great!

I would have liked to modify it slightly, but I can not find the correct syntax or procedure (if you have a BFS and C # command collection for Clipboard Fusion, I am a taker. And also if it is better C # or Visual. Basic?).

I would like the macro Pablo Martinez runs directly on the text (URL link) selected and put it in the paper press to speed up the process.
Is it possible simply by changing certain lines?

I saw that the macro was going to look somewhere on this side: "processtext (string text)", but I do not know how to fill in this variable from the selected text (with that, including: "bfs.clipboard.copytext () ").

Or nickening several macro in one?
1) Select the text and copy it;
2) Start the Marco de Pablo Martinez.

Here, I hope I have not been too confused in my explanation.

Looking forward to your return, I remain at your disposal for any further information.

Thank you in advance.

Edgar
Nov 21, 2020  • #5
Owen Muhlethaler (BFS)'s profile on WallpaperFusion.com
Hi Edgar,

We've added a new macro to the repository you can download named "Shorten URL with Bit.ly (with auto copy/paste)"

You will have to create your own API key, and set it on line 11. You can create the key here: https://bitly.is/accesstoken

Thanks!
Nov 23, 2020  • #6
User Image
Edgar RAMEL
6 discussion posts
Hello Owen,

Thank you and bravo for your work, modification and your responsiveness!
It works perfectly.

I just changed your code so that the macro does not stick directly after copying it because it crushed the original link.

Some complementary questions around Clipboard Fusion ...

As I said, I start and I have never programmed into C # or visual (and to tell the truth I do not know if I have the sacred fire for that).
Is there a Bible or a collection of macro functions of clipboard fusion?
Would you have reading tips or exercises to start?

And finally, a practical case, can we go or chain a sequence of simple macros in another macro?

Still a big thank you.

Good continuation.
Cordially.
Edgar
Nov 24, 2020  • #7
Owen Muhlethaler (BFS)'s profile on WallpaperFusion.com
Hi Edgar,

We have a list of our scripting functions found here: https://www.clipboardfusion.com/Macros/Help/

If you are looking to learn how to code in C#, I'm sure there are a ton of great tutorials on youtube or google that would interest you.

You also can run macros inside of each other, the help section for that is found here: https://www.clipboardfusion.com/Macros/Help/#bfs_clipboardfusion_runmacro

Thanks!
Nov 26, 2020  • #8
User Image
Edgar RAMEL
6 discussion posts
Hello Owen,
Thank you for this additional information that will allow me to put a little more hands under the hood!
Good weekend.
Cordially.
Edgar
Nov 27, 2020  • #9
Subscribe to this discussion topic using RSS
Was this helpful?  Login to Vote(1)  Login to Vote(-)