1 """Utility routines depending on the finder,
2 a combination of code by Jack Jansen and erik@letterror.com.
4 Most events have been captured from
5 Lasso Capture AE and than translated to python code.
8 Note that the processes() function returns different values
9 depending on the OS version it is running on. On MacOS 9
10 the Finder returns the process *names* which can then be
11 used to find out more about them. On MacOS 8.6 and earlier
12 the Finder returns a code which does not seem to work.
13 So bottom line: the processes() stuff does not work on < MacOS9
15 Mostly written by erik@letterror.com
18 from Carbon
import AppleEvents
27 Error
= 'findertools.Error'
32 """returns basic (recyclable) Finder AE interface object"""
34 if not _finder_talker
:
35 _finder_talker
= Finder
.Finder()
36 _finder_talker
.send_flags
= ( _finder_talker
.send_flags |
37 AppleEvents
.kAECanInteract | AppleEvents
.kAECanSwitchLayer
)
41 """Open a file thru the finder. Specify file by name or fsspec"""
43 fss
= macfs
.FSSpec(file)
44 return finder
.open(fss
)
47 """Print a file thru the finder. Specify file by name or fsspec"""
49 fss
= macfs
.FSSpec(file)
50 return finder
._print
(fss
)
52 def copy(src
, dstdir
):
53 """Copy a file to a folder"""
55 if type(src
) == type([]):
58 src_fss
.append(macfs
.FSSpec(s
))
60 src_fss
= macfs
.FSSpec(src
)
61 dst_fss
= macfs
.FSSpec(dstdir
)
62 return finder
.duplicate(src_fss
, to
=dst_fss
)
64 def move(src
, dstdir
):
65 """Move a file to a folder"""
67 if type(src
) == type([]):
70 src_fss
.append(macfs
.FSSpec(s
))
72 src_fss
= macfs
.FSSpec(src
)
73 dst_fss
= macfs
.FSSpec(dstdir
)
74 return finder
.move(src_fss
, to
=dst_fss
)
77 """Put the mac to sleep"""
82 """Shut the mac down"""
92 #---------------------------------------------------
93 # Additional findertools
97 """Reveal a file in the finder. Specify file by name or fsspec."""
99 fss
= macfs
.FSSpec(file)
100 file_alias
= fss
.NewAlias()
101 return finder
.reveal(file_alias
)
104 """select a file in the finder. Specify file by name or fsspec."""
105 finder
= _getfinder()
106 fss
= macfs
.FSSpec(file)
107 file_alias
= fss
.NewAlias()
108 return finder
.select(file_alias
)
111 """Update the display of the specified object(s) to match
112 their on-disk representation. Specify file by name or fsspec."""
113 finder
= _getfinder()
114 fss
= macfs
.FSSpec(file)
115 file_alias
= fss
.NewAlias()
116 return finder
.update(file_alias
)
119 #---------------------------------------------------
123 def comment(object, comment
=None):
124 """comment: get or set the Finder-comment of the item, displayed in the –Get Info” window."""
125 object = macfs
.FSSpec(object)
126 fss
= macfs
.FSSpec(object)
127 object_alias
= fss
.NewAlias()
129 return _getcomment(object_alias
)
131 return _setcomment(object_alias
, comment
)
133 def _setcomment(object_alias
, comment
):
134 finder
= _getfinder()
137 aeobj_00
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('cobj'), form
="alis", seld
=object_alias
, fr
=None)
138 aeobj_01
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('prop'), form
="prop", seld
=aetypes
.Type('comt'), fr
=aeobj_00
)
139 args
['----'] = aeobj_01
140 args
["data"] = comment
141 _reply
, args
, attrs
= finder
.send("core", "setd", args
, attrs
)
142 if args
.has_key('errn'):
143 raise Error
, aetools
.decodeerror(args
)
144 if args
.has_key('----'):
147 def _getcomment(object_alias
):
148 finder
= _getfinder()
151 aeobj_00
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('cobj'), form
="alis", seld
=object_alias
, fr
=None)
152 aeobj_01
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('prop'), form
="prop", seld
=aetypes
.Type('comt'), fr
=aeobj_00
)
153 args
['----'] = aeobj_01
154 _reply
, args
, attrs
= finder
.send("core", "getd", args
, attrs
)
155 if args
.has_key('errn'):
156 raise Error
, aetools
.decodeerror(args
)
157 if args
.has_key('----'):
161 #---------------------------------------------------
162 # Get information about current processes in the Finder.
165 """processes returns a list of all active processes running on this computer and their creators."""
166 finder
= _getfinder()
174 ## get the processnames or else the processnumbers
175 args
['----'] = aetypes
.ObjectSpecifier(want
=aetypes
.Type('prcs'), form
="indx", seld
=aetypes
.Unknown('abso', "all "), fr
=None)
176 _reply
, args
, attrs
= finder
.send('core', 'getd', args
, attrs
)
177 if args
.has_key('errn'):
178 raise Error
, aetools
.decodeerror(args
)
180 if args
.has_key('----'):
183 if hasattr(proc
, 'seld'):
185 processnames
.append(proc
.seld
)
186 elif hasattr(proc
, 'type'):
187 if proc
.type == "psn ":
188 # it has a process number
189 processnumbers
.append(proc
.data
)
193 aeobj_0
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('prcs'), form
="indx", seld
=aetypes
.Unknown('abso', "all "), fr
=None)
194 args
['----'] = aetypes
.ObjectSpecifier(want
=aetypes
.Type('prop'), form
="prop", seld
=aetypes
.Type('fcrt'), fr
=aeobj_0
)
195 _reply
, args
, attrs
= finder
.send('core', 'getd', args
, attrs
)
196 if args
.has_key('errn'):
197 raise Error
, aetools
.decodeerror(_arg
)
198 if args
.has_key('----'):
201 ## concatenate in one dict
203 if len(processnames
) > len(processnumbers
):
206 data
= processnumbers
207 for i
in range(len(creators
)):
208 result
.append((data
[i
], creators
[i
]))
214 def isactiveprocess(processname
):
215 """Check of processname is active. MacOS9"""
223 def processinfo(processname
):
224 """Return an object with all process properties as attributes for processname. MacOS9"""
227 if processname
== "Finder":
231 p
.partition
= _processproperty(processname
, 'appt')
232 p
.used
= _processproperty(processname
, 'pusd')
233 p
.visible
= _processproperty(processname
, 'pvis') #Is the process' layer visible?
234 p
.frontmost
= _processproperty(processname
, 'pisf') #Is the process the frontmost process?
235 p
.file = _processproperty(processname
, 'file') #the file from which the process was launched
236 p
.filetype
= _processproperty(processname
, 'asty') #the OSType of the file type of the process
237 p
.creatortype
= _processproperty(processname
, 'fcrt') #the OSType of the creator of the process (the signature)
238 p
.accepthighlevel
= _processproperty(processname
, 'revt') #Is the process high-level event aware (accepts open application, open document, print document, and quit)?
239 p
.hasscripting
= _processproperty(processname
, 'hscr') #Does the process have a scripting terminology, i.e., can it be scripted?
242 def _processproperty(processname
, property):
243 """return the partition size and memory used for processname"""
244 finder
= _getfinder()
247 aeobj_00
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('prcs'), form
="name", seld
=processname
, fr
=None)
248 aeobj_01
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('prop'), form
="prop", seld
=aetypes
.Type(property), fr
=aeobj_00
)
249 args
['----'] = aeobj_01
250 _reply
, args
, attrs
= finder
.send("core", "getd", args
, attrs
)
251 if args
.has_key('errn'):
252 raise Error
, aetools
.decodeerror(args
)
253 if args
.has_key('----'):
257 #---------------------------------------------------
258 # Mess around with Finder windows.
260 def openwindow(object):
261 """Open a Finder window for object, Specify object by name or fsspec."""
262 finder
= _getfinder()
263 object = macfs
.FSSpec(object)
264 fss
= macfs
.FSSpec(object)
265 object_alias
= fss
.NewAlias()
270 aeobj_0
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('cfol'), form
="alis", seld
=object_alias
, fr
=None)
271 args
['----'] = aeobj_0
272 _reply
, args
, attrs
= finder
.send(_code
, _subcode
, args
, attrs
)
273 if args
.has_key('errn'):
274 raise Error
, aetools
.decodeerror(args
)
276 def closewindow(object):
277 """Close a Finder window for folder, Specify by path."""
278 finder
= _getfinder()
279 fss
= macfs
.FSSpec(object)
280 object_alias
= fss
.NewAlias()
285 aeobj_0
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('cfol'), form
="alis", seld
=object_alias
, fr
=None)
286 args
['----'] = aeobj_0
287 _reply
, args
, attrs
= finder
.send(_code
, _subcode
, args
, attrs
)
288 if args
.has_key('errn'):
289 raise Error
, aetools
.decodeerror(args
)
291 def location(object, pos
=None):
292 """Set the position of a Finder window for folder to pos=(w, h). Specify file by name or fsspec.
293 If pos=None, location will return the current position of the object."""
294 fss
= macfs
.FSSpec(object)
295 object_alias
= fss
.NewAlias()
297 return _getlocation(object_alias
)
298 return _setlocation(object_alias
, pos
)
300 def _setlocation(object_alias
, (x
, y
)):
301 """_setlocation: Set the location of the icon for the object."""
302 finder
= _getfinder()
305 aeobj_00
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('cfol'), form
="alis", seld
=object_alias
, fr
=None)
306 aeobj_01
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('prop'), form
="prop", seld
=aetypes
.Type('posn'), fr
=aeobj_00
)
307 args
['----'] = aeobj_01
308 args
["data"] = [x
, y
]
309 _reply
, args
, attrs
= finder
.send("core", "setd", args
, attrs
)
310 if args
.has_key('errn'):
311 raise Error
, aetools
.decodeerror(args
)
314 def _getlocation(object_alias
):
315 """_getlocation: get the location of the icon for the object."""
316 finder
= _getfinder()
319 aeobj_00
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('cfol'), form
="alis", seld
=object_alias
, fr
=None)
320 aeobj_01
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('prop'), form
="prop", seld
=aetypes
.Type('posn'), fr
=aeobj_00
)
321 args
['----'] = aeobj_01
322 _reply
, args
, attrs
= finder
.send("core", "getd", args
, attrs
)
323 if args
.has_key('errn'):
324 raise Error
, aetools
.decodeerror(args
)
325 if args
.has_key('----'):
329 def label(object, index
=None):
330 """label: set or get the label of the item. Specify file by name or fsspec."""
331 fss
= macfs
.FSSpec(object)
332 object_alias
= fss
.NewAlias()
334 return _getlabel(object_alias
)
335 if index
< 0 or index
> 7:
337 return _setlabel(object_alias
, index
)
339 def _getlabel(object_alias
):
340 """label: Get the label for the object."""
341 finder
= _getfinder()
344 aeobj_00
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('cobj'), form
="alis", seld
=object_alias
, fr
=None)
345 aeobj_01
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('prop'), form
="prop", seld
=aetypes
.Type('labi'), fr
=aeobj_00
)
346 args
['----'] = aeobj_01
347 _reply
, args
, attrs
= finder
.send("core", "getd", args
, attrs
)
348 if args
.has_key('errn'):
349 raise Error
, aetools
.decodeerror(args
)
350 if args
.has_key('----'):
353 def _setlabel(object_alias
, index
):
354 """label: Set the label for the object."""
355 finder
= _getfinder()
360 aeobj_0
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('prop'),
361 form
="alis", seld
=object_alias
, fr
=None)
362 aeobj_1
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('prop'),
363 form
="prop", seld
=aetypes
.Type('labi'), fr
=aeobj_0
)
364 args
['----'] = aeobj_1
366 _reply
, args
, attrs
= finder
.send(_code
, _subcode
, args
, attrs
)
367 if args
.has_key('errn'):
368 raise Error
, aetools
.decodeerror(args
)
371 def windowview(folder
, view
=None):
372 """windowview: Set the view of the window for the folder. Specify file by name or fsspec.
373 0 = by icon (default)
377 fss
= macfs
.FSSpec(folder
)
378 folder_alias
= fss
.NewAlias()
380 return _getwindowview(folder_alias
)
381 return _setwindowview(folder_alias
, view
)
383 def _setwindowview(folder_alias
, view
=0):
384 """set the windowview"""
388 _v
= aetypes
.Type('pnam')
390 _v
= aetypes
.Type('lgbu')
392 _v
= aetypes
.Type('iimg')
393 finder
= _getfinder()
394 aeobj_0
= aetypes
.ObjectSpecifier(want
= aetypes
.Type('cfol'),
395 form
= 'alis', seld
= folder_alias
, fr
=None)
396 aeobj_1
= aetypes
.ObjectSpecifier(want
= aetypes
.Type('prop'),
397 form
= 'prop', seld
= aetypes
.Type('cwnd'), fr
=aeobj_0
)
398 aeobj_2
= aetypes
.ObjectSpecifier(want
= aetypes
.Type('prop'),
399 form
= 'prop', seld
= aetypes
.Type('pvew'), fr
=aeobj_1
)
400 aeobj_3
= aetypes
.ObjectSpecifier(want
= aetypes
.Type('prop'),
401 form
= 'prop', seld
= _v
, fr
=None)
404 args
['----'] = aeobj_2
405 args
['data'] = aeobj_3
406 _reply
, args
, attrs
= finder
.send(_code
, _subcode
, args
, attrs
)
407 if args
.has_key('errn'):
408 raise Error
, aetools
.decodeerror(args
)
409 if args
.has_key('----'):
412 def _getwindowview(folder_alias
):
413 """get the windowview"""
416 finder
= _getfinder()
419 aeobj_00
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('cfol'), form
="alis", seld
=folder_alias
, fr
=None)
420 aeobj_01
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('prop'), form
="prop", seld
=aetypes
.Type('cwnd'), fr
=aeobj_00
)
421 aeobj_02
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('prop'), form
="prop", seld
=aetypes
.Type('pvew'), fr
=aeobj_01
)
422 args
['----'] = aeobj_02
423 _reply
, args
, attrs
= finder
.send("core", "getd", args
, attrs
)
424 if args
.has_key('errn'):
425 raise Error
, aetools
.decodeerror(args
)
426 views
= {'iimg':0, 'pnam':1, 'lgbu':2}
427 if args
.has_key('----'):
428 return views
[args
['----'].enum
]
430 def windowsize(folder
, size
=None):
431 """Set the size of a Finder window for folder to size=(w, h), Specify by path.
432 If size=None, windowsize will return the current size of the window.
433 Specify file by name or fsspec.
435 fss
= macfs
.FSSpec(folder
)
436 folder_alias
= fss
.NewAlias()
439 return _getwindowsize(folder_alias
)
440 return _setwindowsize(folder_alias
, size
)
442 def _setwindowsize(folder_alias
, (w
, h
)):
443 """Set the size of a Finder window for folder to (w, h)"""
444 finder
= _getfinder()
450 aeobj_0
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('cfol'),
451 form
="alis", seld
=folder_alias
, fr
=None)
452 aeobj_1
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('prop'),
453 form
="prop", seld
=aetypes
.Type('cwnd'), fr
=aeobj_0
)
454 aeobj_2
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('prop'),
455 form
="prop", seld
=aetypes
.Type('ptsz'), fr
=aeobj_1
)
456 args
['----'] = aeobj_2
457 args
["data"] = aevar00
458 _reply
, args
, attrs
= finder
.send(_code
, _subcode
, args
, attrs
)
459 if args
.has_key('errn'):
460 raise Error
, aetools
.decodeerror(args
)
463 def _getwindowsize(folder_alias
):
464 """Set the size of a Finder window for folder to (w, h)"""
465 finder
= _getfinder()
468 aeobj_0
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('cfol'),
469 form
="alis", seld
=folder_alias
, fr
=None)
470 aeobj_1
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('prop'),
471 form
="prop", seld
=aetypes
.Type('cwnd'), fr
=aeobj_0
)
472 aeobj_2
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('prop'),
473 form
="prop", seld
=aetypes
.Type('posn'), fr
=aeobj_1
)
474 args
['----'] = aeobj_2
475 _reply
, args
, attrs
= finder
.send('core', 'getd', args
, attrs
)
476 if args
.has_key('errn'):
477 raise Error
, aetools
.decodeerror(args
)
478 if args
.has_key('----'):
481 def windowposition(folder
, pos
=None):
482 """Set the position of a Finder window for folder to pos=(w, h)."""
483 fss
= macfs
.FSSpec(folder
)
484 folder_alias
= fss
.NewAlias()
487 return _getwindowposition(folder_alias
)
488 if type(pos
) == InstanceType
:
489 # pos might be a QDPoint object as returned by _getwindowposition
491 return _setwindowposition(folder_alias
, pos
)
493 def _setwindowposition(folder_alias
, (x
, y
)):
494 """Set the size of a Finder window for folder to (w, h)."""
495 finder
= _getfinder()
498 aeobj_0
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('cfol'),
499 form
="alis", seld
=folder_alias
, fr
=None)
500 aeobj_1
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('prop'),
501 form
="prop", seld
=aetypes
.Type('cwnd'), fr
=aeobj_0
)
502 aeobj_2
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('prop'),
503 form
="prop", seld
=aetypes
.Type('posn'), fr
=aeobj_1
)
504 args
['----'] = aeobj_2
505 args
["data"] = [x
, y
]
506 _reply
, args
, attrs
= finder
.send('core', 'setd', args
, attrs
)
507 if args
.has_key('errn'):
508 raise Error
, aetools
.decodeerror(args
)
509 if args
.has_key('----'):
512 def _getwindowposition(folder_alias
):
513 """Get the size of a Finder window for folder, Specify by path."""
514 finder
= _getfinder()
517 aeobj_0
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('cfol'),
518 form
="alis", seld
=folder_alias
, fr
=None)
519 aeobj_1
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('prop'),
520 form
="prop", seld
=aetypes
.Type('cwnd'), fr
=aeobj_0
)
521 aeobj_2
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('prop'),
522 form
="prop", seld
=aetypes
.Type('ptsz'), fr
=aeobj_1
)
523 args
['----'] = aeobj_2
524 _reply
, args
, attrs
= finder
.send('core', 'getd', args
, attrs
)
525 if args
.has_key('errn'):
526 raise Error
, aetools
.decodeerror(args
)
527 if args
.has_key('----'):
530 def icon(object, icondata
=None):
531 """icon sets the icon of object, if no icondata is given,
532 icon will return an AE object with binary data for the current icon.
533 If left untouched, this data can be used to paste the icon on another file.
534 Development opportunity: get and set the data as PICT."""
535 fss
= macfs
.FSSpec(object)
536 object_alias
= fss
.NewAlias()
538 return _geticon(object_alias
)
539 return _seticon(object_alias
, icondata
)
541 def _geticon(object_alias
):
542 """get the icondata for object. Binary data of some sort."""
543 finder
= _getfinder()
546 aeobj_00
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('cobj'),
547 form
="alis", seld
=object_alias
, fr
=None)
548 aeobj_01
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('prop'),
549 form
="prop", seld
=aetypes
.Type('iimg'), fr
=aeobj_00
)
550 args
['----'] = aeobj_01
551 _reply
, args
, attrs
= finder
.send("core", "getd", args
, attrs
)
552 if args
.has_key('errn'):
553 raise Error
, aetools
.decodeerror(args
)
554 if args
.has_key('----'):
557 def _seticon(object_alias
, icondata
):
558 """set the icondata for object, formatted as produced by _geticon()"""
559 finder
= _getfinder()
562 aeobj_00
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('cobj'),
563 form
="alis", seld
=object_alias
, fr
=None)
564 aeobj_01
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('prop'),
565 form
="prop", seld
=aetypes
.Type('iimg'), fr
=aeobj_00
)
566 args
['----'] = aeobj_01
567 args
["data"] = icondata
568 _reply
, args
, attrs
= finder
.send("core", "setd", args
, attrs
)
569 if args
.has_key('errn'):
570 raise Error
, aetools
.decodeerror(args
)
571 if args
.has_key('----'):
572 return args
['----'].data
575 #---------------------------------------------------
576 # Volumes and servers.
578 def mountvolume(volume
, server
=None, username
=None, password
=None):
579 """mount a volume, local or on a server on AppleTalk.
580 Note: mounting a ASIP server requires a different operation.
581 server is the name of the server where the volume belongs
582 username, password belong to a registered user of the volume."""
583 finder
= _getfinder()
587 args
["PASS"] = password
589 args
["USER"] = username
591 args
["SRVR"] = server
592 args
['----'] = volume
593 _reply
, args
, attrs
= finder
.send("aevt", "mvol", args
, attrs
)
594 if args
.has_key('errn'):
595 raise Error
, aetools
.decodeerror(args
)
596 if args
.has_key('----'):
599 def unmountvolume(volume
):
600 """unmount a volume that's on the desktop"""
604 """puth the object away, whereever it came from."""
605 finder
= _getfinder()
608 args
['----'] = aetypes
.ObjectSpecifier(want
=aetypes
.Type('cdis'), form
="name", seld
=object, fr
=None)
609 _reply
, args
, attrs
= talker
.send("fndr", "ptwy", args
, attrs
)
610 if args
.has_key('errn'):
611 raise Error
, aetools
.decodeerror(args
)
612 if args
.has_key('----'):
616 #---------------------------------------------------
617 # Miscellaneous functions
620 def volumelevel(level
):
621 """set the audio output level, parameter between 0 (silent) and 7 (full blast)"""
622 finder
= _getfinder()
630 _reply
, args
, attrs
= finder
.send("aevt", "stvl", args
, attrs
)
631 if args
.has_key('errn'):
632 raise Error
, aetools
.decodeerror(args
)
633 if args
.has_key('----'):
637 """return the version of the system software"""
638 finder
= _getfinder()
641 aeobj_00
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('prop'), form
="prop", seld
=aetypes
.Type('ver2'), fr
=None)
642 args
['----'] = aeobj_00
643 _reply
, args
, attrs
= finder
.send("core", "getd", args
, attrs
)
644 if args
.has_key('errn'):
645 raise Error
, aetools
.decodeerror(args
)
646 if args
.has_key('----'):
650 """return the current status of filesharing and whether it is starting up or not:
651 -1 file sharing is off and not starting up
652 0 file sharing is off and starting up
653 1 file sharing is on"""
655 finder
= _getfinder()
659 args
['----'] = aetypes
.ObjectSpecifier(want
=aetypes
.Type('prop'), form
="prop", seld
=aetypes
.Type('fshr'), fr
=None)
660 _reply
, args
, attrs
= finder
.send("core", "getd", args
, attrs
)
661 if args
.has_key('errn'):
662 raise Error
, aetools
.decodeerror(args
)
663 if args
.has_key('----'):
664 if args
['----'] == 0:
668 # is it starting up perchance?
671 args
['----'] = aetypes
.ObjectSpecifier(want
=aetypes
.Type('prop'), form
="prop", seld
=aetypes
.Type('fsup'), fr
=None)
672 _reply
, args
, attrs
= finder
.send("core", "getd", args
, attrs
)
673 if args
.has_key('errn'):
674 raise Error
, aetools
.decodeerror(args
)
675 if args
.has_key('----'):
676 if args
['----'] == 1:
680 def movetotrash(path
):
681 """move the object to the trash"""
682 fss
= macfs
.FSSpec(path
)
683 trashfolder
= macfs
.FSSpec(macfs
.FindFolder(fss
.as_tuple()[0], 'trsh', 0) + ("",)).as_pathname()
684 move(path
, trashfolder
)
687 """empty the trash"""
688 finder
= _getfinder()
691 args
['----'] = aetypes
.ObjectSpecifier(want
=aetypes
.Type('prop'), form
="prop", seld
=aetypes
.Type('trsh'), fr
=None)
692 _reply
, args
, attrs
= finder
.send("fndr", "empt", args
, attrs
)
693 if args
.has_key('errn'):
694 raise aetools
.Error
, aetools
.decodeerror(args
)
698 print 'Original findertools functionality test...'
699 print 'Testing launch...'
700 fss
, ok
= macfs
.PromptGetFile('File to launch:')
704 print 'Result: ', result
705 print 'Press return-',
707 print 'Testing print...'
708 fss
, ok
= macfs
.PromptGetFile('File to print:')
712 print 'Result: ', result
713 print 'Press return-',
715 print 'Testing copy...'
716 fss
, ok
= macfs
.PromptGetFile('File to copy:')
718 dfss
, ok
= macfs
.GetDirectory()
720 result
= copy(fss
, dfss
)
722 print 'Result:', result
723 print 'Press return-',
725 print 'Testing move...'
726 fss
, ok
= macfs
.PromptGetFile('File to move:')
728 dfss
, ok
= macfs
.GetDirectory()
730 result
= move(fss
, dfss
)
732 print 'Result:', result
733 print 'Press return-',
736 print 'Testing sleep...'
737 if EasyDialogs
.AskYesNoCancel('Sleep?') > 0:
740 print 'Result:', result
741 print 'Press return-',
743 print 'Testing shutdown...'
744 if EasyDialogs
.AskYesNoCancel('Shut down?') > 0:
747 print 'Result:', result
748 print 'Press return-',
750 print 'Testing restart...'
751 if EasyDialogs
.AskYesNoCancel('Restart?') > 0:
754 print 'Result:', result
755 print 'Press return-',
759 print '\nmorefindertools version %s\nTests coming upƒ' %__version__
764 print '\tfilesharing on?', filesharing() # is file sharing on, off, starting up?
765 print '\tOS version', OSversion() # the version of the system software
767 # set the soundvolume in a simple way
768 print '\tSystem beep volume'
769 for i
in range(0, 7):
773 # Finder's windows, file location, file attributes
774 open("@findertoolstest", "w")
775 f
= macfs
.FSSpec("@findertoolstest").as_pathname()
776 reveal(f
) # reveal this file in a Finder window
777 select(f
) # select this file
779 base
, file = os
.path
.split(f
)
780 closewindow(base
) # close the window this file is in (opened by reveal)
781 openwindow(base
) # open it again
782 windowview(base
, 1) # set the view by list
784 label(f
, 2) # set the label of this file to something orange
785 print '\tlabel', label(f
) # get the label of this file
787 # the file location only works in a window with icon view!
788 print 'Random locations for an icon'
789 windowview(base
, 0) # set the view by icon
790 windowsize(base
, (600, 600))
792 location(f
, (random
.randint(10, 590), random
.randint(10, 590)))
794 windowsize(base
, (200, 400))
795 windowview(base
, 1) # set the view by icon
797 orgpos
= windowposition(base
)
798 print 'Animated window location'
800 pos
= (100+i
*10, 100+i
*10)
801 windowposition(base
, pos
)
802 print '\twindow position', pos
803 windowposition(base
, orgpos
) # park it where it was beforeƒ
805 print 'Put a comment in file', f
, ':'
806 print '\t', comment(f
) # print the Finder comment this file has
807 s
= 'This is a comment no one reads!'
808 comment(f
, s
) # set the Finder comment
811 print 'MacOS9 or better specific functions'
813 pr
= processes() # return a list of tuples with (active_processname, creatorcode)
814 print 'Return a list of current active processes:'
818 # get attributes of the first process in the list
819 print 'Attributes of the first process in the list:'
820 pinfo
= processinfo(pr
[0][0])
822 print '\t\tmemory partition', pinfo
.partition
# the memory allocated to this process
823 print '\t\tmemory used', pinfo
.used
# the memory actuall used by this process
824 print '\t\tis visible', pinfo
.visible
# is the process visible to the user
825 print '\t\tis frontmost', pinfo
.frontmost
# is the process the front most one?
826 print '\t\thas scripting', pinfo
.hasscripting
# is the process scriptable?
827 print '\t\taccepts high level events', pinfo
.accepthighlevel
# does the process accept high level appleevents?
829 if __name__
== '__main__':