Computer Container

I want to use the following in a script but it doesn’t work:

tell application "Finder" to set target of front Finder window to (computer container)

The error message is:

The following works but it opens a new Finder window and this is not what I want.

tell application "Finder" to open (computer container)

GUI scripting works but I’d rather avoid that if possible:

on selectComputerContainer()
	tell application "System Events"
		tell process "Finder"
			click menu item "Computer" of menu "Go" of menu bar 1
		end tell
	end tell
end selectComputerContainer

I also tried the select command but couldn’t get that to work.

The Finder dictionary defines “computer container” as:

This will be used in a long and convoluted script that opens and manipulates a Finder window. However, my simple goal with the above code line is to change the target of a frontmost Finder window to the computer container, which on my computer is “Robert’s Mac mini”. Thanks.

Thanks Fredrik71. I tested your script and it does what I want. It will remain an option along with GUI scripting.

Hello

Assuming that there is a folders named “Tartempion” and “Trucmuche” on the Desktop.

Run the script below:

set p2d to path to desktop

tell application "Finder"
	close every Finder window
	open folder "Trucmuche" of p2d
	get target of front Finder window
	--> folder "Trucmuche" of folder "Desktop" of folder "**********" of folder "Users" of startup disk
	set aContainer to folder "Tartempion" of p2d
	--> folder "Tartempion" of folder "Desktop" of folder "**********" of folder "Users" of startup disk
	(get properties of aContainer)
	--> {class:folder, name:"Tartempion", index:80, displayed name:"Tartempion", name extension:"", extension hidden:false, container:folder "Desktop" of folder "**********" of folder "Users" of startup disk, disk:startup disk, position:{-1, -1}, desktop position:{862, 129}, bounds:{-33, -33, 31, 31}, kind:"Dossier", label index:0, locked:false, description:missing value, comment:"", size:0, physical size:0, creation date:date "mercredi 28 octobre 2020 à 15:41:18", modification date:date "mercredi 28 octobre 2020 à 15:41:18", icon:missing value, URL:"file:///Users/**********/Desktop/Tartempion/", owner:"**********", group:"(inconnu)", owner privileges:read write, group privileges:read only, everyones privileges:read only, container window:container window of folder "Tartempion" of folder "Desktop" of folder "**********" of folder "Users" of startup disk}
	set target of front Finder window to aContainer
	--> folder "Tartempion" of folder "Desktop" of folder "**********" of folder "Users" of startup disk
	
	set aContainer to (get computer container)
	--> computer container
	(get properties of aContainer)
	--> {class:computer-object, name:"iMac de Yvan", index:missing value, displayed name:"iMac de Yvan", name extension:"", extension hidden:false, container:missing value, disk:disk "iMac de Yvan", position:{-1, -1}, desktop position:missing value, bounds:{-33, -33, 31, 31}, kind:"", label index:0, locked:false, description:missing value, comment:missing value, size:missing value, physical size:missing value, creation date:date "lundi 1 janvier 2001 à 01:00:00", modification date:date "lundi 1 janvier 2001 à 01:00:00", icon:missing value, URL:"", owner:"système", group:"(inconnu)", owner privileges:none, group privileges:none, everyones privileges:none}
	set target of front Finder window to aContainer
	--> error number -1700 from «data Toke80D3840000600000» to item
	
end tell

As you may see, if we try to change replace the folder targeted by window 1, by an other folder, it works.
But if we try to replace it by the computer container, it fails.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) mercredi 28 octobre 2020 16:13:52

I see the best solution:


tell application "Finder"
	try
		close Finder window -1 -- close some concrete window (I choose the last here)
		-- close Finder windows -- close all windows if it is what the OP wanted
	end try
	open computer container
end tell

Thanks for the replies. It’s good to know I didn’t miss anything.

This question is similar to the above and I suspect the answer is the same.

The choose folder command has a default location property, which has to be an alias. I’m not sure of the correct terminology but when I open a Finder window the first location is “Robert’s Mac mini”. Is there any way to convert this into an alias for use with the choose folder command, as in the following:

choose folder default location alias "Robert's Mac mini"

The above fails, of course, because Robert’s Mac mini cannot be made into an alias but I thought perhaps there might be a way to do this. If this can’t be done directly, I will use GUI scripting.

Thanks.

Fredrik71. That will work well with my script. Many thanks.

It isn’t so simple. You choose not from computer object but only from disk. Here I wrote workaround to choose indeed from computer container (from Hard disk or Network):


tell application "Finder"
	open computer container
	activate
	set selection to {}
	display dialog "Choose item from computer location"
end tell

repeat
	tell application "Finder" to if not selection is {} then return selection
	delay 0.02
end repeat

NOTE: click triangle to go to subdirectories