Move folders of a folder>> Where am i wrong in this script?

I’m trying to move items of the trashcan to another folder, but only folders whose names begin with "BH’ and “BU”

Whats wrong with this? please

	tell application "Finder"
		set theTrashcan to "~/.trash"
		set fakeTrash to "~/FakeTrash"
		try
			move (folders of the folder theTrashcan whose name starts with "BH" or name starts with "BU" or name starts with "DA" or name starts with "DV" or name starts with "DO" or name starts with "FR" or name starts with "IN" or name starts with "NO" or name starts with "MA" or name starts with "TM" or name starts with "WA" or name starts with "PR" or name starts with "SE") to folder fakeTrash
		end try
	end tell

Hi,

this is the most common mistake or misunderstanding ever

The native path string representation of AppleScript is HFS (starting with a disk name and colon separated)

POSIX style paths (starting with and separated by slashes) are used only in do shell script calls and in a some very rare cases.

PS: while developing and debugging scripts it’s recommended to comment out all try blocks to get error messages

How do I reference the trashcan though?

I had this for the above

set theTrashcan to “Hal 9000:Users:matthew:trash”
set fakeTrash to “Hal 9000:Users:matthew:FakeTrash”

trash starts with a dot, but there is a “shortcut” for the trash folder


set theTrashcan to (path to trash folder as text)

I’m assuming this is due the nature of the trashcan but i get this error

error “Finder got an error: Can’t make alias "Hal 9000:Users:matthew:.Trash:" into type folder.” number -1700 from alias “Hal 9000:Users:matthew:.Trash:” to folder

it seems that you wrote


set theTrashcan to (path to trash folder)

instead of


set theTrashcan to (path to trash folder as text)

the result of the former is an alias, of the latter it’s an HFS path

Sorry my mistake I tried removing it to get it to work but gave this is the error I do get

tell application “Finder”
path to trash as text
→ “Hal 9000:Users:matthew:.Trash:”
move every folder of folder “Hal 9000:Users:matthew:.Trash:” whose name starts with “BH” or name starts with “BU” or name starts with “DA” or name starts with “DV” or name starts with “DO” or name starts with “FR” or name starts with “IN” or name starts with “NO” or name starts with “MA” or name starts with “TM” or name starts with “WA” or name starts with “PR” or name starts with “SE” to folder “Hal 9000:Users:matthew:FakeTrash”
→ error number -1728 from folder “Hal 9000:Users:matthew:.Trash:”
Result:
error “Finder got an error: Can’t get folder "Hal 9000:Users:matthew:.Trash:".” number -1728 from folder “Hal 9000:Users:matthew:.Trash:”

the Finder “sees” only visible items (unless you set showHiddenFiles to true)

Use System Events or the shell

Compelete Novice at this of course but trying to use a few borrowed scripts.
Your help is appreciated.

This is what I have but Result:
error “Finder got an error: Can’t get 1.” number -1728 from 1 to «class furl»

tell application "Finder"
		set fakeTrash to "Hal 9000:Users:matthew:FakeTrash"
		set theTrashcan to paragraphs of (do shell script "ls -F ~/.Trash | grep '/' | cut -d'/' -f1")
		set tc to (count theTrashcan)
		repeat with i from 1 to tc
			set folderName to item i of theTrashcan --<:  is the folder name, no need to use text item delimiters -->":"
			move folder of the (folder folderName whose name starts with "BH" or name starts with "BU" or name starts with "DA" or name starts with "DV" or name starts with "DO" or name starts with "FR" or name starts with "IN" or name starts with "NO" or name starts with "MA" or name starts with "TM" or name starts with "WA" or name starts with "PR" or name starts with "SE") to fakeTrash
			
			
		end repeat
		
		
		
	end tell

this cannot work. To move files with the Finder you have to specify valid object references.
As the Finder doesn’t recognize the trash folder the reference is not valid

I’m going to start a new post to attempt to explain what I am trying to acheive.

try something like this


set trashCan to quoted form of POSIX path of (path to trash folder)
set fakeTrashCan to quoted form of (POSIX path of (path to home folder) & "FakeTrash")
set theFolders to paragraphs of (do shell script "/usr/bin/find " & trashCan & " -type d -name BH* -or -name BU* -or -name DA* -or -name DV* -or -name DO* -or -name FR* -or -name IN* -or -name NO* -or -name MA* -or -name TM* -or -name WA* -or -name PR* -or -name SE*")
repeat with aFolder in theFolders
	do shell script "/bin/mv " & quoted form of aFolder & space & fakeTrashCan
end repeat


That does move the stuff but moves the contents of the folders rather than the folder and its contents.

Is that still possible?