adding folder to doc - right click doesnt reveal fan, grid, list etc


the code from this old post places a folder in the doc, that’s fine, but when you go to right click to set
either fan, grid, list or automatic it doesn’t show them, or other selections, does any one no how to
change the script top allow those selections and the others please, as if you were manually placing a folder
in the doc.


I have set the code uo to work how I need it and it works great, adds folder COMMON adds it to the dock, adds alias
of files I want in the the folder COMMON, but I still have no idea how to have the folder in the dock when right clicked show the options to have it as list, grid etc any help appreciated here please.

tell application "Finder"
	set scriptfolder to ((path to documents folder) as string) & "COMMON"
	if not (exists alias scriptfolder) then
		make folder at folder ((path to documents folder) as string) with properties {name:"COMMON"}
	end if
	set theFolder to folder scriptfolder
	delete every item of theFolder
	set add_item_to_dock to scriptfolder
	set item_path to POSIX path of add_item_to_dock
		tell application "Dock" to quit
	end try
	do shell script "defaults write persistent-others -array-add '<dict><key>tile-data</key><dict><key>file-data</key><dict><key>_CFURLString</key><string>" & item_path & "</string><key>_CFURLStringType</key><integer>0</integer></dict></dict></dict>'"
		tell application "Dock" to activate
	end try
	set _AliasFile to {myMel1, myMel2, myMel3} --THIS IS THE LIST OF FILES TO GO INTO THIS FOLDER AS ALAIS
	set WhereToPutAlias to scriptfolder
	repeat with theItem in _AliasFile
		tell application "Finder" to make new alias file at WhereToPutAlias to theItem
	end repeat
end tell

Not tested but it may be useful to take care of the comment posted in the source thread. It urged users to add the sting in bold (I underlined it here too).

“defaults write persistent-others -array-add ‘tile-datafile-data_CFURLString/Users/user/Filepath/_CFURLStringType0tile-typefile-tile’; killall Dock”

Yvan KOENIG running El Capitan 10.11.1 in French (VALLAURIS, France) mercredi 18 novembre 2015 11:00:59

Thanks Yvan

I tried that bit, but for me under OSX10.11.1 it creates the folder and alias’s etc, but all it puts in the dock is a question mark

The first part of the script can be simplified a bit

set documentsFolder to path to documents folder
tell application "Finder"
	if not (exists folder "COMMON" of documentsFolder) then
		make folder at documentsFolder with properties {name:"COMMON"}
	end if
	set scriptfolder to folder "COMMON" of documentsFolder as alias
	delete every item of scriptfolder
end tell
set item_path to POSIX path of script folder

delete also the last

end tell

to avoid nested application tell blocks

Thanks Stefan, it’s working a bit faster now

any ideas about the other part, when right clicking not showing the fan, grid, list etc etc, ?

I have found that the script puts the folder in the dock, and seems to treat it like an icon thats in the dock
i.e.: right click an icon and it will give you “options” & a few other selections, yet if you right click a folder
manually placed in the dock you get all the options to “view as” & “display as” etc etc.

If I manually remove the folder generated from the script from the dock and then manually put it back in the
dock you now can select view option etc etc.

Must be some where in the something missing that differentiates between icon and folder?

any ideas?

ok, I think I have found the problem.

When the code creates the folder it makes it’s tile-type String “file-tile”

and when you manually put a folder into the dock it makes it tile-type String “directory-tile”

I tested this by having the code create the folder in the dock, then opened the plist and
manually changed the tile-type from file-tile to directory-tile and issued a killall Dock from terminal
and wolla, all the view as etc etc appears

problem is I don’t no how to write this into the code, can someone help me out here please.

getting there, managed to figure out through a lot of trial and error how to get “file-tile” to be “directory-tile”

The next part was to figure out how to have it open as “List” view,

as far as I can figure the “showas” as integer for Automatic is 0, and 3 is list view


the above slotted in does change the showas from 0 to 3 but upon dock relaunch it still remains as Automatic
even tried killing the dock again, but this does nothing but consume time, it may be in the wrong place, not sure

do shell script "defaults write persistent-others -array-add '<dict><key>tile-data</key><dict><key>file-data</key><dict><key>_CFURLString</key><string>" & item_path & "</string><key>_CFURLStringType</key><integer>0</integer></dict></dict><key>tile-type</key><string>directory-tile</string></dict></dict><key>showas</key><integer>3</integer></dict></dict></dict>'"