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 warnings
import warnpy3k
19 warnpy3k("In 3.x, the findertools module is removed.", stacklevel
=2)
22 from Carbon
import AppleEvents
32 Error
= 'findertools.Error'
37 """returns basic (recyclable) Finder AE interface object"""
39 if not _finder_talker
:
40 _finder_talker
= Finder
.Finder()
41 _finder_talker
.send_flags
= ( _finder_talker
.send_flags |
42 AppleEvents
.kAECanInteract | AppleEvents
.kAECanSwitchLayer
)
46 """Open a file thru the finder. Specify file by name or fsspec"""
48 fss
= Carbon
.File
.FSSpec(file)
49 return finder
.open(fss
)
52 """Print a file thru the finder. Specify file by name or fsspec"""
54 fss
= Carbon
.File
.FSSpec(file)
55 return finder
._print
(fss
)
57 def copy(src
, dstdir
):
58 """Copy a file to a folder"""
60 if type(src
) == type([]):
63 src_fss
.append(Carbon
.File
.FSSpec(s
))
65 src_fss
= Carbon
.File
.FSSpec(src
)
66 dst_fss
= Carbon
.File
.FSSpec(dstdir
)
67 return finder
.duplicate(src_fss
, to
=dst_fss
)
69 def move(src
, dstdir
):
70 """Move a file to a folder"""
72 if type(src
) == type([]):
75 src_fss
.append(Carbon
.File
.FSSpec(s
))
77 src_fss
= Carbon
.File
.FSSpec(src
)
78 dst_fss
= Carbon
.File
.FSSpec(dstdir
)
79 return finder
.move(src_fss
, to
=dst_fss
)
82 """Put the mac to sleep"""
87 """Shut the mac down"""
97 #---------------------------------------------------
98 # Additional findertools
102 """Reveal a file in the finder. Specify file by name, fsref or fsspec."""
103 finder
= _getfinder()
104 fsr
= Carbon
.File
.FSRef(file)
105 file_alias
= fsr
.FSNewAliasMinimal()
106 return finder
.reveal(file_alias
)
109 """select a file in the finder. Specify file by name, fsref or fsspec."""
110 finder
= _getfinder()
111 fsr
= Carbon
.File
.FSRef(file)
112 file_alias
= fsr
.FSNewAliasMinimal()
113 return finder
.select(file_alias
)
116 """Update the display of the specified object(s) to match
117 their on-disk representation. Specify file by name, fsref or fsspec."""
118 finder
= _getfinder()
119 fsr
= Carbon
.File
.FSRef(file)
120 file_alias
= fsr
.FSNewAliasMinimal()
121 return finder
.update(file_alias
)
124 #---------------------------------------------------
128 def comment(object, comment
=None):
129 """comment: get or set the Finder-comment of the item, displayed in the 'Get Info' window."""
130 object = Carbon
.File
.FSRef(object)
131 object_alias
= object.FSNewAliasMonimal()
133 return _getcomment(object_alias
)
135 return _setcomment(object_alias
, comment
)
137 def _setcomment(object_alias
, comment
):
138 finder
= _getfinder()
141 aeobj_00
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('cobj'), form
="alis", seld
=object_alias
, fr
=None)
142 aeobj_01
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('prop'), form
="prop", seld
=aetypes
.Type('comt'), fr
=aeobj_00
)
143 args
['----'] = aeobj_01
144 args
["data"] = comment
145 _reply
, args
, attrs
= finder
.send("core", "setd", args
, attrs
)
146 if args
.has_key('errn'):
147 raise Error
, aetools
.decodeerror(args
)
148 if args
.has_key('----'):
151 def _getcomment(object_alias
):
152 finder
= _getfinder()
155 aeobj_00
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('cobj'), form
="alis", seld
=object_alias
, fr
=None)
156 aeobj_01
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('prop'), form
="prop", seld
=aetypes
.Type('comt'), fr
=aeobj_00
)
157 args
['----'] = aeobj_01
158 _reply
, args
, attrs
= finder
.send("core", "getd", args
, attrs
)
159 if args
.has_key('errn'):
160 raise Error
, aetools
.decodeerror(args
)
161 if args
.has_key('----'):
165 #---------------------------------------------------
166 # Get information about current processes in the Finder.
169 """processes returns a list of all active processes running on this computer and their creators."""
170 finder
= _getfinder()
178 ## get the processnames or else the processnumbers
179 args
['----'] = aetypes
.ObjectSpecifier(want
=aetypes
.Type('prcs'), form
="indx", seld
=aetypes
.Unknown('abso', "all "), fr
=None)
180 _reply
, args
, attrs
= finder
.send('core', 'getd', args
, attrs
)
181 if args
.has_key('errn'):
182 raise Error
, aetools
.decodeerror(args
)
184 if args
.has_key('----'):
187 if hasattr(proc
, 'seld'):
189 processnames
.append(proc
.seld
)
190 elif hasattr(proc
, 'type'):
191 if proc
.type == "psn ":
192 # it has a process number
193 processnumbers
.append(proc
.data
)
197 aeobj_0
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('prcs'), form
="indx", seld
=aetypes
.Unknown('abso', "all "), fr
=None)
198 args
['----'] = aetypes
.ObjectSpecifier(want
=aetypes
.Type('prop'), form
="prop", seld
=aetypes
.Type('fcrt'), fr
=aeobj_0
)
199 _reply
, args
, attrs
= finder
.send('core', 'getd', args
, attrs
)
200 if args
.has_key('errn'):
201 raise Error
, aetools
.decodeerror(_arg
)
202 if args
.has_key('----'):
205 ## concatenate in one dict
207 if len(processnames
) > len(processnumbers
):
210 data
= processnumbers
211 for i
in range(len(creators
)):
212 result
.append((data
[i
], creators
[i
]))
218 def isactiveprocess(processname
):
219 """Check of processname is active. MacOS9"""
227 def processinfo(processname
):
228 """Return an object with all process properties as attributes for processname. MacOS9"""
231 if processname
== "Finder":
235 p
.partition
= _processproperty(processname
, 'appt')
236 p
.used
= _processproperty(processname
, 'pusd')
237 p
.visible
= _processproperty(processname
, 'pvis') #Is the process' layer visible?
238 p
.frontmost
= _processproperty(processname
, 'pisf') #Is the process the frontmost process?
239 p
.file = _processproperty(processname
, 'file') #the file from which the process was launched
240 p
.filetype
= _processproperty(processname
, 'asty') #the OSType of the file type of the process
241 p
.creatortype
= _processproperty(processname
, 'fcrt') #the OSType of the creator of the process (the signature)
242 p
.accepthighlevel
= _processproperty(processname
, 'revt') #Is the process high-level event aware (accepts open application, open document, print document, and quit)?
243 p
.hasscripting
= _processproperty(processname
, 'hscr') #Does the process have a scripting terminology, i.e., can it be scripted?
246 def _processproperty(processname
, property):
247 """return the partition size and memory used for processname"""
248 finder
= _getfinder()
251 aeobj_00
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('prcs'), form
="name", seld
=processname
, fr
=None)
252 aeobj_01
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('prop'), form
="prop", seld
=aetypes
.Type(property), fr
=aeobj_00
)
253 args
['----'] = aeobj_01
254 _reply
, args
, attrs
= finder
.send("core", "getd", args
, attrs
)
255 if args
.has_key('errn'):
256 raise Error
, aetools
.decodeerror(args
)
257 if args
.has_key('----'):
261 #---------------------------------------------------
262 # Mess around with Finder windows.
264 def openwindow(object):
265 """Open a Finder window for object, Specify object by name or fsspec."""
266 finder
= _getfinder()
267 object = Carbon
.File
.FSRef(object)
268 object_alias
= object.FSNewAliasMinimal()
273 aeobj_0
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('cfol'), form
="alis", seld
=object_alias
, fr
=None)
274 args
['----'] = aeobj_0
275 _reply
, args
, attrs
= finder
.send(_code
, _subcode
, args
, attrs
)
276 if args
.has_key('errn'):
277 raise Error
, aetools
.decodeerror(args
)
279 def closewindow(object):
280 """Close a Finder window for folder, Specify by path."""
281 finder
= _getfinder()
282 object = Carbon
.File
.FSRef(object)
283 object_alias
= object.FSNewAliasMinimal()
288 aeobj_0
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('cfol'), form
="alis", seld
=object_alias
, fr
=None)
289 args
['----'] = aeobj_0
290 _reply
, args
, attrs
= finder
.send(_code
, _subcode
, args
, attrs
)
291 if args
.has_key('errn'):
292 raise Error
, aetools
.decodeerror(args
)
294 def location(object, pos
=None):
295 """Set the position of a Finder window for folder to pos=(w, h). Specify file by name or fsspec.
296 If pos=None, location will return the current position of the object."""
297 object = Carbon
.File
.FSRef(object)
298 object_alias
= object.FSNewAliasMinimal()
300 return _getlocation(object_alias
)
301 return _setlocation(object_alias
, pos
)
303 def _setlocation(object_alias
, (x
, y
)):
304 """_setlocation: Set the location of the icon for the object."""
305 finder
= _getfinder()
308 aeobj_00
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('cfol'), form
="alis", seld
=object_alias
, fr
=None)
309 aeobj_01
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('prop'), form
="prop", seld
=aetypes
.Type('posn'), fr
=aeobj_00
)
310 args
['----'] = aeobj_01
311 args
["data"] = [x
, y
]
312 _reply
, args
, attrs
= finder
.send("core", "setd", args
, attrs
)
313 if args
.has_key('errn'):
314 raise Error
, aetools
.decodeerror(args
)
317 def _getlocation(object_alias
):
318 """_getlocation: get the location of the icon for the object."""
319 finder
= _getfinder()
322 aeobj_00
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('cfol'), form
="alis", seld
=object_alias
, fr
=None)
323 aeobj_01
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('prop'), form
="prop", seld
=aetypes
.Type('posn'), fr
=aeobj_00
)
324 args
['----'] = aeobj_01
325 _reply
, args
, attrs
= finder
.send("core", "getd", args
, attrs
)
326 if args
.has_key('errn'):
327 raise Error
, aetools
.decodeerror(args
)
328 if args
.has_key('----'):
332 def label(object, index
=None):
333 """label: set or get the label of the item. Specify file by name or fsspec."""
334 object = Carbon
.File
.FSRef(object)
335 object_alias
= object.FSNewAliasMinimal()
337 return _getlabel(object_alias
)
338 if index
< 0 or index
> 7:
340 return _setlabel(object_alias
, index
)
342 def _getlabel(object_alias
):
343 """label: Get the label for the object."""
344 finder
= _getfinder()
347 aeobj_00
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('cobj'), form
="alis", seld
=object_alias
, fr
=None)
348 aeobj_01
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('prop'), form
="prop", seld
=aetypes
.Type('labi'), fr
=aeobj_00
)
349 args
['----'] = aeobj_01
350 _reply
, args
, attrs
= finder
.send("core", "getd", args
, attrs
)
351 if args
.has_key('errn'):
352 raise Error
, aetools
.decodeerror(args
)
353 if args
.has_key('----'):
356 def _setlabel(object_alias
, index
):
357 """label: Set the label for the object."""
358 finder
= _getfinder()
363 aeobj_0
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('prop'),
364 form
="alis", seld
=object_alias
, fr
=None)
365 aeobj_1
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('prop'),
366 form
="prop", seld
=aetypes
.Type('labi'), fr
=aeobj_0
)
367 args
['----'] = aeobj_1
369 _reply
, args
, attrs
= finder
.send(_code
, _subcode
, args
, attrs
)
370 if args
.has_key('errn'):
371 raise Error
, aetools
.decodeerror(args
)
374 def windowview(folder
, view
=None):
375 """windowview: Set the view of the window for the folder. Specify file by name or fsspec.
376 0 = by icon (default)
380 fsr
= Carbon
.File
.FSRef(folder
)
381 folder_alias
= fsr
.FSNewAliasMinimal()
383 return _getwindowview(folder_alias
)
384 return _setwindowview(folder_alias
, view
)
386 def _setwindowview(folder_alias
, view
=0):
387 """set the windowview"""
391 _v
= aetypes
.Type('pnam')
393 _v
= aetypes
.Type('lgbu')
395 _v
= aetypes
.Type('iimg')
396 finder
= _getfinder()
397 aeobj_0
= aetypes
.ObjectSpecifier(want
= aetypes
.Type('cfol'),
398 form
= 'alis', seld
= folder_alias
, fr
=None)
399 aeobj_1
= aetypes
.ObjectSpecifier(want
= aetypes
.Type('prop'),
400 form
= 'prop', seld
= aetypes
.Type('cwnd'), fr
=aeobj_0
)
401 aeobj_2
= aetypes
.ObjectSpecifier(want
= aetypes
.Type('prop'),
402 form
= 'prop', seld
= aetypes
.Type('pvew'), fr
=aeobj_1
)
403 aeobj_3
= aetypes
.ObjectSpecifier(want
= aetypes
.Type('prop'),
404 form
= 'prop', seld
= _v
, fr
=None)
407 args
['----'] = aeobj_2
408 args
['data'] = aeobj_3
409 _reply
, args
, attrs
= finder
.send(_code
, _subcode
, args
, attrs
)
410 if args
.has_key('errn'):
411 raise Error
, aetools
.decodeerror(args
)
412 if args
.has_key('----'):
415 def _getwindowview(folder_alias
):
416 """get the windowview"""
419 finder
= _getfinder()
422 aeobj_00
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('cfol'), form
="alis", seld
=folder_alias
, fr
=None)
423 aeobj_01
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('prop'), form
="prop", seld
=aetypes
.Type('cwnd'), fr
=aeobj_00
)
424 aeobj_02
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('prop'), form
="prop", seld
=aetypes
.Type('pvew'), fr
=aeobj_01
)
425 args
['----'] = aeobj_02
426 _reply
, args
, attrs
= finder
.send("core", "getd", args
, attrs
)
427 if args
.has_key('errn'):
428 raise Error
, aetools
.decodeerror(args
)
429 views
= {'iimg':0, 'pnam':1, 'lgbu':2}
430 if args
.has_key('----'):
431 return views
[args
['----'].enum
]
433 def windowsize(folder
, size
=None):
434 """Set the size of a Finder window for folder to size=(w, h), Specify by path.
435 If size=None, windowsize will return the current size of the window.
436 Specify file by name or fsspec.
438 fsr
= Carbon
.File
.FSRef(folder
)
439 folder_alias
= fsr
.FSNewAliasMinimal()
442 return _getwindowsize(folder_alias
)
443 return _setwindowsize(folder_alias
, size
)
445 def _setwindowsize(folder_alias
, (w
, h
)):
446 """Set the size of a Finder window for folder to (w, h)"""
447 finder
= _getfinder()
453 aeobj_0
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('cfol'),
454 form
="alis", seld
=folder_alias
, fr
=None)
455 aeobj_1
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('prop'),
456 form
="prop", seld
=aetypes
.Type('cwnd'), fr
=aeobj_0
)
457 aeobj_2
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('prop'),
458 form
="prop", seld
=aetypes
.Type('ptsz'), fr
=aeobj_1
)
459 args
['----'] = aeobj_2
460 args
["data"] = aevar00
461 _reply
, args
, attrs
= finder
.send(_code
, _subcode
, args
, attrs
)
462 if args
.has_key('errn'):
463 raise Error
, aetools
.decodeerror(args
)
466 def _getwindowsize(folder_alias
):
467 """Set the size of a Finder window for folder to (w, h)"""
468 finder
= _getfinder()
471 aeobj_0
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('cfol'),
472 form
="alis", seld
=folder_alias
, fr
=None)
473 aeobj_1
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('prop'),
474 form
="prop", seld
=aetypes
.Type('cwnd'), fr
=aeobj_0
)
475 aeobj_2
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('prop'),
476 form
="prop", seld
=aetypes
.Type('posn'), fr
=aeobj_1
)
477 args
['----'] = aeobj_2
478 _reply
, args
, attrs
= finder
.send('core', 'getd', args
, attrs
)
479 if args
.has_key('errn'):
480 raise Error
, aetools
.decodeerror(args
)
481 if args
.has_key('----'):
484 def windowposition(folder
, pos
=None):
485 """Set the position of a Finder window for folder to pos=(w, h)."""
486 fsr
= Carbon
.File
.FSRef(folder
)
487 folder_alias
= fsr
.FSNewAliasMinimal()
490 return _getwindowposition(folder_alias
)
491 if type(pos
) == InstanceType
:
492 # pos might be a QDPoint object as returned by _getwindowposition
494 return _setwindowposition(folder_alias
, pos
)
496 def _setwindowposition(folder_alias
, (x
, y
)):
497 """Set the size of a Finder window for folder to (w, h)."""
498 finder
= _getfinder()
501 aeobj_0
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('cfol'),
502 form
="alis", seld
=folder_alias
, fr
=None)
503 aeobj_1
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('prop'),
504 form
="prop", seld
=aetypes
.Type('cwnd'), fr
=aeobj_0
)
505 aeobj_2
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('prop'),
506 form
="prop", seld
=aetypes
.Type('posn'), fr
=aeobj_1
)
507 args
['----'] = aeobj_2
508 args
["data"] = [x
, y
]
509 _reply
, args
, attrs
= finder
.send('core', 'setd', args
, attrs
)
510 if args
.has_key('errn'):
511 raise Error
, aetools
.decodeerror(args
)
512 if args
.has_key('----'):
515 def _getwindowposition(folder_alias
):
516 """Get the size of a Finder window for folder, Specify by path."""
517 finder
= _getfinder()
520 aeobj_0
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('cfol'),
521 form
="alis", seld
=folder_alias
, fr
=None)
522 aeobj_1
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('prop'),
523 form
="prop", seld
=aetypes
.Type('cwnd'), fr
=aeobj_0
)
524 aeobj_2
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('prop'),
525 form
="prop", seld
=aetypes
.Type('ptsz'), fr
=aeobj_1
)
526 args
['----'] = aeobj_2
527 _reply
, args
, attrs
= finder
.send('core', 'getd', args
, attrs
)
528 if args
.has_key('errn'):
529 raise Error
, aetools
.decodeerror(args
)
530 if args
.has_key('----'):
533 def icon(object, icondata
=None):
534 """icon sets the icon of object, if no icondata is given,
535 icon will return an AE object with binary data for the current icon.
536 If left untouched, this data can be used to paste the icon on another file.
537 Development opportunity: get and set the data as PICT."""
538 fsr
= Carbon
.File
.FSRef(object)
539 object_alias
= fsr
.FSNewAliasMinimal()
541 return _geticon(object_alias
)
542 return _seticon(object_alias
, icondata
)
544 def _geticon(object_alias
):
545 """get the icondata for object. Binary data of some sort."""
546 finder
= _getfinder()
549 aeobj_00
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('cobj'),
550 form
="alis", seld
=object_alias
, fr
=None)
551 aeobj_01
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('prop'),
552 form
="prop", seld
=aetypes
.Type('iimg'), fr
=aeobj_00
)
553 args
['----'] = aeobj_01
554 _reply
, args
, attrs
= finder
.send("core", "getd", args
, attrs
)
555 if args
.has_key('errn'):
556 raise Error
, aetools
.decodeerror(args
)
557 if args
.has_key('----'):
560 def _seticon(object_alias
, icondata
):
561 """set the icondata for object, formatted as produced by _geticon()"""
562 finder
= _getfinder()
565 aeobj_00
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('cobj'),
566 form
="alis", seld
=object_alias
, fr
=None)
567 aeobj_01
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('prop'),
568 form
="prop", seld
=aetypes
.Type('iimg'), fr
=aeobj_00
)
569 args
['----'] = aeobj_01
570 args
["data"] = icondata
571 _reply
, args
, attrs
= finder
.send("core", "setd", args
, attrs
)
572 if args
.has_key('errn'):
573 raise Error
, aetools
.decodeerror(args
)
574 if args
.has_key('----'):
575 return args
['----'].data
578 #---------------------------------------------------
579 # Volumes and servers.
581 def mountvolume(volume
, server
=None, username
=None, password
=None):
582 """mount a volume, local or on a server on AppleTalk.
583 Note: mounting a ASIP server requires a different operation.
584 server is the name of the server where the volume belongs
585 username, password belong to a registered user of the volume."""
586 finder
= _getfinder()
590 args
["PASS"] = password
592 args
["USER"] = username
594 args
["SRVR"] = server
595 args
['----'] = volume
596 _reply
, args
, attrs
= finder
.send("aevt", "mvol", args
, attrs
)
597 if args
.has_key('errn'):
598 raise Error
, aetools
.decodeerror(args
)
599 if args
.has_key('----'):
602 def unmountvolume(volume
):
603 """unmount a volume that's on the desktop"""
607 """puth the object away, whereever it came from."""
608 finder
= _getfinder()
611 args
['----'] = aetypes
.ObjectSpecifier(want
=aetypes
.Type('cdis'), form
="name", seld
=object, fr
=None)
612 _reply
, args
, attrs
= talker
.send("fndr", "ptwy", args
, attrs
)
613 if args
.has_key('errn'):
614 raise Error
, aetools
.decodeerror(args
)
615 if args
.has_key('----'):
619 #---------------------------------------------------
620 # Miscellaneous functions
623 def volumelevel(level
):
624 """set the audio output level, parameter between 0 (silent) and 7 (full blast)"""
625 finder
= _getfinder()
633 _reply
, args
, attrs
= finder
.send("aevt", "stvl", args
, attrs
)
634 if args
.has_key('errn'):
635 raise Error
, aetools
.decodeerror(args
)
636 if args
.has_key('----'):
640 """return the version of the system software"""
641 finder
= _getfinder()
644 aeobj_00
= aetypes
.ObjectSpecifier(want
=aetypes
.Type('prop'), form
="prop", seld
=aetypes
.Type('ver2'), fr
=None)
645 args
['----'] = aeobj_00
646 _reply
, args
, attrs
= finder
.send("core", "getd", args
, attrs
)
647 if args
.has_key('errn'):
648 raise Error
, aetools
.decodeerror(args
)
649 if args
.has_key('----'):
653 """return the current status of filesharing and whether it is starting up or not:
654 -1 file sharing is off and not starting up
655 0 file sharing is off and starting up
656 1 file sharing is on"""
658 finder
= _getfinder()
662 args
['----'] = aetypes
.ObjectSpecifier(want
=aetypes
.Type('prop'), form
="prop", seld
=aetypes
.Type('fshr'), fr
=None)
663 _reply
, args
, attrs
= finder
.send("core", "getd", args
, attrs
)
664 if args
.has_key('errn'):
665 raise Error
, aetools
.decodeerror(args
)
666 if args
.has_key('----'):
667 if args
['----'] == 0:
671 # is it starting up perchance?
674 args
['----'] = aetypes
.ObjectSpecifier(want
=aetypes
.Type('prop'), form
="prop", seld
=aetypes
.Type('fsup'), fr
=None)
675 _reply
, args
, attrs
= finder
.send("core", "getd", args
, attrs
)
676 if args
.has_key('errn'):
677 raise Error
, aetools
.decodeerror(args
)
678 if args
.has_key('----'):
679 if args
['----'] == 1:
683 def movetotrash(path
):
684 """move the object to the trash"""
685 fss
= Carbon
.File
.FSSpec(path
)
686 trashfolder
= Carbon
.Folder
.FSFindFolder(fss
.as_tuple()[0], 'trsh', 0)
687 move(path
, trashfolder
)
690 """empty the trash"""
691 finder
= _getfinder()
694 args
['----'] = aetypes
.ObjectSpecifier(want
=aetypes
.Type('prop'), form
="prop", seld
=aetypes
.Type('trsh'), fr
=None)
695 _reply
, args
, attrs
= finder
.send("fndr", "empt", args
, attrs
)
696 if args
.has_key('errn'):
697 raise aetools
.Error
, aetools
.decodeerror(args
)
702 print 'Original findertools functionality test...'
703 print 'Testing launch...'
704 pathname
= EasyDialogs
.AskFileForOpen('File to launch:')
706 result
= launch(pathname
)
708 print 'Result: ', result
709 print 'Press return-',
711 print 'Testing print...'
712 pathname
= EasyDialogs
.AskFileForOpen('File to print:')
714 result
= Print(pathname
)
716 print 'Result: ', result
717 print 'Press return-',
719 print 'Testing copy...'
720 pathname
= EasyDialogs
.AskFileForOpen('File to copy:')
722 destdir
= EasyDialogs
.AskFolder('Destination:')
724 result
= copy(pathname
, destdir
)
726 print 'Result:', result
727 print 'Press return-',
729 print 'Testing move...'
730 pathname
= EasyDialogs
.AskFileForOpen('File to move:')
732 destdir
= EasyDialogs
.AskFolder('Destination:')
734 result
= move(pathname
, destdir
)
736 print 'Result:', result
737 print 'Press return-',
739 print 'Testing sleep...'
740 if EasyDialogs
.AskYesNoCancel('Sleep?') > 0:
743 print 'Result:', result
744 print 'Press return-',
746 print 'Testing shutdown...'
747 if EasyDialogs
.AskYesNoCancel('Shut down?') > 0:
750 print 'Result:', result
751 print 'Press return-',
753 print 'Testing restart...'
754 if EasyDialogs
.AskYesNoCancel('Restart?') > 0:
757 print 'Result:', result
758 print 'Press return-',
762 print '\nmorefindertools version %s\nTests coming up...' %__version__
767 print '\tfilesharing on?', filesharing() # is file sharing on, off, starting up?
768 print '\tOS version', OSversion() # the version of the system software
770 # set the soundvolume in a simple way
771 print '\tSystem beep volume'
772 for i
in range(0, 7):
776 # Finder's windows, file location, file attributes
777 open("@findertoolstest", "w")
778 f
= "@findertoolstest"
779 reveal(f
) # reveal this file in a Finder window
780 select(f
) # select this file
782 base
, file = os
.path
.split(f
)
783 closewindow(base
) # close the window this file is in (opened by reveal)
784 openwindow(base
) # open it again
785 windowview(base
, 1) # set the view by list
787 label(f
, 2) # set the label of this file to something orange
788 print '\tlabel', label(f
) # get the label of this file
790 # the file location only works in a window with icon view!
791 print 'Random locations for an icon'
792 windowview(base
, 0) # set the view by icon
793 windowsize(base
, (600, 600))
795 location(f
, (random
.randint(10, 590), random
.randint(10, 590)))
797 windowsize(base
, (200, 400))
798 windowview(base
, 1) # set the view by icon
800 orgpos
= windowposition(base
)
801 print 'Animated window location'
803 pos
= (100+i
*10, 100+i
*10)
804 windowposition(base
, pos
)
805 print '\twindow position', pos
806 windowposition(base
, orgpos
) # park it where it was before
808 print 'Put a comment in file', f
, ':'
809 print '\t', comment(f
) # print the Finder comment this file has
810 s
= 'This is a comment no one reads!'
811 comment(f
, s
) # set the Finder comment
814 print 'MacOS9 or better specific functions'
816 pr
= processes() # return a list of tuples with (active_processname, creatorcode)
817 print 'Return a list of current active processes:'
821 # get attributes of the first process in the list
822 print 'Attributes of the first process in the list:'
823 pinfo
= processinfo(pr
[0][0])
825 print '\t\tmemory partition', pinfo
.partition
# the memory allocated to this process
826 print '\t\tmemory used', pinfo
.used
# the memory actuall used by this process
827 print '\t\tis visible', pinfo
.visible
# is the process visible to the user
828 print '\t\tis frontmost', pinfo
.frontmost
# is the process the front most one?
829 print '\t\thas scripting', pinfo
.hasscripting
# is the process scriptable?
830 print '\t\taccepts high level events', pinfo
.accepthighlevel
# does the process accept high level appleevents?
832 if __name__
== '__main__':