views:

790

answers:

6

I am looking for a way to programatically get/set the icon positions on the desktop. Clearly there is some "state" stored in a somewhere. Does anybody know here?

I am trying to get a proof of concept going on ANY platform so if you know how to do it on XP in gnome, KDE or Mac OS I would really like to hear about it.

+2  A: 

Start here: http://msdn.microsoft.com/en-us/library/bb773177(VS.85).aspx

It's unfortunately quite a nasty API because every object in the shell is identified by a thing called a PIDL, which was created by Satan himself to confuse anyone trying to avoid access violations and memory leaks.

Daniel Earwicker
+1 for Satan reference
Eric
A: 

I've tried looking into this a couple of times the last couple of years, it seems like such a trivial thing (It was for the AmigaDos workbench), but programming for the Windows shell is ugly; actually programming anything in the Windows API is ugly. Its a horrible mess. Be prepared for a bunch of hair pulling and heart ache.

Not to discourage you, but MicroSoft thinks it knows best when it comes to icon placement in folder views and I have found little in a way to implement 'permanent' icon placement (I.e. Icon view is far from permanent). The MSDN docs offer little help in this regard (at least no examples). The last thing I looked into was writing a shell extension to record and restore icon position (I wouldn't record these in the registry, I was just going to store positions in the folder's desktop.ini file, but it would probably be better to create a file in the user's private settings folder).

Code Project has a number of articles on shell programming and extensions.

http://www.codeproject.com/KB/shell/ http://www.codeproject.com/KB/shell/shlext.aspx

I ended up writing my own little shell in nice clean pure C++ that does exactly what I want in the context of my application.

Roger Nelson
+1  A: 

Position of normal files and folders is stored in the hidden .DS_Store file, that exists for any directory The position of volume icons on Mac OS X seems to be stored in the Finders .plist (~/Library/Preferences/com.apple.finder).

weichsel
+1  A: 

A lot of the answers here are saying that doing this sort of thing is pretty difficult to do in Windows. I suspect that this is not by accident. If you've never read Raymond Chen's blog The Old New Thing I suggest you do. Mr. Chen frequently discusses the pitfalls and abuse that occur with programmatic access to things such as the placement of icons.

Edit: Here are some commentaries about allow programmatic access in Windows.

Although you're probably not meant to be able to do this (at least on Windows), that doesn't mean that it can't be done. I just ask that you do this in the spirit of good and not evil.

Andrew Keeton
A: 

For desktops following the freedesktop.org specifications (however flawed they may be), the relevant document seems to be here; it does not say anything about positions, though.

pmf
A: 

In GNOME, Nautilus stores the position of icons and other stuff in ~/.nautilus/metafiles.

The files in there have ugly filenames, as they are really escaped URIs. For example, my metadata for my desktop icons lives in ~/.nautilus/metafiles/file:%2F%2F%2Fhome%2Ffederico%2FDesktop.xml

There is no public interface to access or modify that data, however. You can of course parse the file on your own and modify it, but the changes will not take effect until the next time you restart Nautilus.

Federico Mena-Quintero