AGBear Posted January 24, 2022 Share Posted January 24, 2022 (edited) Hi everyone, I have to work with Office 365 Advanced Threat Protection 'safelinks' all day long: these are URLs checked for phishing and other cybersecurity issues, then converted into a unique format. https://aus01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.google.com%2F&data=04|lots of parameters and personally identifiable information that isn't important for this purpose| There are many tools available to decode these URLs - like https://o365atp.com/ . Rather than pasting URLs into that website every time, I want to use Alfred to process the Office URLs and return the 'real' URL to the clipboard. Digging into the source of that website, the underlying Javascript is pretty straightforward. However my knowledge of scripting is limited to basic bash (and some Perl ten years ago) so I don't know how to convert that link variable into a query passed from Alfred. Can anyone help with this? Thanks in advance! function decode_url() { setTimeout("generate_decode_url()", 20); } function generate_decode_url() { var link = document.getElementById("safelink").value; var url_parts = link.split("?")[1]; var params = url_parts.split("&"); var target_url = "Error: couldn't find target URL."; for(n=0;n<params.length;n++) { namval = params[n].split("="); if(namval[0]=="url") target_url = namval[1]; } decode_url = decodeURIComponent(target_url); document.getElementById("target_url").value = decode_url; } function clear() { location.reload(); } Edited January 24, 2022 by AGBear clarified URL format Link to comment
vitor Posted January 25, 2022 Share Posted January 25, 2022 If I’m understanding correctly, what you want is a Run Script Action with language /usr/bin/osascript (JavaScript) and code: function run(argv) { return decodeURIComponent(argv[0].split("?url=")[1].split('&')[0]) } That will take whatever argument you passed early (e.g. from a Keyword Input), transform it, and output it to the next Alfred object. AGBear 1 Link to comment
AGBear Posted January 25, 2022 Author Share Posted January 25, 2022 Wow, that works perfectly! Thanks so much for your help! Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now