Jump to content
Macro Express Forums

terrypin

Members
  • Posts

    2,232
  • Joined

  • Last visited

  • Days Won

    23

Posts posted by terrypin

  1. 5 hours ago, mikecox said:

     

    Quote

    This shortcut pops up a row of unfamiliar icons,

     

    Hover over each and read what they do: Rectangular, Window, Freeform, and Full Screen. Just the same as using the Mode button in the old Snipping Tool.

     

    Quote

    The first thing I need is for the app to open the way it does when I click the icon

     

    I assume you are saying you definitely want to remain with the old, unsupported tool called Snipping Tool, so that you can immediately save to a chosen location as before? If so then the following macro works for me:

     

    // Open the Start/Search box
    Text Type (Simulate Keystrokes): <WIND>
    Delay: 0.1 seconds
    Text Type (Simulate Keystrokes): <WINU>
    Delay: 0.1 seconds
    Text Type (Simulate Keystrokes): Snipping Tool
    Delay: 0.5 seconds
    Text Type (Simulate Keystrokes): <ENTER> // This opens the highlighted entry from your Search, which should by default be 'Snipping Tool'.
    Wait for Window Title: Snipping Tool
    Text Type (Simulate Keystrokes): <ALT>n // Select 'New'
    Delay: 0.1 seconds
    // Now proceed manually as advised, i.e. select and then save your target.
    
    <COMMENT Value="Open the Start/Search box"/>
    <TEXT TYPE Action="0" Text="<WIND>"/>
    <DELAY Flags="\x01" Time="0.1"/>
    <TEXT TYPE Action="0" Text="<WINU>"/>
    <DELAY Flags="\x01" Time="0.1"/>
    <TEXT TYPE Action="0" Text="Snipping Tool"/>
    <DELAY Flags="\x01" Time="0.5"/>
    <TEXT TYPE Action="0" Text="<ENTER>" _COMMENT="This opens the highlighted entry from your Search, which should by default be 'Snipping Tool'."/>
    <WAIT FOR WINDOW TITLE Title="Snipping Tool" Partial="FALSE" Wildcards="FALSE" Indefinite="TRUE" Hours="0" Minutes="0" Seconds="0"/>
    <TEXT TYPE Action="0" Text="<ALT>n" _COMMENT="Select 'New'"/>
    <DELAY Flags="\x01" Time="0.1"/>
    <COMMENT Value="Now proceed manually as advised, i.e. select and then save your target."/>
     

     

     

    Snipping Tool - New File.mex

    • Thanks 1
  2. "...I'm really just a layperson here."

    Not in my opinion!

     

    I'm not a programmer and my experience with Python has been confined to using PaintShop Pro scripts: 95% content from those who DO know the language, plus adaptation/experiment myself. And even that was a few years ago.

     

    I reckon that Samrae's suggestions are likely to give you what you need. The registry would be my preference, as I gather there are several relevant Python commands, e.g:
    https://docs.python.org/3/library/winreg.html#access-rights

     

    Alternatively, going the API route, VBA should be the closest match. You might even be able to use one of the conversion tools to change your VBA code to Python.

     

    But FWIW the following is an example of the much cruder method I used to exchange variable data between PSP Python and ME Pro. In summary, the MEP macro first runs a submacro ('Script Open') and then runs a specific Python script. Very ponderous. But it worked for me (daunted by Python's learning curve) to automate a score or so of PSP tasks that I couldn't perform reliably and quickly with ME Pro alone.

    ====================

    MACRO: Script run - Elev-GPSU-Miles

    Delay: 0.1 seconds
    Macro Run: Script Open
    Delay: 0.5 seconds
    Text Type (Use Clipboard and Paste Text): Elev-GPSU-Miles.PspScript // Elevation Edit
    Delay: 0.5 seconds
    Variable Modify String %tMiles%: Trim
    Variable Modify String: Save %tMiles% to the clipboard
    Delay: 0.5 seconds
    Text Type (Simulate Keystrokes): <ENTER> // Run that script.
    Delay: 0.1 seconds

    --------------------

    MACRO: Script Open

    // Open Scripts folder
    // Runs from PSP 8, which must be active.
    Macro Playback Speed: 0.50 times faster than normal
    Keystroke Speed: 20 milliseconds
    Text Type (Simulate Keystrokes): <ALT>f
    Delay: 0.1 seconds
    Text Type (Simulate Keystrokes): r
    Delay: 0.1 seconds
    Text Type (Simulate Keystrokes): <ENTER>
    Delay: 0.4 seconds
    Text Type (Simulate Keystrokes): <ALT>n // Cursor to empty name box
    Delay: 0.2 seconds
    Text Type (Use Clipboard and Paste Text): C:\Users\terry\My PSP8 Files\Scripts-Trusted\ // Cursor to empty name box
    Delay: 0.5 seconds
    Text Type (Simulate Keystrokes): <ENTER>
    Delay: 0.2 seconds

    --------------------

    PAINTSHOP PRO PYTHON SCRIPT: Elev-GPSU-Miles.PspScript

    from JascApp import *
    from Tkinter import Tk

    def ScriptProperties():
        return {
            'Author': u'Terry Pinnell',
            'Copyright': u'',
            'Description': u'',
            'Host': u'Paint Shop Pro',
            'Host Version': u'8.10'
            }

    def Do(Environment):
        # EnableOptimizedScriptUndo
        App.Do( Environment, 'EnableOptimizedScriptUndo', {
               
                })
        # ASSUMES THAT VALUE OF MILES (%tMiles%) IS ON CLIPBOARD
        # ******************************************************
        
        # Text
        App.Do( Environment, 'Text', {
                'CreateAs': App.Constants.CreateAs.Vector,
                'Segments': [{
                    'Bold': App.Constants.Boolean.true,
                    'Fill': {
                        'Color': (0,0,0),
                        'Pattern': None,
                        'Gradient': None,
                        'Texture': None,
                        'Identity': u'Material'
                        },
                    'Font': u'Arial',
                    'LineStyle': {
                        'Name': u'',
                        'FirstCap': (u'Butt',0.25,0.25),
                        'LastCap': (u'Butt',0.25,0.25),
                        'FirstSegCap': (u'',0.25),
                        'LastSegCap': (u'',0.25),
                        'UseSegmentCaps': App.Constants.Boolean.false,
                        'Segments': []
                        },
                    'LineWidth': 0,
                    'PointSize': 36,
                    'Start': (1460.5,314.5),
                    'Stroke': {
                        'Color': None,
                        'Pattern': None,
                        'Gradient': None,
                        'Texture': None,
                        'Identity': u'Material'
                        }
                    },{
                    'Antialias': App.Constants.Boolean.true,
                    'WarpText': App.Constants.Boolean.true,
                    'AutoKern': App.Constants.Boolean.true,
                    'Bold': App.Constants.Boolean.true,
                    'Kerning': 0,
                    'Leading': 0,
                    'Fill': {
                        'Color': (0,0,0),
                        'Pattern': None,
                        'Gradient': None,
                        'Texture': None,
                        'Identity': u'Material'
                        },
                    'Font': u'Arial',
                    'Italic': App.Constants.Boolean.false,
                    'Join': App.Constants.JointStyle.Miter,
                    'LineStyle': {
                        'Name': u'',
                        'FirstCap': (u'Butt',0.25,0.25),
                        'LastCap': (u'Butt',0.25,0.25),
                        'FirstSegCap': (u'',0.25),
                        'LastSegCap': (u'',0.25),
                        'UseSegmentCaps': App.Constants.Boolean.false,
                        'Segments': []
                        },
                    'LineWidth': 0,
                    'MiterLimit': 10,
                    'PointSize': 36,     
                    'SetText': App.Constants.Justify.Left,
                    'Start': (1460.5,314.5),
                    'Strikethru': App.Constants.Boolean.false,
                    'Stroke': {
                        'Color': (255,255,255),
                        'Pattern': None,
                        'Gradient': None,
                        'Texture': None,
                        'Identity': u'Material'
                        },
                    'Underline': App.Constants.Boolean.false
                    },{
                    'Characters': getText()
                    }],
                'SavedText': None,
                'FinalApply': App.Constants.Boolean.false,
                'Matrix': None,
                'GeneralSettings': {
                    'ExecutionMode': App.Constants.ExecutionMode.Default,
                    'AutoActionMode': App.Constants.AutoActionMode.Match
                    }
                })
        # SelectNone
        App.Do( Environment, 'SelectNone', {
                'GeneralSettings': {
                    'ExecutionMode': App.Constants.ExecutionMode.Default,
                    'AutoActionMode': App.Constants.AutoActionMode.Match
                    }
                })

    def getText():
        r = Tk()
        text = r.selection_get(selection='CLIPBOARD')
        r.withdraw()
        r.update()
        r.destroy()
        return text

     

    --------------------

    Good luck!

     

    Terry, UK

     

     

  3. @mikecox

    The easiest way to open Snip & Sketch is to use the keyboard shortcut combination Shift+Win+S. You can then use its four capture tools by clicking the appropriate icon.

     

    If you still need help to write a macro then please specify exactly what it should do once Snip & Sketch is open.

     

    P.S: After posting a query, in my experience you cannot rely on receiving a 'notification'. Just check back regularly.

    • Like 1
  4. Is there a particular reason you want to use Snipping Tool rather than its replacement a year or so ago by Snip & Sketch?

     

    I tried both and found the update superior in all respects. Here's a comparison:

    https://www.guidingtech.com/snipping-tool-vs-snip-sketch-difference/

     

    Did you also see the 18th April post about this topic?

     

    If you do explicitly want the outdated tool, this is the target:

     

    C:\Windows\System32\SnippingTool.exe

     

    Terry, UK

     

     

     

     

     

  5. Did you try my suggestion about your Delay commands?


    Try adding a Wait for Window Title afer activating Act!

     

    Try adding a 0.1 s delay after typing <Alt + I>.

     

    Try using Waits for Text Playback after the TextType.

     

    Try using mouse move and click commands.

     

    Is it only <Alt + I> that fails?

     

    Best to confine all subsequent example macros to this single issue, as you’ve just done in your lat post.

  6. Here's one way to do it:

     

    EDITED

    // Two cols of info, User ID and Name, separated by a tab, are stored in G:\Traffic\IBS\Other\id.txt.
    This macro prompts for a user id. If it is found it displays the name. Otherwise it displays an appropriate message and ends the macro.
    // I've defined Use ID as a string variable. That not only allows future flexibility but simplifies the script. And unless you intend to do arithmetic on the User ID it's unnecessary to set it as an integer.
    // Note: I prefix my string variables with 't' (for 'text'), and integer variables with 'n' (for 'number').
     
    Variable Set String %tUser%: Prompt
    ASCII File Begin Process: "G:\Traffic\IBS\Other\id.txt" (Tab Delimited Text (.txt))
      If Variable %tUser% Equals "%tLine[1]%" // This is a match.
        Text Box Display: User %tUser% is:
        Variable Set String %tResult% to "Matched"
        Macro Stop
      End If
    ASCII File End Process
    If Variable %tResult% Does not Equal "Matched" // There was no match
      Text Box Display: User %tUser% is:
    End If

     

    CODE:

     

    <COMMENT Value="Two cols of info, User ID and Name, separated by a tab, are stored in G:\\Traffic\\IBS\\Other\\id.txt.\r\nThis macro prompts for a user id. If it is found it displays the name. Otherwise it displays an appropriate message and ends the macro."/>
    <COMMENT Value="I've defined Use ID as a string variable. That not only allows future flexibility but simplifies the script. And unless you intend to do arithmetic on the User ID it's unnecessary to set it as an integer."/>
    <COMMENT Value="Note: I prefix my string variables with 't' (for 'text'), and integer variables with 'n' (for 'number')."/>
    <COMMENT/>
    <VARIABLE SET STRING Option="\x01" Destination="%tUser%" Prompt="Enter the target User ID." Mask="FALSE" OnTop="TRUE" Left="Center" Top="Center" Monitor="0"/>
    <ASCII FILE BEGIN PROCESS Filename="G:\\Traffic\\IBS\\Other\\id.txt" Format="Tab" Start_Record="1" Process_All="TRUE" Records="1" Variable="%tLine%" Start_Index="1" Parse_Blank_Lines="FALSE" Clear_Array="TRUE"/>
    <IF VARIABLE Variable="%tUser%" Condition="\x00" Value="%tLine[1]%" IgnoreCase="FALSE" _COMMENT="This is a match."/>
    <TEXT BOX DISPLAY Title="User %tUser% is:" Content="{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang2057{\\fonttbl{\\f0\\fnil\\fcharset0 Tahoma;}{\\f1\\fnil Tahoma;}}\r\n\\viewkind4\\uc1\\pard\\qc\\b\\f0\\fs20 %tLine[2]%\\f1 \r\n\\par }\r\n" Left="689" Top="334" Width="378" Height="138" Monitor="0" OnTop="TRUE" Keep_Focus="TRUE" Mode="\x00" Delay="0"/>
    <VARIABLE SET STRING Option="\x00" Destination="%tResult%" Value="Matched" NoEmbeddedVars="FALSE"/>
    <MACRO STOP/>
    <END IF/>
    <ASCII FILE END PROCESS/>
    <IF VARIABLE Variable="%tResult%" Condition="\x01" Value="Matched" IgnoreCase="FALSE" _COMMENT="There was no match"/>
    <TEXT BOX DISPLAY Title="User %tUser% is:" Content="{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang2057{\\fonttbl{\\f0\\fnil\\fcharset0 Tahoma;}{\\f1\\fnil Tahoma;}}\r\n\\viewkind4\\uc1\\pard\\qc\\b\\f0\\fs20 Not on record.\\f1 \r\n\\par }\r\n" Left="689" Top="334" Width="378" Height="138" Monitor="0" OnTop="TRUE" Keep_Focus="TRUE" Mode="\x00" Delay="0"/>
    <END IF/>

     

     

    Terry, UK

     

     

    MacromanDemo-Edited.mex

  7. Thanks for the further details. Yes, I would use ASCll File Begin Process. Personally I would separate the two cols with a tab, to minimise any ambiguity with the Name (which contains a comma).

     

    Seeing the variable 'V1' I assume you are using ME Pro? If so I suggest you name your variables meaningfully, especially when arrays are involved.

     

    Note that your macro will fail because N2 is an integer but V1 is a string. You'd have to convert N2 first, using Variable Modify Intger > Convert to Text String.

     

    I'll suggest a macro shortly.

     

    Terry, East Grinstead, UK

     

  8. 3 hours ago, Cory said:

    I don't understand why you don't use the MEP file manipulation commands. It's much easier to conditionally handle exceptions with them. Much faster and more reliable. Since this is the way I handle files, I am not going to be of much help, but I urge you to try and use them instead. 

    When I things that could have a popup error I use the existence of the controls. Let's say that's a "Do you want to continue?" button. I define the control and use "if control exists". And I'd never type in file names, I'd use the controls to enter those values. And here again, checking of the controls exist are useful. What I'm saying is not only can you use the controls to do things, you can also use their existence and value to control the flow of your macro. 

     

    "I don't understand why you don't use the MEP file manipulation commands."

    I'm not sure I've understood. Apart from If File Exists, which I mentioned, what other  'file manipulation commands' do you suggest to handle file saving when OS messages are displayed as in my example? Or maybe you're referring to the simple way I've handled  the file processing in that? IOW, are you instead recommending a Repeat with Folder to build a variable holding all files? If so, I agree, and if this was a larger project with many more files involved that's probably how I'd do it. But this was just a simplified example to focus on the subject issue.

     

    "I'd never type in file names..."

    Do you mean you don't use string variables to enter data as in my example? What advantage would using Controls offer? Wouldn't that involve more steps, and the same variable?

     

    "When I things that could have a popup error I use the existence of the controls."

    How would you do that for my example? What would be the target of the Get Control command, for instance?

     

     

     

     

  9. When running macros that save files they frequently fail because messages from the OS do not automatically pause the macro to allow user interaction before proceeding. A typical example:

     

      // Now re-open the file in F2 mode and enter the new name
      Text Type (Simulate Keystrokes): <F2>
      Delay: 0.1 seconds
      Text Type (Simulate Keystrokes): %tFilename%
      Delay: 0.1 seconds
      Text Type (Simulate Keystrokes): <ENTER>
      Delay: 0.1 seconds
      Text Type (Simulate Keystrokes): <ARROW DOWN>
      Delay: 0.1 seconds
    End Repeat

    After the ENTER command I might briefly see a message like "A file of this name already exists..." and be asked to choose a Yes or No option (e.g. to save with a suffixed name), but the macro continues regardless. Sometimes the fix is easy; for example when the message is asking whether to overwrite the previous file I can often safely insert a Text Type Y command. Or I can use If Window, specify 'Replace File', and add an appropriate  action, such as a simple Pause. Or sometimes an If File Exists command is possible. But sometimes it's not so easy.

     

    What techniques do others use please?

     

    Terry, UK

  10. On 2/29/2020 at 5:44 PM, acantor said:

    Here is the MEP script I use to change the background colour of selected lines to yellow

     

    Hi Alan,

     

    This command caused failure for me:

    Wait for Window Title: Color

    That has me fascinated, especially as I see that you personally spell 'colour' the same as I do!

     

    Is your version of MEP indeed AmericaniZed in that way?

     

    Using 6.1.3.1 here, and your macro works fine when I use the correct spelling 🙂

     

    Terry

     

     

×
×
  • Create New...