Default Folder: setting default folders for uploading to specific URLs/domains

Just got a new handy automation working with the help of the Default Folder developer: the ability to set a default folder for a specific URL/domain.

Typically you can only specify default folders for the entire app.

I wanted this functionality for certain domains to which I always upload from a certain folder.

Turns out a recent Default Folder upgrade got AppleScript functionality. Jon over at St. Clair Software had a similar existing AppleScript setup which did the opposite of what I wanted, saving files from a specific app to the most recently-modified project folder.

Jon was kind enough to work up an AppleScript to do what I wanted. See the AppleScript code below, and note that the file must be named “GetDefaultFolder.scpt” (and placed in the proper directory) for it to work. See the link in the previous paragraph for more details.

My sample AppleScript is set up to default to a certain folder in iCloud Drive when invoking the standard macOS “Open File” sheet when clicking on an “upload file” button on a web page, so you’ll have to edit the script to point to the directory of your choice. I left the iCloud Drive file path in the example code because it was a bit tricky figuring that out.

In this example the script would only default to the “t-shirts” folder if the upload domain included “printful.com”.

If you want to add more domain/folder pairs, that has to be done in the AppleScript (using if/else I assume) and I’ve not yet figured out how to do that (my AppleScript skills are very basic, always have to refresh my knowledge each time I code a new one).

------------------------------------------------------------------------------------------------------------
-- getDefaultFolder( appName, dialogType, firstTime )
--
-- 		appName is a string containing the name of the app that owns the file dialog.
--		dialogType is a string containing either "open" or "save" to indicate the dialog type.
--		firstTime is a boolean indicating if this is the first dialog shown since the app launched.
--
--		The return value can be an alias, posix file, valid path name, or nothing.
--		If you return nothing, Default Folder X will proceed with its normal behavior.
------------------------------------------------------------------------------------------------------------

on getDefaultFolder(appName, dialogType, firstTime)
	set userLibraryFolder to path to library folder from user domain
	tell application "Finder"
		set uploadFolder to folder "t-shirts" of folder "merchandise" of folder "Art" of folder "iCloud Drive" of folder "Mobile Documents" of userLibraryFolder as alias
	end tell
	
	tell application "Safari"
		set currentURL to URL of document 1
	end tell
	
	set theResult to ""
	
	set hostName to DNS form of host of (currentURL as URL)
	if hostName ends with "printful.com" then
		set theResult to uploadFolder as alias
	end if
	
	return theResult
end getDefaultFolder

1 Like