Okay, so I’m developing an application that will allow users to select file objects in a menu and will allow them to copy said selections to another location. I have so far managed to use the pywin32 module to allow me to copy files using Windows’ native file copier.
The code for it:
from win32com.shell import shell, shellcon
srcstr = chr( 0 ).join( [ file[0] for file in files ] )
deststr = chr( 0 ).join( [ file[1] for file in files ] )
shell.SHFileOperation(
( 0, shellcon.FO_COPY, srcstr, deststr, shellcon.FOF_MULTIDESTFILES, None, None )
)
This is a fine method for copying under Windows, but I was wondering if there is a way to accomplish the same goal under Mac and/or Linux.
On Mac, you’ll need to script Finder.
One way to do this is with ScriptingBridge. To start with:
Then… well, fire up AppleScript Editor, look at Finder’s Dictionary, and figure out how to translate that from AppleScript into Python+ScriptingBridge, and if you have any problems, come back and ask again. But here are some hints:
The trick is to get from a path to a Finder reference. And there’s no easy way to get there directly. Instead, you have to start with startupDisk, call folders() on it, filter for name == the first component of path, and repeat. See http://developer.apple.com/library/mac/#samplecode/ScriptingBridgeFinder/Listings/Controller_m.html (which is written in Objective C, not Python, but the ScriptingBridge parts are pretty easy to translate).