URL Decoding Macro

This forum allows you to share scripts with other Zeus users. Please do not post bug reports, feature requests or questions to this forum, but rather use it exclusively for posting scripts or for the discussion of scripts that have been posted.
Post Reply
jussij
Site Admin
Posts: 2650
Joined: Fri Aug 13, 2004 5:10 pm

URL Decoding Macro

Post by jussij »

Consider the following mapping of characters to their encoded equivalent value:

Code: Select all

   !   #   $   &   '   (   )   *   +   ,   /   :   ;   =   ?   @   [   ]
   %21 %23 %24 %26 %27 %28 %29 %2A %2B %2C %2F %3A %3B %3D %3F %40 %5B %5D
As an example this macro will take this string:

Code: Select all

   %21 %23 %24 %26 %27 %28 %29 %2A %2B %2C %2F %3A %3B %3D %3F %40 %5B %5D
and produce this decoded result:

Code: Select all

   !   #   $   &   '   (   )   *   +   ,   /   :   ;   =   ?   @   [   ]
Here is the macro:

Code: Select all

#
#        Name: Unquote Marked Region of Text
#
#      Author: Jussi Jumppanen
#
#    Language: Python
#
# Description: This macro will unquote a marked region of text and add
# the results to the clipboard.
#
# Consider the following mapping for characters to their encoded equivalent
# value:
#
#    !   #   $   &   '   (   )   *   +   ,   /   :   ;   =   ?   @   [   ]
#    %21 %23 %24 %26 %27 %28 %29 %2A %2B %2C %2F %3A %3B %3D %3F %40 %5B %5D
#
# As an example this macro will take this string:
#
#    %21 %23 %24 %26 %27 %28 %29 %2A %2B %2C %2F %3A %3B %3D %3F %40 %5B %5D
#
# and produce this unquoted result:
#
#    !   #   $   &   '   (   )   *   +   ,   /   :   ;   =   ?   @   [   ]
#
import zeus
import urllib.parse

def unquoteMarkedText():

    if zeus.is_marked():
        text = zeus.macro_tag("$wex").decode('utf8')
        zeus.set_clipboard_text(urllib.parse.unquote(text))
        zeus.message("The unquoted text has been added to the clipboard.")
    else:
        zeus.message("No text is currently marked.")
        zeus.beep()

unquoteMarkedText()


Last bumped by jussij on Thu Mar 24, 2022 5:40 am.
Post Reply