How to Select a Pulldown for File Type within a Save As Menu WITHOUT mouse movements

Hi Keyboard Macro Forum,

Forgive the Noob question but I've looked high and low for a way to:

Switch a pulldown menu item within a 'save as' window... without using mouse movements.

Trouble is that I can't tab/arrow to access the menu with the keyboard.

Is there a Keyboard Maestro function to select the menu and scroll through it?

I've attached some screen shots to give you the idea about what I'm trying to do...
THANK YOU!!
Best wishes,
Michael

1 )
2)
3)

I don't think so, but I'm not sure. If there is one of the KM gurus will jump in here and let us know.

Meanwhile, if your app supports AppleScript you can probably do the "Save As" via AppleScript, with a popup to allow you to select the file type.
You can do a search on "YourAppName AppleScript" to find out.

Or better, open the "Script Editor" app, then goto File > Open Dictionary, and see if your app is there.

Just lets know your app name, and what you find out.

Popup menus are tricky to control. To select a popup menu, you need to simulate a click on the menu, and then use typeahead to select the desired item, ie actions:

Click on popup menu
Insert Text by Typing “Menu Name%Return%”

The tricky part is clicking on the menu. First, make sure you have paused long enough to allow the window to come to the front, and then you can need to click on the popup. You can click in one of these ways:

  • if the window has keyboard focus, then you can click relative to the window, and if the popup menu is in a fixed location, then that may be a reliable solution.
  • click relative to the found image. If the popup menu always defaults to the same thing, then you can use the popup menu as the image. Otherwise, you need to click relative to something nearby that is consistent (like some label text).

To click relative to an image, you use the Mouse Click action, configure it to be relative to a found image, and take a screenshot of the desired area of the screen using Command-Control-Shift-4, and paste it into the image well on the action. The image has to be unique (which includes not being visible in the action if the image is small enough not to be shrunk in the image well) otherwise Keyboard Maestro will not know where to click. The Display option in the action will allow you to see where Keyboard Maestro is matching.

1 Like

That is very strange. Have you tried SHIFT-TAB ?

I just tried this in SnagIT when the SaveAs dialog was up, and

  1. 4 presses moved the focus to the "Format" dropdown.
  2. Then a DOWNARROW opened the dropdown.
  3. Typing the name of the file type selected it.
  4. RETURN executed the SaveAs with selected format.

Hey Michael,

Even with full keyboard access turned on?

Always tell us what software you're working in. (I'm inferring this is Digital Performer.)

I can't tell if your “Save As” window is a sheet or a dialog. (Usually these days it's a sheet.)

Here's how it might be possible to accomplish your task with AppleScript and System Events.

tell application "System Events"
  tell application process "BBEdit"
    set frontmost to true
    tell (first window whose subrole is "AXStandardWindow")
      tell sheet 1
        tell pop up button 1 of group 1
          perform action "AXShowMenu"
        end tell
      end tell
    end tell
  end tell
end tell

This example is using BBEdit, since I don't have Digital Performer handy.

This may or may not work by changing the process name to “Digital Performer” – open your dialog and run the script from Script Editor.app to find out.

If it doesn't work then some detective work is in order.

-Chris

1 Like

I'm attempting the same thing in Adobe Illustrator CC 2015. I can access the File Format Popup menu using multiple tabs, but this only works if there are no sub-folders. Sub-folders changes the number of tabs required. I would like the macro to work regardless of the existence of sub-folders. Was not able to make the AppleScript work in Illustrator.

Any other suggestions would be appreciated.

More info: I learned if I "minimise" the Save As window, the number of Tabs remains constant because the multiple folders are not visible. My next question is how to determine what state the window is in and how to toggle it within the macro. Here are the two screen states.


Popup menus are tricky to control. To select a popup menu, you need to simulate a click on the menu, and then use typeahead to select the desired item, ie actions:

Click on popup menu
Insert Text by Typing "Menu Name%Return%"

The tricky part is clicking on the menu. First, make sure you have paused long enough to allow the window to come to the front, and then you can need to click on the popup. You can click in one of these ways:

  • if the window has keyboard focus, then you can click relative to the window, and if the popup menu is in a fixed location, then that may be a reliable solution. It probably isn't in this case.
  • click relative to the found image. If the popup menu always defaults to the same thing, then you can use the popup menu as the image. Otherwise, you need to click relative to something nearby that is consistent (like some label text). If the window always comes up with the same format selected, then the whole area of the popup menu might be a good choice for the image:

To click relative to an image, you use the Mouse Click action, configure it to be relative to a found image, and take a screenshot of the desired area of the screen using Command-Control-Shift-4, and paste it into the image well on the action. The image has to be unique (which includes not being visible in the action if the image is small enough not to be shrunk in the image well) otherwise Keyboard Maestro will not know where to click. The Display option in the action will allow you to see where Keyboard Maestro is matching.

1 Like

Thanks for the suggestions. I ended up using "Found Image" but selected only the menu name and a small portion of the pull-down outline. This allows the macro to work regardless of the current format selected.

I didn't really understand your instructions:

Should I have used a Variable for "Adobe PDF"? It seems to work as is, but want to make it a efficient as reasonably possible.

No. The %Return% is pretty much the same as the first Type a Keystroke Enter.

Because you are switching text focus from the window to the menu (after the click) and from the menu to the window (after the first Enter), you might need to include a short Pause action there. Generally, I would not add a pause until I noticed the macro was not robust, and would then look at where a pause might be needed.

@ccstone: How can I select the 6. entry from the pull down menu with the script?
In my case: the label is: "OFX-Datei for YNAB (.ofx)

tell application "System Events"
	tell application process "MoneyMoney"
		set frontmost to true
		tell (first window whose subrole is "AXStandardWindow")
			tell sheet 1
				tell pop up button 1 of group 1
					perform action "AXShowMenu"
				end tell
			end tell
		end tell
	end tell
end tell

Hey Thomas,

Is that a save dialog? If so, we can probably work with it.

-Chris

Yes. This is the "Save as/Export dialog" dialog from the app.

I use this:

tell application "System Events"
	tell application process "MoneyMoney"
		set frontmost to true
		tell (first window whose subrole is "AXStandardWindow")
			tell sheet 1
				tell pop up button 1 of group 1
					if value is not "OFX-Datei for YNAB (.ofx)" then
						click
						delay 0.5
						pick menu item "OFX-Datei for YNAB (.ofx)" of menu 1
					end if
				end tell
			end tell
		end tell
	end tell
end tell

… is there an elegant way?

This is the dialog:

And a second question: I have a correct filepath + file name in a KM variable. How can I fill the "file name field" with the value from the KM variable an push the button "Export" in the save as dialog ? The KM variable name is: YNAB_OFX_FILE

Hey Thomas,

Doing all of that gets a trifle complicated, but it’s all doable.

Because you have Default Folder X installed you can even set the destination of the export dialog.

I’ve done this in a hard-coded property

property destinationFolderAlias : path to downloads folder

But you can change that to:

set myFilePath to getvariable "YOUR_VARIABLE_NAME" --» User Setting

In the tell Keyboard Maestro Engine block.

Note that the file name and file destination are two different variables in the script.

-Chris

------------------------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2017/11/21 22:28
# dMod: 2017/11/22 09:15
# Appl: MoneyMoney, System Events
# Task: Automate Export Dialog
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @ccstone, @MoneyMoney, @System_Events, @Automate, @Export, @Dialog
------------------------------------------------------------------------------
# USER SETTINGS:
------------------------------------------------------------------------------
property destinationFolderAlias : path to downloads folder
property exportButtonName : "Export"
property fileType : "SEPA camt.053 (.xml)"
------------------------------------------------------------------------------

tell application "Keyboard Maestro Engine"
   set myFileName to getvariable "YNAB_OFX_FILE" --» User Setting
end tell

tell application "System Events"
   tell application process "MoneyMoney"
      tell window "MoneyMoney"
         tell sheet 1
            if (it exists) = false then error "The save dialog is NOT open!"
            
            --» Set value of save-as file name.
            tell (first text field whose name is "Save As:")
               set value to myFileName
            end tell
            
            --» Set file-type to save.
            tell group 1
               tell pop up button 1
                  perform action "AXShowMenu"
                  delay 0.1
                  tell menu 1
                     tell menu item fileType
                        perform action "AXPress"
                     end tell
                  end tell
               end tell
            end tell
            
            --» Set save destination.
            setDialogDestination(destinationFolderAlias) of me
            
            --» Press export button.
            tell (first button whose name is exportButtonName) --» User Setting
               perform action "AXPress"
            end tell
            
         end tell
      end tell
   end tell
end tell

------------------------------------------------------------------------------
--» HANDLERS
------------------------------------------------------------------------------
# Set export destination using Default Folder.
------------------------------------------------------------------------------
on setDialogDestination(destinationFolderAlias)
   tell application "Default Folder X"
      
      repeat while (get IsDialogOpen) = false
         
         if (get IsDialogOpen) = true then
            exit repeat
         end if
         
         delay 0.1
         
      end repeat
      
      delay 0.1
      
      if (get GetCurrentFolder) ≠ destinationFolderAlias then
         SwitchToFolder destinationFolderAlias
      end if
      
   end tell
end setDialogDestination
------------------------------------------------------------------------------
1 Like

I need a little help with the script. The Script reports an error:

excution error: „System Events“ hat einen Fehler erhalten: „menu 1 of pop up button 1 of group 1 of sheet 1 of window "MoneyMoney" of application process "MoneyMoney"“ kann nicht gelesen werden. Ungültiger Index. (-1719)

IMO it is problem to select the file type?

Script with my modifications: (German string for save as) and a different filetype
------------------------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2017/11/21 22:28
# dMod: 2017/11/22 09:15
# Appl: MoneyMoney, System Events
# Task: Automate Export Dialog
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @ccstone, @MoneyMoney, @System_Events, @Automate, @Export, @Dialog
# 2017-11-26 Replaced: “Save as:” with “Speichern unter:”
------------------------------------------------------------------------------
# USER SETTINGS:
------------------------------------------------------------------------------
property destinationFolderAlias : path to downloads folder
property exportButtonName : "Exportieren"
property fileType : “OFX-Datei for YNAB (.ofx)”
------------------------------------------------------------------------------

tell application "Keyboard Maestro Engine"
	set myFilePath to getvariable "YNAB_OFX_PATH" --» User Setting
	set myFileName to getvariable "YNAB_OFX_FILENAME" --» User Setting
end tell

tell application "System Events"
	tell application process "MoneyMoney"
		tell window "MoneyMoney"
			tell sheet 1
				if (it exists) = false then error "The save dialog is NOT open!"
				
				--» Set value of save-as file name. » German: "Sichern unter:"
				tell (first text field whose name is "Sichern unter:")
					set value to myFileName
				end tell
				
				--» Set file-type to save.
				tell group 1
					tell pop up button 1
						perform action "AXShowMenu"
						delay 0.9
						tell menu 1
							tell menu item fileType
								perform action "AXPress"
							end tell
						end tell
					end tell
				end tell
				
				--» Set save destination.
				setDialogDestination(destinationFolderAlias) of me
				
				--» Press export button.
				tell (first button whose name is exportButtonName) --» User Setting
					perform action "AXPress"
				end tell
				
			end tell
		end tell
	end tell
end tell

------------------------------------------------------------------------------
--» HANDLERS
------------------------------------------------------------------------------
# Set export destination using Default Folder.
------------------------------------------------------------------------------
on setDialogDestination(destinationFolderAlias)
	tell application "Default Folder X"
		
		repeat while (get IsDialogOpen) = false
			
			if (get IsDialogOpen) = true then
				exit repeat
			end if
			
			delay 0.1
			
		end repeat
		
		delay 0.1
		
		if (get GetCurrentFolder) ≠ destinationFolderAlias then
			SwitchToFolder destinationFolderAlias
		end if
		
	end tell
end setDialogDestination
------------------------------------------------------------------------------

And one thing is not clear. How can I use my own file path YNAB_OFX_PATH in the Default Folder X dialog?

1 Like

Hey Thomas,

Give me a real-world example path.

-Chris

Example:

YNAB_OFX_PATH="/tmp/"
YNAB_OFX_FILENAME="20171126_D.ofx"

Hey Thomas (@confluencepoint),

It took me some time to get back to this, but I think I have a solution.

You’ll have to return a value or two back to German.

-Chris

----------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2017/11/21 22:28
# dMod: 2017/12/03 20:03
# Appl: MoneyMoney, System Events
# Task: Automate Export Dialog
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @ccstone, @MoneyMoney, @System_Events, @Automate, @Export, @Dialog
# 2017-11-26 Replaced: "Save as:" with "Speichern unter:"
----------------------------------------------------------------
# USER SETTINGS:
----------------------------------------------------------------
property exportButtonName : "Export"
property fileType : "CSV File (.csv)"
# property fileType : "OFX-Datei for YNAB (.ofx)"
----------------------------------------------------------------

tell application "Keyboard Maestro Engine"
   set myFilePath to getvariable "YNAB_OFX_PATH" --» User Setting
   set myFileName to getvariable "YNAB_OFX_FILENAME" --» User Setting
end tell

tell application "System Events"
   tell application process "MoneyMoney"
      tell window "MoneyMoney"
         tell sheet 1
            if (it exists) = false then error "The save dialog is NOT open!"
            
            --» Set value of save-as file name. » German: "Sichern unter:"
            tell (first text field whose name is "Save As:")
               set value to myFileName
            end tell
            
            --» Set file-type to save.
            tell group 1
               tell pop up button 1
                  perform action "AXShowMenu"
                  delay 0.9
                  tell menu 1
                     tell menu item fileType
                        perform action "AXPress"
                     end tell
                  end tell
               end tell
            end tell
            
            --» Set save destination in save dialog.
            setDialogDestination(myFilePath) of me
            --» Press export button.
            tell (first button whose name is exportButtonName) --» User Setting
               perform action "AXPress"
            end tell
            
         end tell
      end tell
   end tell
end tell

----------------------------------------------------------------
--» HANDLERS
----------------------------------------------------------------
# Set export destination using Default Folder.
----------------------------------------------------------------
on setDialogDestination(destinationFolderPath)
   tell application "Default Folder X"
      
      repeat while (get IsDialogOpen) = false
         
         if (get IsDialogOpen) = true then
            exit repeat
         end if
         
         delay 0.1
         
      end repeat
      
      delay 0.1
      
      if (get GetCurrentFolder) ≠ destinationFolderPath then
         SwitchToFolder destinationFolderPath
      end if
      
   end tell
end setDialogDestination
----------------------------------------------------------------

@ccstone: The script hangs on these lines …

tell group 1
   tell pop up button 1
      perform action "AXShowMenu"
      delay 0.9
      tell menu 1
         tell menu item fileType
            perform action "AXPress"
         end tell
      end tell
   end tell
end tell

The pop out dialog opens - but nothing happens.

Did you change the fileType property back to the one you want to use?

-ccs

Sure!

----------------------------------------------------------------
# USER SETTINGS:
----------------------------------------------------------------
property exportButtonName : "Exportieren"
property fileType : "OFX-Datei for YNAB (.ofx)"
----------------------------------------------------------------