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.
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:
I included the first action, which is the menu item that starts the export, so you could see all this in context.
"Wait for Save button" waits until the Save dialog appears, so I don't have to use a pause of indiscriminate duration.
The â§âG opens the "Go To" dialog, which is native to the Save dialog.
Waits until the "Go To" dialog pops up.
Here I insert the folder I want. I used "Insert by Typing" because I didn't want to change the clipboard.
Closes the "Go To" dialog, effectively "going to" the desired folder.
Waits for the "Go To" dialog to close, so we're back in the Save dialog.
Self-explanatory.
This just waits until the save has completed. At least for Quiver, this works.
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.
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.
A lot of people say that, until they've used it long enough to know better.
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.
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)
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
@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
------------------------------------------------------------------------------
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.