drag and drop filters

John W. Baxter jwbaxter at olympus.net
Sat Sep 4 14:21:26 EDT 1999


In article <jwbaxter-0409991113060001 at otter.olympus.net>,
jwbaxter at olympus.net (John W. Baxter) wrote:

> In article <nospamkjray-0409991050070001 at ali-ca77-112.ix.netcom.com>,
> nospamkjray at ix.netcom.com.nospam.org (C. Keith Ray) wrote:
> 
> > Is is possible to use Python on the Mac to create an "applet" that, when
> > you drop files or folders on its icon in the Finder, opens and processes
> > those files or folders.
> > 
> > In applescript you'd create save the following as "an application":
> > 
> > on open theSelectedItems
> >         repeat with thisItem in theSelectedItems
> >           -- process thisItem
> >         end repeat
> > end open
> > 
> > What would the equivalent be with Python on MacOS?
> Write Python-like code (what you would write on Unix).  If you just want
> to read the contents of the dropped file(s) you can use the fileinput
> module as usual.  If you want to do something else with the dropped files,
> you can index across sys.argv[1:] in the usual Python idiom.
> 
> 
> > 
> > Has anyone hooked Python into MacOS Open Scripting Architecture?
> 
> Maybe...I haven't cared (speaking as a longtime Frontier user, AppleScript
> user, and [Mac]Perl user).
> 
>   --John

OK, so I forgot a wee detail, and the news server I use has broken cancel
for the moment.

After writing the script as described (or hinted) above, drop the text
onto the "BuildApplet" applet which comes with Mac Python.  Out comes a
Mac application onto which you can drop one or more files or folders. 
Don't count on the order in which the files are found in sys.argv...it's
deterministic, but bizarre.

  --John

-- 
John W. Baxter   Port Ludlow, WA USA  jwb at olympus.net




More information about the Python-list mailing list