useless macro?



  • I would like the macro to memorize an action and not just copy paste.
    I need a function that is on the list of inserted photos,
    takes the title tag and alt from the photo name.

    I would like it to memorize the action and to repeat it on the selected lines
    if I have a list of 10 different photos, the title and alt tags will be different

    how can I do? I have thousands of photos upload with the plugin “ImgTag”
    but there is no title field and the alt field is blank

    please, someone help me quickly!
    thank you soo much!



  • I am no coder, can barely program, but I am sure what you need is outside the realm of a text editor. I am sure there are photo tag editors available just like there are editors for mp3 tags.



  • If OP (original poster) explain what she need more clearly and detail in better correct English and how the condition and environment she is on now that is supporting, it’d be more likely many more people would give useful help. Thanks in advance



  • @Angelica-Bartoloni isn’t overly clear (but maybe English isn’t her native language), but I read the description of the ImgTag plugin in the Plugin Manager: it appears to allow you to use a File|Open-style dialog to select images from your drive, and then insert the appropriate <IMG> tag in the HTML document you are editing in Notepad++.

    Given that description, then it could probably be automated inside NPP… but probably not with the macro-recording tool.

    The ways that I can think of:

    1. Use the ImgTag plugin as normal. Then use a regex-based search-and-replace to update the title and alt fields. If the OP gave us the example output HTML from ImgTag, the regex experts could easily customize to fit the OP needs.

    2. Use PythonScript to automate the ImgTag plugin, and edit the output as it’s going. (I don’t think this really has any benefit over #1)

    3. Use PythonScript to completely replace the ImgTag functionality: have the .py call a File|Open-style dialog itself, and then generate the HTML <img> tags, with all the fields that are desired. (For simplest case, this might work; but if OP is relying on getting/setting the width and height tags via ImgTag as well, then it would probably require accessing other libraries through the .py, at which point, #1 is probably simpler again.)

    I think probably #1 is the easiest.

    Assuming ImgTag would return the following if you selected a.png, b.png, and c.png: (and assuming that “alt field is blank” means there is the alt attribute but no string inserted, and that “no title field” means that there isn’t a title attribute at all):

    <img src="./a.png" width=640 height=480 alt="">
    <img src="./b.png" width=1280 height=720 alt="">
    <img src="./c.png" width=1920 height=1080 alt="">
    

    And assuming @Angelica-Bartoloni wants

    <img src="./a.png" width=640 height=480 alt="./a.png" title="./a.png">
    <img src="./b.png" width=1280 height=720 alt="./b.png" title="./b.png">
    <img src="./c.png" width=1920 height=1080 alt="./c.png" title="./c.png">
    

    Then I would use something like

    • Find What = (?-s)src="([^"]*)"([^>]*)alt="">
    • Replace With = src="$1"$2alt="$1" title="$1">

    If the order of attributes is different, or ImgTag uses different quote characters (single quotes, for example), or if it uses xhtml-style <img ... />, then the regular expressions could be changed to accommodate.

    Angelica, please give us actual example output from ImgTag, and the exact desired final result: we can tweak the regex as necessary. Try to think of edge cases: do any of your filenames have quotes or apostrophes embedded, such as Mr. D'Angelo's "favorite" picture.png, or any other special characters that you think might influence things? Does ImgTag always output attributes in the same order? Does it include the alt="", or alt='', or no alt at all; similar for title? What other helpful information can you give us? (The more details you give of “what you have” vs “what you want”, the easier it is for us to help you find a solution.)

    <edit>: also, we need to know if you have other <IMG> tags already in the document. If so, then before doing the search-and-replace, you’ll have to select just the ImgTag-based <IMG> tags, and use the ☑ In Selection option, to avoid messing up other images.</edit>


Log in to reply