Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Recycle File
#21
(02-28-2026, 01:42 AM)ahenry3068 Wrote:
(02-28-2026, 01:34 AM)ahenry3068 Wrote:
(02-28-2026, 01:16 AM)NakedApe Wrote: Sorry, ahenry that didn't do it either.

SHELL "trash myfile.txt" works for me when the file is in the current working directory - QB folder here.

   Well hell.   Then do that !   It's certainly a lot simpler than Applescript.  

I would guess it should work with a full pathname too.   (adding Quotes around it if it has spaces in it !)
after the if FileExists I would add

    if Instr(File$, chr$(32)) > 0 then File$ = chr$(34) + File$ + Chr$(34) 

Space's in file names need to be quoted on the command line !

This would break Windows as we single quote the file names and use double quotes for the entire powershell command.

think of it as powershell -command "RENAME 'whatever.txt' AS 'whatnever.txt' "

The version I updated put those quotes in the mac shell statement, and not where you suggest.  Wink   

SHELL "trash " + CHR$(34) + file$ + CHR$(34)
Reply
#22
Note that the documentation also seems to suggest that this simple method would work:

https://www.macterminal.cc/answers/mv-command-examples

Code: (Select All)
SHELL "mv file.txt ~/.Trash/"

If folks try trash and it doesn't work on their systems, they may want to swap this in and give it a go and see how it does for them as well.  It's always nice to have a backup in case something doesn't work right.
Reply
#23
I tried the "mv" method first and it wouldn't work for me. Shrug.
Reply
#24
(02-28-2026, 02:10 AM)NakedApe Wrote: I tried the "mv" method first and it wouldn't work for me. Shrug.

And folks wonder why I stick to windows.  LOL!!  

I put both in there.  Hopefully one or the other will work for folks.  If not, then they may have to just keep tossing things at it themselves until they sort out what works on their systems.  The documentation claims it works, but with apple one always has to ask "When was it implemented?  When was it obsoleted?"  They swap and change commands every few years just so folks have to buy new machines to keep using modern software.  It's all a scam, in my opinion.
Reply
#25
I'd be happy to help you...

 - Jia Tan Big Grin
Reply
#26
@SMcNeill 
I tested this variation on my old Mac and it appears to work. The other version deleted the file permanently after fixing it with the slash quotes.

Thank you Steve for the program.
Code: (Select All)
OPEN "MyFile.txt" FOR OUTPUT AS #1
PRINT #1, "Test:" + DATE$ + " " + TIME$
CLOSE
PRINT "File created called MyFile.txt"

Recycle "MyFile.txt"
PRINT "MyFile.txt should now be recycled and in the Recycle Bin, instead of just erased permanently."
PRINT "Check your recycle bin to see if it exists there and contains a simple message of 'Test'."
END

SUB Recycle (file$)
  IF _FILEEXISTS(file$) THEN
    $IF WIN THEN
            ps$ = "powershell -NoLogo -NoProfile -Command "
            ps$ = ps$ + Chr$(34) + "Add-Type -AssemblyName Microsoft.VisualBasic; "
            ps$ = ps$ + "[Microsoft.VisualBasic.FileIO.FileSystem]:eleteFile('"
            ps$ = ps$ + file$
            ps$ = ps$ + "','OnlyErrorDialogs','SendToRecycleBin')" + Chr$(34)
            Shell _Hide ps$
    $ELSEIF MAC THEN
            cmd$ = "mv " + Chr$(34) + file$ + Chr$(34) + " ~/.Trash/"
            Shell cmd$
    $ELSE
      'Assume Linux-like environment with gio available
      SHELL _HIDE "gio trash " + CHR$(34) + file$ + CHR$(34)
    $END IF
  END IF
END SUB
Reply
#27
Do you guys have two different Macs or something?  Is one an ARM processor while the other isn't?

One command works for one of you and not the other, while the other has the exact opposite results.  If this is something as simple as ARM being involved vs not, then we can trap for that and sort out the issue for good.  Otherwise, The solution may be to add a toggle for mac owners to choose which to run on their system.   I don't personally have one for testing so have no way to check for myself (and if it's a difference in OS, I still would only get *one* result for my own OS and not be able to account for others), so all I can do is pester you guys and fumble blindly while trying to sort out what the difference might be and why it seems to work sometimes but differently than expected other times.
Reply
#28
My Mac is 14 years old ebay buy for $200. It smells like BO and cigarettes, I hate it. It's running Catalina. 

Could be a permissions thing, if so permissions would have to be granted prior to running the command. It may just fail silently.

If someone wants to try to troubleshoot it. Have the cmd$ write to the clipboard instead of the shell and then copy and paste to the console and then run it. See what the shell complains about.
Reply
#29
Or try $CONSOLE:ONLY and then remove the _HIDE from that shell hide statement.  It should let you see in the console that pops up whatever the output is that it's returning for you, even if that's just something generic like "command not recognized" or whatnot for the OS.
Reply
#30
Yes, justsomeguy has an Intel-based Mac while mine is an M2 ARM-based Mac, which is about four years old. Yesterday I looked up "mv" and "trash" and I coulda sworn it said that the Mac/Unix terminal command trash was introduced in 2023, but now I can't find that. And what I did find says that the trash command is non-native and requires installing with third-party software. Wha?!  I just tried it again and it works fine, so I'm fairly flummoxed with this.

I just created a dummy file and used Terminal to "trash /users/me/desktop/crap.pages" and the file was successfully moved to the trash can. Maybe Sam @a740g can shine some light on this? 
Reply


Forum Jump:


Users browsing this thread: