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
28 Error
= 'findertools.Error'
33 """returns basic (recyclable) Finder AE interface object"""
35 if not _finder_talker
:
36 _finder_talker
= Finder
.Finder()
37 _finder_talker
.send_flags
= ( _finder_talker
.send_flags |
38 AppleEvents
.kAECanInteract | AppleEvents
.kAECanSwitchLayer
)
42 """Open a file thru the finder. Specify file by name or fsspec"""
44 fss
= Carbon
.File
.FSSpec(file)
45 return finder
.open(fss
)
48 """Print a file thru the finder. Specify file by name or fsspec"""
50 fss
= Carbon
.File
.FSSpec(file)
51 return finder
._print
(fss
)
53 def copy(src
, dstdir
):
54 """Copy a file to a folder"""
56 if type(src
) == type([]):
59 src_fss
.append(Carbon
.File
.FSSpec(s
))
61 src_fss
= Carbon
.File
.FSSpec(src
)
62 dst_fss
= Carbon
.File
.FSSpec(dstdir
)
63 return finder
.duplicate(src_fss
, to
=dst_fss
)
65 def move(src
, dstdir
):
66 """Move a file to a folder"""
68 if type(src
) == type([]):
71 src_fss
.append(Carbon
.File
.FSSpec(s
))
73 src_fss
= Carbon
.File
.FSSpec(src
)
74 dst_fss
= Carbon
.File
.FSSpec(dstdir
)
75 return finder
.move(src_fss
, to
=dst_fss
)
78 """Put the mac to sleep"""
83 """Shut the mac down"""
93 #---------------------------------------------------
94 # Additional findertools
98 """Reveal a file in the finder. Specify file by name, fsref or fsspec."""
100 fsr
= Carbon
.File
.FSRef(file)
101 file_alias
= fsr
.FSNewAliasMinimal()
102 return finder
.reveal(file_alias
)
105 """select a file in the finder. Specify file by name, fsref or fsspec."""
106 finder
= _getfinder()
107 fsr
= Carbon
.File
.FSRef(file)
108 file_alias
= fsr
.FSNewAliasMinimal()
109 return finder
.select(file_alias
)
112 """Update the display of the specified object(s) to match
113 their on-disk representation. Specify file by name, fsref or fsspec."""
114 finder
= _getfinder()
115 fsr
= Carbon
.File
.FSRef(file)
116 file_alias
= fsr
.FSNewAliasMinimal()
117 return finder
.update(file_alias
)
120 #---------------------------------------------------
124 def comment(object, comment
=None):
125 """comment: get or set the Finder-comment of the item, displayed in the 'Get Info' window."""
126 object = Carbon
.File
.FSRef(object)
127 object_alias
= object.FSNewAliasMonimal()
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 = Carbon
.File
.FSRef(object)
264 object_alias
= object.FSNewAliasMinimal()
269 aeobj_0
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('cfol'), form
="alis", seld
=object_alias
, fr
=None)
270 args
['----'] = aeobj_0
271 _reply
, args
, attrs
= finder
.send(_code
, _subcode
, args
, attrs
)
272 if args
.has_key('errn'):
273 raise Error
, aetools
.decodeerror(args
)
275 def closewindow(object):
276 """Close a Finder window for folder, Specify by path."""
277 finder
= _getfinder()
278 object = Carbon
.File
.FSRef(object)
279 object_alias
= object.FSNewAliasMinimal()
284 aeobj_0
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('cfol'), form
="alis", seld
=object_alias
, fr
=None)
285 args
['----'] = aeobj_0
286 _reply
, args
, attrs
= finder
.send(_code
, _subcode
, args
, attrs
)
287 if args
.has_key('errn'):
288 raise Error
, aetools
.decodeerror(args
)
290 def location(object, pos
=None):
291 """Set the position of a Finder window for folder to pos=(w, h). Specify file by name or fsspec.
292 If pos=None, location will return the current position of the object."""
293 object = Carbon
.File
.FSRef(object)
294 object_alias
= object.FSNewAliasMinimal()
296 return _getlocation(object_alias
)
297 return _setlocation(object_alias
, pos
)
299 def _setlocation(object_alias
, (x
, y
)):
300 """_setlocation: Set the location of the icon for the object."""
301 finder
= _getfinder()
304 aeobj_00
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('cfol'), form
="alis", seld
=object_alias
, fr
=None)
305 aeobj_01
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('prop'), form
="prop", seld
=aetypes
.Type('posn'), fr
=aeobj_00
)
306 args
['----'] = aeobj_01
307 args
["data"] = [x
, y
]
308 _reply
, args
, attrs
= finder
.send("core", "setd", args
, attrs
)
309 if args
.has_key('errn'):
310 raise Error
, aetools
.decodeerror(args
)
313 def _getlocation(object_alias
):
314 """_getlocation: get the location of the icon for the object."""
315 finder
= _getfinder()
318 aeobj_00
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('cfol'), form
="alis", seld
=object_alias
, fr
=None)
319 aeobj_01
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('prop'), form
="prop", seld
=aetypes
.Type('posn'), fr
=aeobj_00
)
320 args
['----'] = aeobj_01
321 _reply
, args
, attrs
= finder
.send("core", "getd", args
, attrs
)
322 if args
.has_key('errn'):
323 raise Error
, aetools
.decodeerror(args
)
324 if args
.has_key('----'):
328 def label(object, index
=None):
329 """label: set or get the label of the item. Specify file by name or fsspec."""
330 object = Carbon
.File
.FSRef(object)
331 object_alias
= object.FSNewAliasMinimal()
333 return _getlabel(object_alias
)
334 if index
< 0 or index
> 7:
336 return _setlabel(object_alias
, index
)
338 def _getlabel(object_alias
):
339 """label: Get the label for the object."""
340 finder
= _getfinder()
343 aeobj_00
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('cobj'), form
="alis", seld
=object_alias
, fr
=None)
344 aeobj_01
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('prop'), form
="prop", seld
=aetypes
.Type('labi'), fr
=aeobj_00
)
345 args
['----'] = aeobj_01
346 _reply
, args
, attrs
= finder
.send("core", "getd", args
, attrs
)
347 if args
.has_key('errn'):
348 raise Error
, aetools
.decodeerror(args
)
349 if args
.has_key('----'):
352 def _setlabel(object_alias
, index
):
353 """label: Set the label for the object."""
354 finder
= _getfinder()
359 aeobj_0
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('prop'),
360 form
="alis", seld
=object_alias
, fr
=None)
361 aeobj_1
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('prop'),
362 form
="prop", seld
=aetypes
.Type('labi'), fr
=aeobj_0
)
363 args
['----'] = aeobj_1
365 _reply
, args
, attrs
= finder
.send(_code
, _subcode
, args
, attrs
)
366 if args
.has_key('errn'):
367 raise Error
, aetools
.decodeerror(args
)
370 def windowview(folder
, view
=None):
371 """windowview: Set the view of the window for the folder. Specify file by name or fsspec.
372 0 = by icon (default)
376 fsr
= Carbon
.File
.FSRef(folder
)
377 folder_alias
= fsr
.FSNewAliasMinimal()
379 return _getwindowview(folder_alias
)
380 return _setwindowview(folder_alias
, view
)
382 def _setwindowview(folder_alias
, view
=0):
383 """set the windowview"""
387 _v
= aetypes
.Type('pnam')
389 _v
= aetypes
.Type('lgbu')
391 _v
= aetypes
.Type('iimg')
392 finder
= _getfinder()
393 aeobj_0
= aetypes
.ObjectSpecifier(want
= aetypes
.Type('cfol'),
394 form
= 'alis', seld
= folder_alias
, fr
=None)
395 aeobj_1
= aetypes
.ObjectSpecifier(want
= aetypes
.Type('prop'),
396 form
= 'prop', seld
= aetypes
.Type('cwnd'), fr
=aeobj_0
)
397 aeobj_2
= aetypes
.ObjectSpecifier(want
= aetypes
.Type('prop'),
398 form
= 'prop', seld
= aetypes
.Type('pvew'), fr
=aeobj_1
)
399 aeobj_3
= aetypes
.ObjectSpecifier(want
= aetypes
.Type('prop'),
400 form
= 'prop', seld
= _v
, fr
=None)
403 args
['----'] = aeobj_2
404 args
['data'] = aeobj_3
405 _reply
, args
, attrs
= finder
.send(_code
, _subcode
, args
, attrs
)
406 if args
.has_key('errn'):
407 raise Error
, aetools
.decodeerror(args
)
408 if args
.has_key('----'):
411 def _getwindowview(folder_alias
):
412 """get the windowview"""
415 finder
= _getfinder()
418 aeobj_00
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('cfol'), form
="alis", seld
=folder_alias
, fr
=None)
419 aeobj_01
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('prop'), form
="prop", seld
=aetypes
.Type('cwnd'), fr
=aeobj_00
)
420 aeobj_02
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('prop'), form
="prop", seld
=aetypes
.Type('pvew'), fr
=aeobj_01
)
421 args
['----'] = aeobj_02
422 _reply
, args
, attrs
= finder
.send("core", "getd", args
, attrs
)
423 if args
.has_key('errn'):
424 raise Error
, aetools
.decodeerror(args
)
425 views
= {'iimg':0, 'pnam':1, 'lgbu':2}
426 if args
.has_key('----'):
427 return views
[args
['----'].enum
]
429 def windowsize(folder
, size
=None):
430 """Set the size of a Finder window for folder to size=(w, h), Specify by path.
431 If size=None, windowsize will return the current size of the window.
432 Specify file by name or fsspec.
434 fsr
= Carbon
.File
.FSRef(folder
)
435 folder_alias
= fsr
.FSNewAliasMinimal()
438 return _getwindowsize(folder_alias
)
439 return _setwindowsize(folder_alias
, size
)
441 def _setwindowsize(folder_alias
, (w
, h
)):
442 """Set the size of a Finder window for folder to (w, h)"""
443 finder
= _getfinder()
449 aeobj_0
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('cfol'),
450 form
="alis", seld
=folder_alias
, fr
=None)
451 aeobj_1
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('prop'),
452 form
="prop", seld
=aetypes
.Type('cwnd'), fr
=aeobj_0
)
453 aeobj_2
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('prop'),
454 form
="prop", seld
=aetypes
.Type('ptsz'), fr
=aeobj_1
)
455 args
['----'] = aeobj_2
456 args
["data"] = aevar00
457 _reply
, args
, attrs
= finder
.send(_code
, _subcode
, args
, attrs
)
458 if args
.has_key('errn'):
459 raise Error
, aetools
.decodeerror(args
)
462 def _getwindowsize(folder_alias
):
463 """Set the size of a Finder window for folder to (w, h)"""
464 finder
= _getfinder()
467 aeobj_0
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('cfol'),
468 form
="alis", seld
=folder_alias
, fr
=None)
469 aeobj_1
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('prop'),
470 form
="prop", seld
=aetypes
.Type('cwnd'), fr
=aeobj_0
)
471 aeobj_2
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('prop'),
472 form
="prop", seld
=aetypes
.Type('posn'), fr
=aeobj_1
)
473 args
['----'] = aeobj_2
474 _reply
, args
, attrs
= finder
.send('core', 'getd', args
, attrs
)
475 if args
.has_key('errn'):
476 raise Error
, aetools
.decodeerror(args
)
477 if args
.has_key('----'):
480 def windowposition(folder
, pos
=None):
481 """Set the position of a Finder window for folder to pos=(w, h)."""
482 fsr
= Carbon
.File
.FSRef(folder
)
483 folder_alias
= fsr
.FSNewAliasMinimal()
486 return _getwindowposition(folder_alias
)
487 if type(pos
) == InstanceType
:
488 # pos might be a QDPoint object as returned by _getwindowposition
490 return _setwindowposition(folder_alias
, pos
)
492 def _setwindowposition(folder_alias
, (x
, y
)):
493 """Set the size of a Finder window for folder to (w, h)."""
494 finder
= _getfinder()
497 aeobj_0
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('cfol'),
498 form
="alis", seld
=folder_alias
, fr
=None)
499 aeobj_1
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('prop'),
500 form
="prop", seld
=aetypes
.Type('cwnd'), fr
=aeobj_0
)
501 aeobj_2
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('prop'),
502 form
="prop", seld
=aetypes
.Type('posn'), fr
=aeobj_1
)
503 args
['----'] = aeobj_2
504 args
["data"] = [x
, y
]
505 _reply
, args
, attrs
= finder
.send('core', 'setd', args
, attrs
)
506 if args
.has_key('errn'):
507 raise Error
, aetools
.decodeerror(args
)
508 if args
.has_key('----'):
511 def _getwindowposition(folder_alias
):
512 """Get the size of a Finder window for folder, Specify by path."""
513 finder
= _getfinder()
516 aeobj_0
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('cfol'),
517 form
="alis", seld
=folder_alias
, fr
=None)
518 aeobj_1
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('prop'),
519 form
="prop", seld
=aetypes
.Type('cwnd'), fr
=aeobj_0
)
520 aeobj_2
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('prop'),
521 form
="prop", seld
=aetypes
.Type('ptsz'), fr
=aeobj_1
)
522 args
['----'] = aeobj_2
523 _reply
, args
, attrs
= finder
.send('core', 'getd', args
, attrs
)
524 if args
.has_key('errn'):
525 raise Error
, aetools
.decodeerror(args
)
526 if args
.has_key('----'):
529 def icon(object, icondata
=None):
530 """icon sets the icon of object, if no icondata is given,
531 icon will return an AE object with binary data for the current icon.
532 If left untouched, this data can be used to paste the icon on another file.
533 Development opportunity: get and set the data as PICT."""
534 fsr
= Carbon
.File
.FSRef(object)
535 object_alias
= fsr
.FSNewAliasMinimal()
537 return _geticon(object_alias
)
538 return _seticon(object_alias
, icondata
)
540 def _geticon(object_alias
):
541 """get the icondata for object. Binary data of some sort."""
542 finder
= _getfinder()
545 aeobj_00
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('cobj'),
546 form
="alis", seld
=object_alias
, fr
=None)
547 aeobj_01
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('prop'),
548 form
="prop", seld
=aetypes
.Type('iimg'), fr
=aeobj_00
)
549 args
['----'] = aeobj_01
550 _reply
, args
, attrs
= finder
.send("core", "getd", args
, attrs
)
551 if args
.has_key('errn'):
552 raise Error
, aetools
.decodeerror(args
)
553 if args
.has_key('----'):
556 def _seticon(object_alias
, icondata
):
557 """set the icondata for object, formatted as produced by _geticon()"""
558 finder
= _getfinder()
561 aeobj_00
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('cobj'),
562 form
="alis", seld
=object_alias
, fr
=None)
563 aeobj_01
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('prop'),
564 form
="prop", seld
=aetypes
.Type('iimg'), fr
=aeobj_00
)
565 args
['----'] = aeobj_01
566 args
["data"] = icondata
567 _reply
, args
, attrs
= finder
.send("core", "setd", args
, attrs
)
568 if args
.has_key('errn'):
569 raise Error
, aetools
.decodeerror(args
)
570 if args
.has_key('----'):
571 return args
['----'].data
574 #---------------------------------------------------
575 # Volumes and servers.
577 def mountvolume(volume
, server
=None, username
=None, password
=None):
578 """mount a volume, local or on a server on AppleTalk.
579 Note: mounting a ASIP server requires a different operation.
580 server is the name of the server where the volume belongs
581 username, password belong to a registered user of the volume."""
582 finder
= _getfinder()
586 args
["PASS"] = password
588 args
["USER"] = username
590 args
["SRVR"] = server
591 args
['----'] = volume
592 _reply
, args
, attrs
= finder
.send("aevt", "mvol", args
, attrs
)
593 if args
.has_key('errn'):
594 raise Error
, aetools
.decodeerror(args
)
595 if args
.has_key('----'):
598 def unmountvolume(volume
):
599 """unmount a volume that's on the desktop"""
603 """puth the object away, whereever it came from."""
604 finder
= _getfinder()
607 args
['----'] = aetypes
.ObjectSpecifier(want
=aetypes
.Type('cdis'), form
="name", seld
=object, fr
=None)
608 _reply
, args
, attrs
= talker
.send("fndr", "ptwy", args
, attrs
)
609 if args
.has_key('errn'):
610 raise Error
, aetools
.decodeerror(args
)
611 if args
.has_key('----'):
615 #---------------------------------------------------
616 # Miscellaneous functions
619 def volumelevel(level
):
620 """set the audio output level, parameter between 0 (silent) and 7 (full blast)"""
621 finder
= _getfinder()
629 _reply
, args
, attrs
= finder
.send("aevt", "stvl", args
, attrs
)
630 if args
.has_key('errn'):
631 raise Error
, aetools
.decodeerror(args
)
632 if args
.has_key('----'):
636 """return the version of the system software"""
637 finder
= _getfinder()
640 aeobj_00
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('prop'), form
="prop", seld
=aetypes
.Type('ver2'), fr
=None)
641 args
['----'] = aeobj_00
642 _reply
, args
, attrs
= finder
.send("core", "getd", args
, attrs
)
643 if args
.has_key('errn'):
644 raise Error
, aetools
.decodeerror(args
)
645 if args
.has_key('----'):
649 """return the current status of filesharing and whether it is starting up or not:
650 -1 file sharing is off and not starting up
651 0 file sharing is off and starting up
652 1 file sharing is on"""
654 finder
= _getfinder()
658 args
['----'] = aetypes
.ObjectSpecifier(want
=aetypes
.Type('prop'), form
="prop", seld
=aetypes
.Type('fshr'), fr
=None)
659 _reply
, args
, attrs
= finder
.send("core", "getd", args
, attrs
)
660 if args
.has_key('errn'):
661 raise Error
, aetools
.decodeerror(args
)
662 if args
.has_key('----'):
663 if args
['----'] == 0:
667 # is it starting up perchance?
670 args
['----'] = aetypes
.ObjectSpecifier(want
=aetypes
.Type('prop'), form
="prop", seld
=aetypes
.Type('fsup'), fr
=None)
671 _reply
, args
, attrs
= finder
.send("core", "getd", args
, attrs
)
672 if args
.has_key('errn'):
673 raise Error
, aetools
.decodeerror(args
)
674 if args
.has_key('----'):
675 if args
['----'] == 1:
679 def movetotrash(path
):
680 """move the object to the trash"""
681 fss
= Carbon
.File
.FSSpec(path
)
682 trashfolder
= Carbon
.Folder
.FSFindFolder(fss
.as_tuple()[0], 'trsh', 0)
683 move(path
, trashfolder
)
686 """empty the trash"""
687 finder
= _getfinder()
690 args
['----'] = aetypes
.ObjectSpecifier(want
=aetypes
.Type('prop'), form
="prop", seld
=aetypes
.Type('trsh'), fr
=None)
691 _reply
, args
, attrs
= finder
.send("fndr", "empt", args
, attrs
)
692 if args
.has_key('errn'):
693 raise aetools
.Error
, aetools
.decodeerror(args
)
698 print 'Original findertools functionality test...'
699 print 'Testing launch...'
700 pathname
= EasyDialogs
.AskFileForOpen('File to launch:')
702 result
= launch(pathname
)
704 print 'Result: ', result
705 print 'Press return-',
707 print 'Testing print...'
708 pathname
= EasyDialogs
.AskFileForOpen('File to print:')
710 result
= Print(pathname
)
712 print 'Result: ', result
713 print 'Press return-',
715 print 'Testing copy...'
716 pathname
= EasyDialogs
.AskFileForOpen('File to copy:')
718 destdir
= EasyDialogs
.AskFolder('Destination:')
720 result
= copy(pathname
, destdir
)
722 print 'Result:', result
723 print 'Press return-',
725 print 'Testing move...'
726 pathname
= EasyDialogs
.AskFileForOpen('File to move:')
728 destdir
= EasyDialogs
.AskFolder('Destination:')
730 result
= move(pathname
, destdir
)
732 print 'Result:', result
733 print 'Press return-',
735 print 'Testing sleep...'
736 if EasyDialogs
.AskYesNoCancel('Sleep?') > 0:
739 print 'Result:', result
740 print 'Press return-',
742 print 'Testing shutdown...'
743 if EasyDialogs
.AskYesNoCancel('Shut down?') > 0:
746 print 'Result:', result
747 print 'Press return-',
749 print 'Testing restart...'
750 if EasyDialogs
.AskYesNoCancel('Restart?') > 0:
753 print 'Result:', result
754 print 'Press return-',
758 print '\nmorefindertools version %s\nTests coming up...' %__version__
763 print '\tfilesharing on?', filesharing() # is file sharing on, off, starting up?
764 print '\tOS version', OSversion() # the version of the system software
766 # set the soundvolume in a simple way
767 print '\tSystem beep volume'
768 for i
in range(0, 7):
772 # Finder's windows, file location, file attributes
773 open("@findertoolstest", "w")
774 f
= "@findertoolstest"
775 reveal(f
) # reveal this file in a Finder window
776 select(f
) # select this file
778 base
, file = os
.path
.split(f
)
779 closewindow(base
) # close the window this file is in (opened by reveal)
780 openwindow(base
) # open it again
781 windowview(base
, 1) # set the view by list
783 label(f
, 2) # set the label of this file to something orange
784 print '\tlabel', label(f
) # get the label of this file
786 # the file location only works in a window with icon view!
787 print 'Random locations for an icon'
788 windowview(base
, 0) # set the view by icon
789 windowsize(base
, (600, 600))
791 location(f
, (random
.randint(10, 590), random
.randint(10, 590)))
793 windowsize(base
, (200, 400))
794 windowview(base
, 1) # set the view by icon
796 orgpos
= windowposition(base
)
797 print 'Animated window location'
799 pos
= (100+i
*10, 100+i
*10)
800 windowposition(base
, pos
)
801 print '\twindow position', pos
802 windowposition(base
, orgpos
) # park it where it was before
804 print 'Put a comment in file', f
, ':'
805 print '\t', comment(f
) # print the Finder comment this file has
806 s
= 'This is a comment no one reads!'
807 comment(f
, s
) # set the Finder comment
810 print 'MacOS9 or better specific functions'
812 pr
= processes() # return a list of tuples with (active_processname, creatorcode)
813 print 'Return a list of current active processes:'
817 # get attributes of the first process in the list
818 print 'Attributes of the first process in the list:'
819 pinfo
= processinfo(pr
[0][0])
821 print '\t\tmemory partition', pinfo
.partition
# the memory allocated to this process
822 print '\t\tmemory used', pinfo
.used
# the memory actuall used by this process
823 print '\t\tis visible', pinfo
.visible
# is the process visible to the user
824 print '\t\tis frontmost', pinfo
.frontmost
# is the process the front most one?
825 print '\t\thas scripting', pinfo
.hasscripting
# is the process scriptable?
826 print '\t\taccepts high level events', pinfo
.accepthighlevel
# does the process accept high level appleevents?
828 if __name__
== '__main__':