XMetaL Tips and Tricks

XMetaL Community Forum XMetaL Tips and Tricks Script Example: Expanding an abbreviation by pressing F3 ("AutoText")

  • Su-Laine Yeo

    Script Example: Expanding an abbreviation by pressing F3 ("AutoText")

    Participants 1
    Replies 0
    Last Activity 12 years, 1 month ago

    Description:
    This macro file lets you set up a list of abbreviations that you can expand by pressing a keyboard shortcut. For example, with this macro, if you type “egbdf” in an XMetaL document and then press F3, the text “ebgdf” will be replaced by “Every Good Boy Deserves Fudge.” To configure this macro so that you can expand the abbreviations that are meaningful to you, you will need to edit a script file, so in order to use this feature you should be comfortable working with script.

    Installation:
    1) Download and unzip the attached .zip file.
    2) Open your XMetaL Startup folder. For default installations of XMetaL 6.0, this is C:Program FilesXMetaL 6.0AuthorStartUp.
    3) Move the .mcr file from the .zip package to your XMetaL Startup folder.
    4) Restart XMetaL.

    Usage:
    Open a document in XMetaL, type egbdf. Press the F3 key.

    Configuration:
    By default, the macro file is configured with three abbreviations:
    – egbdf expands to Every Good Boy Deserves Fudge
    – aceg expands to All Cows Eat Grass
    – roygbiv expands to Red Orange Yellow Green Blue Indigo Violet

    (By the way, the first two abbreviations above are [url=http://cnx.org/content/m10941/latest/]mnemonics used in music[/url].)

    To add your own abbreviation, open the AutoText.mcr file in a text editor and add to or change the following lines:

    [code] if (keystr==”egbdf”) {
    return “Every Good Boy Deserves Fudge”;
    } else if (keystr == “aceg”) {
    return “All Cows Eat Grass”;
    } else if (keystr == “roygbiv”) {
    return “Red Orange Yellow Green Blue Indigo Violet”;
    }
    [/code]

    For example, if you want the abbreviation “usd” to be expanded to “U.S. dollar” when you press F3, make the code look like this:

    [code] if (keystr==”usd”) {
    return “U.S. dollar”;
    } else if (keystr == “aceg”) {
    return “All Cows Eat Grass”;
    } else if (keystr == “roygbiv”) {
    return “Red Orange Yellow Green Blue Indigo Violet”;
    }
    [/code]

    You must save the AutoText.mcr file and restart XMetaL for your changes to take effect.

    Products:
    XMetaL Author (Enterprise and Essential) and XMAX
    Tested with XMetaL Author Enterprise 6.0

    Make sure you properly test these in your environment together with all of your other scripts.

    About Demo Code:
    Before using this script please read the notes and comments in the MCR file, which also includes some legal stuff. Basically, this code is provided as a demo and should be treated as if it were completely untested. I have tested it as best I can, but it has not gone through our regular rigorous test process.

    Please also do not use this script without the permission of the people that maintain your XMetaL installation (if that isn't you). Although the possibility is low given the way I have coded this it could conflict with special customizations or scripts, 3rd party tools or plug-ins, a specific work-flow they have set up and wish you to follow, or any number of other things I cannot even guess at. I would recommend telling them about your wish to have something like this and let them integrate it and test it for you.

    Reply

  • You must be logged in to reply to this topic.

Lost Your Password?

Products
Downloads
Support