[Pythonmac-SIG] Dock: adding/removing/checking
Bob Ippolito
bob at redivi.com
Fri Oct 15 19:26:54 CEST 2004
On Oct 15, 2004, at 1:07 PM, brad.allen at omsdal.com wrote:
> What is the most appropriate way to interact with the Dock using
> Python? I
> don't think my current method using the "defaults" command is optimal.
> It
> only works when run as the user; however, most of my scripts are
> designed
> to run as root/sudo because they are used for administering Macs on
> our LAN
> at work. I'm wondering if there is a way to use a native API instead,
> but
> didn't find what I was looking for at
> http://developer.apple.com/documentation.
I don't believe there's a "native API" for manipulating the dock
because software applications are not "allowed" (by convention) to
modify the dock.
I have two comments about what you're doing though:
- The way you call the defaults application is HORRENDOUS! Wow. I
highly suggest using the subprocess module (formerly process, formerly
popen5) that is going to be in Python 2.4, or at least
os.spawnl/os.spawnv:
(reference implementation) http://www.lysator.liu.se/~astrand/popen5/
(proposal) http://www.python.org/peps/pep-0324.html
- You can also read/write plist files with PyObjC, using the
NSUserDefaults and/or NSDictionary's plist
serialization/deserialization methods instead of the defaults command,
which is about as native as you're going to get. The standard
library's plistlib might also work, but it's not the most complete and
accurate implementation out there, so I don't know how much I'd trust
it for this purpose.
-bob
More information about the Pythonmac-SIG
mailing list