[Pythonmac-SIG] Set/get finder color label of a file

matthias.oberlaender@daimlerchrysler.com matthias.oberlaender at daimlerchrysler.com
Fri Aug 19 14:11:52 CEST 2005


has wrote:
> matthias oberlaender wrote:
> >I would very much like to get and set the color label (or 'label 
index')
> >of a file programmatically from Python. I spent quite some time 
googling,
> >but  was unable to extract the necessary bits how to do it with a few
> >Carbon calls.
> 
> Dunno about Carbon APIs, but it's easy enough using IPC:
> 
> #!/usr/bin/env pythonw
> 
> from appscript import *
> from macfile import Alias
> 
> path = '/Users/has/test.txt'
> label = 3
> 
> app('Finder').items[Alias(path)].label_index.set(label)
> print app('Finder').items[Alias(path)].label_index.get()
> 
> 
> See <http://freespace.virgin.net/hamish.sanderson/appscript.html>. 
> Note: if you install appscript using the binary installer (easiest),
> you'll also need to d/l the latest appscript-0.13.1.tar.gz package from 
<
> http://freespace.virgin.net/hamish.sanderson/appscript_source.html> 
> and install that as well.
> 
> HTH
> 
> has

Looked promising. Very concise. Thank you very much. However, I had no 
look installing appscript. I installed the two packages as you suggested 
(OS X 10.3 with Apple supplied Python). Below is what happened. Maybe some 
more updates necessary? (I assume installing appscript-0.13.1.tar.gz was 
meant as a patch to the pure binary installation.)


from appscript import app
from macfile import Alias
import os

path = '/Users/oberlaender/dead.letter'
assert os.path.exists(path)
print app('Finder').items[Alias(path)].label_index.get()


Without AppscriptTerminologyServer running:

pythonw -i test.py
Traceback (most recent call last):
  File "test.py", line 8, in ?
    print app('Finder').items[Alias(path)].label_index.get()
  File 
"/Users/oberlaender/Desktop/appscript-0.13.1/appscript/specifier.py", line 
390, in __init__
    translationTables = tablesForLocalApp(path)
  File 
"/Users/oberlaender/Desktop/appscript-0.13.1/appscript/translationtablereader.py", 
line 142, in tablesForLocalApp
    classes, enums, properties, elements, commands = buildTables(path)
  File 
"/Users/oberlaender/Desktop/appscript-0.13.1/appscript/translationtablebuilder.py", 
line 99, in buildTables
    aeteparser.parse(getaete(path), p)
  File 
"/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/site-packages/osaterminology/aeteparser.py", 
line 254, in parse
  File 
"/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/site-packages/osaterminology/aeteparser.py", 
line 64, in list
  File 
"/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/site-packages/osaterminology/aeteparser.py", 
line 182, in _parseSuite
  File 
"/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/site-packages/osaterminology/aeteparser.py", 
line 64, in list
  File 
"/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/site-packages/osaterminology/aeteparser.py", 
line 100, in _parseCommand
TypeError: start_command() takes exactly 6 arguments (7 given)
>>> 

With AppscriptTerminologyServer running:

pythonw -i test.py
Traceback (most recent call last):
  File "test.py", line 8, in ?
    print app('Finder').items[Alias(path)].label_index.get()
  File 
"/Users/oberlaender/Desktop/appscript-0.13.1/appscript/specifier.py", line 
203, in __call__
    raise CommandError(self, (args, kargs), e)
appscript.specifier.CommandError: event() got an unexpected keyword 
argument 'resulttype'
        Failed command: 
app(u'/System/Library/CoreServices/Finder.app').items[Alias(u'/Users/oberlaender/dead.letter')].label_index.get()
>>> 

 
-- Matthias


More information about the Pythonmac-SIG mailing list