How to put an image into the system-wastebox of macOS or winXP
Ken Ray
kray at sonsothunder.com
Mon Oct 20 13:41:13 EDT 2008
> I want to put an image out of a folder into the wastebasket of macOS
> or win.
> How can I do it?
Here you go (this assumes Rev 2.9+). Note that oddly enough, Windows doesn't
return an error message if it can't execute the VBScript code properly, so
you'll have to check for the file's existence after you execute the code to
confirm it really is gone. Watch for line wraps:
on MoveToTrash pFile
-- Assumes pFile is full file path
if there is not a file pFile then
return "Error: File '" & pFile & "' does not exist."
end if
switch (the platform)
case "MacOS"
put "tell app `Finder`" & cr & \
"move POSIX file `" & pFile & "` to trash" & cr & \
"end tell" into tScript
replace "`" with quote in tScript
do tScript as "AppleScript"
if the result is "execution error" then return "Error: Could not
move file '" & pFile & "' to the Trash."
break
case "Win32"
replace "/" with "\" in pFile
put "Const RECYCLE_BIN = &Ha&" & cr & \
"Set objShell = CreateObject(`Shell.Application`)" & cr & \
"Set recycleFolder = objShell.NameSpace(RECYCLE_BIN)" & cr & \
"recycleFolder.MoveHere `" & pFile & "`" into tScript
replace "`" with quote in tScript
do tScript as "VBScript"
-- VBS doesn't return any error codes for this action, so need to
-- check file existence and return an error if necessary
if there is a file pFile then
return "Error: Could not move file '" & pFile & "' to the
Recycle Bin."
end if
break
end switch
end MoveToTrash
Ken Ray
Sons of Thunder Software, Inc.
Email: kray at sonsothunder.com
Web Site: http://www.sonsothunder.com/
More information about the use-livecode
mailing list