[Pythonmac-SIG] Sending files to the trash

has hengist.podd at virgin.net
Fri Mar 28 22:36:55 CET 2008

Alex MacCaw wrote:

> I'm making a cross platform script that sends files to the trash (or
> recycle bin), but am having trouble with the applescript version:
> Here's the applescript which I'm trying to generate:
>    tell application "Finder"
>      move path to the trash
>    end tell
> And the py-appscript version (which doesn't work):
>    app('Finder').move(os.path.abspath(path), to=k.trash)
> Can anyone give me any pointers on how to get the appscript version
> working?

Couple of things:

- The 'to' argument should be a reference, not a constant.

- Finder expects an HFS path string, alias object, or Finder  
reference. Python uses POSIX path strings.

Example solution:

from appscript import *
import mactypes

f = mactypes.Alias(os.path.abspath(path))
app('Finder').move(f, to=app.trash)

If you're new to appscript but familiar with AppleScript, ASTranslate  
can provide helpful hints when translating AppleScript commands to  
their appscript equivalents:



Control AppleScriptable applications from Python, Ruby and ObjC:

More information about the Pythonmac-SIG mailing list