make new Finder window with properties...works?

Hi folks.

I’m trying to open a finder window with properties, but she doesn’t want to take.


property myTarget : "/Users/rich/Documents/Scanned/"

tell application "Finder"
	set myW to make new Finder window with properties {current view:list view, toolbar visible:true, target:myTarget}
end tell

The target isn’t being taken for some reason. No errors, but it just won’t go to the target I want.

Any ideas appreciated.

Cheers

Hi,

set the target in an extra line


set myTarget to (path to documents folder as text) & "Scanned:"

tell application "Finder"
	set myW to make new Finder window with properties {current view:list view, toolbar visible:true}
	set target of myW to myTarget
end tell

Note: AppleScript expects HFS paths (colon separated)

Ah very good. Why won’t the object take the setter method with parameters? Neither target nor current view stuck as properties.

Cheers

It often happens that some initial properties can’t be set with the ‘with properties’ parameter ” not just with the Finder, but with potentially any application. The reason could be a technicality to do with the kind of object being ‘made’ or an oversight or idiosyncasy on the part of the developer.

However, the Finder’s implementation of ‘make’ has a ‘to’ parameter, which can be used with either ‘alias files’ or ‘Finder windows’.


set myTarget to (path to documents folder as text) & "Scanned:"

tell application "Finder"
	set myW to make new Finder window to folder myTarget
	tell myW to set {current view, toolbar visible} to {list view, true}
end tell

Or, if you don’t need to refer to the window again in the script:


set myTarget to (path to documents folder as text) & "Scanned:"

tell application "Finder"
	tell (make new Finder window to folder myTarget) to set {current view, toolbar visible} to {list view, true}
end tell

Yes, those would be setter methods for an object oriented system. The instance of the object, given properties, should stick. I’d say this is a fault with something. Modifying properties after the object is made shows their onCreate methods lack proper attribute assignment.

LOL I never got AS syntax.

Cheers

Sorry to resurrect this old post, but I wonder: Did anybody find a solution by now?

Is it possible to set a Finder window’s properties, such as view, target, icon size, bounds, etc. before making the widow?
Otherwise you can actually see the changes occur, which is somewhat inelegant…

Thanks!

Sorry, nope you can’t set properties of a finder window, or any window before you create it.

It is actually possible to set the view and view options before opening a window:


set myTarget to (path to documents folder as text) & "Scanned:"

tell application "Finder"
	tell container window of folder myTarget
		set current view to list view
		set icon size of its list view options to large icon
		open
		set its bounds to {50, 50, 800, 800}
		set its toolbar visible to true
	end tell
end tell

I’m sorry. I have never noticed the container window before. At least I can’t recall having used it.

Thanks for showing that the toolbar visible still works. I was sure it was gone now,with the additions of the tabs. :slight_smile:

This worked for me. It’s somewhat of a preset, and it worked as a one-liner too. The new window is quickly modified even though it’s properties (other than target) are not actually set prior to the window appearing. But the values are!


	set myTarget to path to desktop folder as text
	set myBounds to {5, 10, 50, 100}
	set myZoomed to false --some item of {true, false} --
	set myCollapsed to false --some item of {true, false} --
	set myView to list view --some item of {list view, column view, icon view, flow view} --
	set mySidebar to 150 --(some item of {0, 100, 200, 300}) --300 -- 
	
	set {newWNDW, properties of newWNDW} to {make new Finder window, {target:myTarget, bounds:myBounds, zoomed:myZoomed, collapsed:myCollapsed, current view:myView, sidebar width:mySidebar}}
	
	return properties of newWNDW

Model: Mac Pro, Yosemite
AppleScript: 2.7
Browser: Safari 601.2.7
Operating System: macOS 10.14

For me too, if I include the :

tell application "Finder"

end tell