Change Or Set Google Chrome Download Location For Specific Files

I have my Chrome default preference set to "Ask where to save each file before downloading". However, there are messages with particular attachments that I want to always download to a specific location.

Is there a way to programmatically set the download location (.e.g. using AppleScript) rather than using the KM "Click at Found Image" approach? I have a KM macro that sets the filename and want it to also set or ensure the download directory is specified and perhaps different from the default location.

Keyboard Maestro “AUC Overtime Comparison - Week Ending Filename To Download” Macro

AUC Overtime Comparison - Week Ending Filename To Download.kmmacros (2.6 KB)

If all you need is to know how to get it in the right folder, then this should help. I use this when I'm exporting certain things in Quiver, but the concept should be the same. Here's the screenshot, then I'll explain the steps below, so you know how to use this in your situation:

  1. I included the first action, which is the menu item that starts the export, so you could see all this in context.

  2. "Wait for Save button" waits until the Save dialog appears, so I don't have to use a pause of indiscriminate duration.

  3. The ⇧⌘G opens the "Go To" dialog, which is native to the Save dialog.

  4. Waits until the "Go To" dialog pops up.

  5. Here I insert the folder I want. I used "Insert by Typing" because I didn't want to change the clipboard.

  6. Closes the "Go To" dialog, effectively "going to" the desired folder.

  7. Waits for the "Go To" dialog to close, so we're back in the Save dialog.

  8. Self-explanatory.

  9. This just waits until the save has completed. At least for Quiver, this works.

Here's the actions. Have fun!

Keyboard Maestro Actions.kmactions (4.0 KB)

One warning: The next time you use the Save dialog, it will be in the folder you "went to" before. So be aware of this, in case it affects future "save" automations.

Dan,

Works perfectly! I’ve marked it as solved.

Now I’m interested in a “behind the scenes” way to determine if a location change is necessary or not?

Thanks for your assistance,

If you figure it out, let me know. :slight_smile:

If I'm not mistaken, Default Folder X supports this via scripting. In fact, I think it probably makes this whole task a lot easier. I installed it once, but it was overkill and made my head spin.

I just read another solution, and I think this might be better, depending on your situation.

You could have it always save to the same location, then move the file after the save.

The only issue here would be making sure you don’t accidentally have the Save folder set to something else…

Hey Dan,

A lot of people say that, until they've used it long enough to know better.  :sunglasses:

Just being able to jump to a window open in the Finder in the open/save dialog is handy enough – or to open the location in the open or save dialog in the Finder.

I've used Default Folder since at least 1994 and would hate to give it up.

Yes. In fact Jon Gotow has added some goodies for me a couple of times. (He's a good guy.)

It's as simple as this:

tell application "Default Folder X"
   if IsDialogOpen then
      set currentSaveLocation to (GetCurrentFolder) as alias
   end if
end tell

In my opinion it's pretty silly that you can't directly query an open/save dialog for its disk-location, but there's Apple for you.

Default Folder is the only way (I know of) to get the full path of the location of an open/save dialog.

You can get the folder name of the open/save location with System Events though:

tell application "System Events"
   tell application process "Safari"
      tell (first window whose subrole is "AXStandardWindow")
         tell sheet 1
            tell pop up button 1 of group 2
               set locationName to value of attribute "AXValue"
            end tell
         end tell
      end tell
   end tell
end tell

If your locations are unique enough that might do.

-Chris

3 Likes

Chris,

What would the changes be for an open/save dialog in Chrome? I tried the following and got an error:

tell application "System Events"
	tell application process "Chrome"
		tell (first window whose subrole is "AXStandardWindow")
			tell sheet 1
				tell pop up button 1 of group 2
					set locationName to value of attribute "AXValue"
				end tell
			end tell
		end tell
	end tell
end tell

/var/folders/0q/dkk35gnd3pz4sppnxhphs2qw0000gn/T/Keyboard-Maestro-Script-CDAEFE59-38C5-4B59-AE2B-09C41A342790:233:238: execution error: System Events got an error: Can’t get group 2 of sheet 1 of window 1 of application process “Chrome” whose subrole = “AXStandardWindow”. Invalid index. (-1719)

Hey Anthony,

You're running into trouble, because you haven't used the correct process name:

tell application process "Google Chrome"

Not Chrome but Google Chrome.

Ordinarily the process name is the same as the application name shown in the macOS application switcher, but this is not a sinecure.

It's always a good idea to check:

tell application "System Events"
   name of processes whose name contains "chrome"
end tell

In this case you'll find the main process and several helper processes.

-Chris

Chris,

I’m in no way familiar with code, so I’ve just tried a couple of modifications, but still getting a similar error.

tell application "System Events"
   tell application process "Google Chrome"
      tell (first window whose subrole is "AXStandardWindow")
         tell sheet 1
            tell pop up button 1 of group 2
               set locationName to value of attribute "AXValue"
            end tell
         end tell
      end tell
   end tell
end tell

Yields:
/var/folders/0q/dkk35gnd3pz4sppnxhphs2qw0000gn/T/Keyboard-Maestro-Script-2044DAC5-877C-4CCB-90FD-827802138616:210:215: execution error: System Events got an error: Can’t get group 2 of sheet 1 of window 1 of application process “Google Chrome” whose subrole = “AXStandardWindow”. Invalid index. (-1719)

tell application "System Events"
   tell application process "Google Chrome"
      tell (window whose subrole is "AXStandardWindow")
         tell sheet 1
            tell pop up button 1 of group 2
               set locationName to value of attribute "AXValue"
            end tell
         end tell
      end tell
   end tell
end tell

Yields:
/var/folders/0q/dkk35gnd3pz4sppnxhphs2qw0000gn/T/Keyboard-Maestro-Script-BAA355BE-4901-439C-9955-9A5FDB946D63:73:269: execution error: Can’t get window whose subrole = “AXStandardWindow”. (-1728)

Hey Folks,

@KM_Panther and I talked about this off-list and discovered that he was using the collapsed form of the save dialog, whereas I was using the uncollapsed one.

This should work for both open and save (collapsed or uncollapsed) dialogs.

------------------------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2017/01/09 20:45
# dMod: 2017/01/09 21:12
# Appl: Google Chrome & System Events
# Task: Extract the name of the location of the available Open or Save Dialog.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @System_Events, @Google_Chome, @Extract, @Name, @Location, @Open, @Save, @Dialog
# Note: Currently it is impossible to get the full path without the 3rd Pty. utility Default Folder.
------------------------------------------------------------------------------

tell application "System Events"
   tell application process "Google Chrome"
      if frontmost is not true then set frontmost to true
      tell (first window whose subrole is "AXStandardWindow")
         tell sheet 1
            if its accessibility description is "save" then
               if pop up button 1 exists then
                  set dialogLocationName to value of pop up button 1 -- Collapsed Save Dialog
               else
                  set dialogLocationName to value of pop up button 1 of group 2 -- Uncollapsed Save Dialog
               end if
            else if its accessibility description is "open" then -- Open Dialog
               tell group 2
                  tell pop up button 1
                     set dialogLocationName to its value
                  end tell
               end tell
            end if
         end tell
      end tell
   end tell
end tell

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

-Chris

Chris,

Also tested with successful results!

Many thanks

1 Like

Chris,

Any chance of modifying the macro below of yours I found and using it with the above script to both confirm the folder and select single or multiple files for email attachments? The macro below only works with "Finder" and I couldn't get it to access the folder file list shown in the "Google Chrome" window.

Files { Select in Front Window } { KM Version }.kmmacros (7.6 KB)

Nope.