Jump to content
Macro Express Forums

Challenge: a hotkey macro to create new folders while in "Save as" dialog boxes


Recommended Posts

This isn’t a hard challenge. But I’m finding the macro I built to be indispensable. I use it almost every day, and sometimes many times in an hour.

 

 

When saving a document, email message, image, web page, etc., "Save as" dialog boxes in most applications includes basic file management functions. For example, you can navigate from folder to folder, choose different file types, delete files, rename files, change the view, sort and filter, etc.

 

These tasks can be done by pointing and clicking, and with a bit of effort, by pressing keys on the keyboard.

 

I often need to create new folders after I have opened the "Save as" dialog box. Modern "Save as" windows sport a conspicuous "New folder" button. But I don’t know any "Save as" windows that include a built-in hotkey for creating new folders.

 

 

The challenge: make a Macro Express script, triggered by the hotkey of your choice, that creates a new folder within the current folder in the "Save as" dialog boxes of the applications you use most. My script works in Word, Outlook, PowerPoint, Excel, and Firefox.

 

 

A few rules:

 

 

1.    Your macro should work (1) for any display setting, and (2) in windows of any size: So if you maximize the "Save As" dialog box, or change a display setting in the Control Panel (e.g., screen resolution, dots per square inch, etc.) your script should still function. So you probably cannot meet this requirements if your macro clicks on the x-y coordinate of the "New Folder" button! That would be too easy!

 

 

2.    Design your macro to be easily extendable. For example, it you start using a new application, make it easy to revise the macro so the hotkey also works in its "Save As" dialog box.

 

 

As I mentioned, this challenge isn't that hard. It would have been more difficult had you tried it in the past. Modern "Save As" dialog boxes are nearly identical. When I first scripted this macro, years ago, each program’s "Save As" dialog had a slightly different layout and organization, so each program needed to be handled separately. And sometimes, this is still true.

Link to comment
Share on other sites

I never muck about in the GUI of the Save-As dialog. I use MEP's commands. In this case I'd take the path from the nav bar at top using control commands and then create the folder in MEP. Then, alternatively, navigate to that folder.

Link to comment
Share on other sites

I use a variant of this technique for saving e-mails to existing folders, though not for creating new folders since I do that only rarely.  Some email sources have a consistent window title, others can be reliably identified by phrases in their content or simply by the "to" or "from" fields.  To dispose of an email that's on the screen, I start a macro that analyzes these items, sends it to the appropriate folder, or deletes it if it doesn't qualify for saving.  I admit the macro clicks on screen icons to do its work, so when GMail changes its layout the macro has to be adjusted.  But that doesn't happen often. 

Link to comment
Share on other sites

Quote

I admit the macro clicks on screen icons to do its work, so when GMail changes its layout the macro has to be adjusted.  But that doesn't happen often.

 

If it's any consolation, in Office applications, Microsoft changes the key sequences for performing everyday tasks, as well. That means that MEP scripts must be revised.

 

For example, in Word 2003, to format text in three columns was this reasonably logical and understandable sequence of four key presses:

 

Alt   [ activate menu bar ]

o      [ Format - Microsoft chose "o" for "Format" because "f" was "File" ]

c      [ Columns ]

3      [ 3 columns ]

 

In Word 2019, it's this hard-to-learn and -understand sequence:

 

Alt   [ activate ribbon ]

p      [ Layout - but why "p?" ]

j       [ Columns - maybe "j" stand for "Jolumns!" ]

Down

Down

Enter      [ navigate down two lines to "Three" and activate]

 

Link to comment
Share on other sites

11 hours ago, acantor said:

If it's any consolation, in Office applications, Microsoft changes the key sequences for performing everyday tasks, as well. That means that MEP scripts must be revised.

Some consolation!  I suspect Microsoft rewards their employee-of-the-month by saying, "Here's a popular product, go ahead and have some fun by making whatever random design change strikes your fancy." 

 

I just spent 30 minutes trying to turn off an "error" option in Excel.  I could turn it off for a particular spreadsheet but it would turn itself back on almost immediately.  Finally read an online hint to click File and Options, and that way I could turn it off universally and it would stay off.  The oddest thing is, this is a monthly spreadsheet and the "errors" just started showing up this month, after seven years of data.  Must have been from one of those Office updates that sneaked in without telling me now that I'm on Windows 10.  Things like this no longer surprise me, just reinforce my love/hate relationship with Microsoft.

Link to comment
Share on other sites

19 hours ago, Cory said:

I never muck about in the GUI of the Save-As dialog. I use MEP's commands. In this case I'd take the path from the nav bar at top using control commands and then create the folder in MEP. Then, alternatively, navigate to that folder.

 

Hi Cory,

 

There is an interesting approach. I find that in Windows 10 and/or Office 2019, Macro Express sometimes struggles trying to capture control information.

 

But I just tried in two "Save As" dialog boxes, and I see using controls to capture the Address line just might work.

 

Not sure whether there will be complications that will force me to resort to mucking about with the user interface!

Link to comment
Share on other sites

Hi Cory,

 

It turns out there are unanticipated side-effects to the method you proposed. For reasons I don't understand (at least not yet) sometimes the Address field contains the full path (e.g., c:\Users\Alan\Documents\), and sometimes it contains just a word: "Documents". I assume it's a shortcut of some kind.  If the control grabs "Documents" instead of the full path, the "Create New Folder" instruction fails.

 

There is a workaround, but it's not quite as clean as one might hope.

 

I think the source of the problem relates to how Microsoft now handles the Address field in the "Save As" and "Open" dialog boxes. The field behaves in two different ways: like a normal field; and like a field that has several independent segments. I haven't worked out what causes the field to behave one way or the other.

 

rberq, perhaps we should approach Microsoft's "Employee of the Month" for some assistance with this. I'm thinking of the developer who had the brainwave for this Janus-like field!

 

When I post my solution to this challenge, I will include two. One will be my original solution, and the other will be based on Cory's idea... unless, of course, he posts a working version of his macro first!

Link to comment
Share on other sites

I THOUGHT this was a straightforward challenge. But the longer I tested my solution (which I recently updated for compatibility with Windows 10 and Office 2019), the more often it failed.

 

I also tried Cory's proposed solution. The macro worked perfectly. But as I continued to use it, it began failing -- but for different reasons than mine.

 

Finally, I think I'm zeroing in on a script that reliably creates a new folder in the Save As dialog box -- but only under certain conditions. I'll post it in a day or two.

Link to comment
Share on other sites

The solution that I settled on is nothing like I expected.

 

 

On my Windows 7 machine, my script outputted sequences of four or five keystrokes to activate “New Folder” buttons in “Save As” windows. It worked perfectly for years.

 

 

When I upgraded to Windows 10, I noticed that the sequence of keystrokes was different. After revising my old macro, I realized that the key sequence sometimes failed. The reason: several fields in “Save As” windows are flaky. At least one of them has a tendency to steal focus.

 

 

I tried Cory’s approach of using controls to capture the path from the address line, and then to use a Macro Express instruction to create the new folder. But I couldn’t get these scripts to work for a variety of reasons, including, most annoyingly, that the capture control instruction yielded different results when run at different times, all of them “correct.” For example, sometimes the word “Address” would appear in front of the path name; sometimes a word associated with the path would appear instead of the path. Ultimately, I abandoned trying to capturing path information from the Address bar.

 

 

At one point, I tried to take advantage of Macro Express’s error handling to deal with the complexities. But then I discovered a possible error handling bug with the create new folder instruction. I’ve already reported it to Insight Software.

 

 

The script that is working best uses an entirely different approach. I found a “neutral” spot on the “Save As” screen that when clicked resets the tab order back to its default, i.e., when the window is first opened. Then the script sends a sequence of three keystrokes to navigate to and activate the “New Folder” button.

 

 

Feel free to suggest simpler (or better or more reliable) ways to do this. But I’m sticking to one rule: Clicking on the XY coordinates of the “New Folder” button is not allowed, as the coordinates might vary if a user modifies display settings in the Control Panel.

 

 

(Full disclosure: My macro does a mouse click to reset the tab order, and this spot is somewhat arbitrary. I’ve tested the approach, and it does work for a wide variety of display settings, although not all!)

 

 

 

Link to comment
Share on other sites

Quote

// Hotkey to create a new folder in "Save As" dialog boxes
 
// In Windows 10, creating a new folder in "Save As" windows using only controls may not be possible.
// That's because some controls in the "Save As" window behave badly. For example...
// ... the "Search" box sometimes steals focus.
// Other controls also behave erratically, including "Save as Type."
 
// Another approach is to navigate via keyboard from controls that have built-in hotkeys...
// ... (e.g., A&ddress, File &Name)... to the "New Folder" button. But this doesn't work...
// ... because the script cannot reliably tab past controls that behave badly.
 
// Of course, one could click on the "New Folder" button!
// Yet the script does not do this...
// ... because I want the script to work if a user changes display settings such as screen resolution and DPI.
 
// Instead, this script clicks on a "neutral" spot that resets the screen's tab order.
// Then, the script outputs three keystrokes to navigate to and activate the "New Folder" button.
// The neutral spot is around the vertical midpoint of the window, just to the right of the left border.
// The x-coordinate was discovered through trial-and-error, and may need to be adjusted!
 
// Limitation: This script fails when the "New Folder" button is hidden...
// ... which happens when the window height is especially narrow.
 
// Get the application name, in case the steps are different in different programs.
Variable Set String %TopmostProgram% to topmost program name
 
// Use the "default" folder creation method, but be ready for non-standard apps!
Switch( %TopmostProgram% )
 
Case: WINWORD.EXE
Case: OUTLOOK.EXE
Case: POWERPNT.EXE
Case: EXCEL.EXE
Case: FIREFOX.EXE
  Variable Set Integer %FudgeFactor% to 20
  Variable Set Integer %WinHeight%: Set to the Current Window's Height
  Variable Modify Integer: %WinHeightHalf% = %WinHeight% / 2
  Mouse Move: %FudgeFactor%, %WinHeightHalf% Relative to Current Window
  Mouse Left Click
  Text Type (Simulate Keystrokes): <SHIFT><TAB>
  Text Type (Simulate Keystrokes): <ARROW RIGHT>
  Text Type (Simulate Keystrokes): <SPACE>
End Case
 
Default Case
  Variable Set From Misc:  "Name of Current Macro" into %MacroName%
  Text Box Display: Script does not yet handle Save As for "%TopmostProgram%"
  Macro Stop
End Case
End Switch

 

<COMMENT Value="Hotkey to create a new folder in \"Save As\" dialog boxes"/>
<COMMENT/>
<COMMENT Value="In Windows 10, creating a new folder in \"Save As\" windows using only controls may not be possible."/>
<COMMENT Value="That's because some controls in the \"Save As\" window behave badly. For example..."/>
<COMMENT Value="... the \"Search\" box sometimes steals focus."/>
<COMMENT Value="Other controls also behave erratically, including \"Save as Type.\""/>
<COMMENT/>
<COMMENT Value="Another approach is to navigate via keyboard from controls that have built-in hotkeys..."/>
<COMMENT Value="... (e.g., A&ddress, File &Name)... to the \"New Folder\" button. But this doesn't work..."/>
<COMMENT Value="... because the script cannot reliably tab past controls that behave badly."/>
<COMMENT/>
<COMMENT Value="Of course, one could click on the \"New Folder\" button!"/>
<COMMENT Value="Yet the script does not do this..."/>
<COMMENT Value="... because I want the script to work if a user changes display settings such as screen resolution and DPI."/>
<COMMENT/>
<COMMENT Value="Instead, this script clicks on a \"neutral\" spot that resets the screen's tab order."/>
<COMMENT Value="Then, the script outputs three keystrokes to navigate to and activate the \"New Folder\" button."/>
<COMMENT Value="The neutral spot is around the vertical midpoint of the window, just to the right of the left border."/>
<COMMENT Value="The x-coordinate was discovered through trial-and-error, and may need to be adjusted!"/>
<COMMENT/>
<COMMENT Value="Limitation: This script fails when the \"New Folder\" button is hidden..."/>
<COMMENT Value="... which happens when the window height is especially narrow."/>
<COMMENT/>
<COMMENT Value="Get the application name, in case the steps are different in different programs."/>
<VARIABLE SET STRING Option="\x04" Destination="%TopmostProgram%"/>
<COMMENT/>
<COMMENT Value="Use the \"default\" folder creation method, but be ready for non-standard apps!"/>
<SWITCH Variable="%TopmostProgram%"/>
<COMMENT/>
<CASE Value="WINWORD.EXE"/>
<CASE Value="OUTLOOK.EXE"/>
<CASE Value="POWERPNT.EXE"/>
<CASE Value="EXCEL.EXE"/>
<CASE Value="FIREFOX.EXE"/>
<VARIABLE SET INTEGER Option="\x00" Destination="%FudgeFactor%" Value="20"/>
<VARIABLE SET INTEGER Option="\x0B" Destination="%WinHeight%"/>
<VARIABLE MODIFY INTEGER Option="\x03" Destination="%WinHeightHalf%" Value1="%WinHeight%" Value2="2"/>
<MOUSE MOVE Option="\x02" X="%FudgeFactor%" Y="%WinHeightHalf%" _PROMPT="0x000A"/>
<MOUSE LEFT CLICK/>
<TEXT TYPE Action="0" Text="<SHIFT><TAB>"/>
<TEXT TYPE Action="0" Text="<ARROW RIGHT>"/>
<TEXT TYPE Action="0" Text="<SPACE>"/>
<END CASE/>
<COMMENT/>
<DEFAULT CASE/>
<VARIABLE SET FROM MISC Destination="%MacroName%" Value="Name of Current Macro"/>
<TEXT BOX DISPLAY Title="Script does not yet handle Save As for \"%TopmostProgram%\"" Content="{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang4105{\\fonttbl{\\f0\\fnil\\fcharset0 Tahoma;}{\\f1\\fnil Tahoma;}}\r\n\\viewkind4\\uc1\\pard\\f0\\fs24 Macro:    \"\\f1 %\\f0 MacroName\\f1 %\\f0 \"\\f1 \r\n\\par \\f0 Variable: \\f1 TopmostProg\\f0 ra\\f1 m \\f0 = \"\\f1 %TopmostProgram%\\f0 \"\\f1 \r\n\\par }\r\n" Left="821" Top="Center" Width="955" Height="200" Monitor="0" OnTop="FALSE" Keep_Focus="TRUE" Mode="\x00" Delay="0"/>
<MACRO STOP/>
<END CASE/>
<END SWITCH/>

 

 

Link to comment
Share on other sites

  • 2 weeks later...
On 9/30/2020 at 7:56 PM, rberq said:

Some email sources have a consistent window title, others can be reliably identified by phrases in their content or simply by the "to" or "from" fields.  To dispose of an email that's on the screen, I start a macro that analyzes these items, sends it to the appropriate folder, or deletes it if it doesn't qualify for saving...

 

This could be the basis for a good challenge:  write a macro to analyze an email message and decide what to do with it based on its sender, subject, or whatever. Seems like it would be a very useful tool.

Link to comment
Share on other sites

 Hi Alan,

 

“analyze an email message and decide what to do with it based on its sender, subject, or whatever.”

 

It would need to be a very clever macro, incorporating the latest in AI and a LOT of input from you!

 

If you do write such a macro, I wonder how confident you will be in handing over control of your Inbox?

 

Terry
 

 

Link to comment
Share on other sites

I don't think I would allow a macro to act on the entire content of my inbox. A little too risky! But I can imagine a script that acts on individual email messages.

 

I'm thinking of a hotkey macro that parses a message for one or two pieces of information, e.g., the subject line and the sender's email address. For me, one or both fields would provide enough information to decide which folder to store that message in.

 

I keep most messages in my Inbox, and only move small numbers of incoming messages into a handful of folders. So my approach might not be practical for someone who moves almost every message into one of a large number of folders.

 

I'm currently testing several scripts that extract the sender's email address from Outlook messages without sending mouse clicks to the window. Instead, the scripts use window controls to programmatically capture information from the target fields, or quasi-programmatically navigate from field to field via keystrokes. So far, none of these scripts are 100% reliable due to variability in email messages. For example, in Outlook 2019, messages that contains hypertext links in the body behave differently than messages that have attachments, consist of plain text, etc.

 

If I find a solution, I'll start another thread and post it as another challenge. We already know rberq has figured out a way to do this with Gmail!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...