Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Recycle File
#11
Nope, Steve, same deal.
Reply
#12
Code: (Select All)


Screen _NewImage(800, 600, 32)

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
' Build an osascript command that tells Finder to delete the POSIX file (move to Trash)
' Use single quotes around the whole -e argument in the shell, and escape inner double quotes for AppleScript.
cmd$ = "osascript -e " + Chr$(34) + _
"tell application " + Chr$(34) + "Finder" + Chr$(34) + _
" to delete POSIX file " + Chr$(34) + file$ + Chr$(34) + Chr$(34)
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

One last test. This is after pestering AI to sort out the formatting issue. It claims this will work. LOL

Tony suggests changing that delete to move and giving it a test if this doesn't work. @NakedApe mind giving both variations a try and see what we break?
Reply
#13
And for a file on the desktop to be trashed - on my system:

SHELL "trash /users/me/desktop/myfile.txt"
Reply
#14
(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 !)
Reply
#15
Yep, it's just this.

Code: (Select All)
Screen _NewImage(800, 600, 32)

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
            ' Build an osascript command that tells Finder to delete the POSIX file (move to Trash)
            ' Use single quotes around the whole -e argument in the shell, and escape inner double quotes for AppleScript.
            cmd$ = "trash " + file$
            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
#16
(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 !
Reply
#17
@SMcNeill  No, no and... no. But points for persistence!
Reply
#18
I was hoping to not use trash as this is what I get when searching it on the web:

Quote:Compatibility Across Versions
The Trash feature has been present in all versions of macOS, including earlier iterations like Mac OS X. However, the specific command-line methods and user interface may vary slightly between versions.

Conclusion
While the Trash feature is universally available across all macOS versions, the command-line access and specific functionalities may differ. Users can always find the Trash through the Finder or the Dock, regardless of the macOS version they are using.

I was looking for something which would be more universal and thought the osascript would do the job, but apparently it's not being good and playing nice like it should. I guess trash it is, and folks may have to tweak as necessary for their own OS version if it's a slightly different syntax as warned about above.
Reply
#19
Dunno, ahenry, the code I updated above works like a charm on a modern Mac.
Reply
#20
Updated the code to make use of the trash command, but I did put the filename in quotes.

I imagine as it is, it may have issues with something like My File.txt, where there's a space in there.  Most command line parsers tend to get blown up unless you keep things together inside quotes like that.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)