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
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
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:”
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
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