Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the position of icons on the desktop

Tags:

macos

cocoa

How can I get the position of an icon on the desktop in OS X? Or, how can I get a list of all icons on the desktop and their positions?

like image 831
OmidH Avatar asked May 16 '10 20:05

OmidH


2 Answers

Try this AppleScript code

tell application "Finder"
    get desktop position of every item of desktop
end tell
like image 192
Vaskravchuk Avatar answered Sep 21 '22 16:09

Vaskravchuk


The solution for a folder is to use a catalog iterator to get the Finder info for every item in the folder. The Finder info is a FileInfo or FolderInfo structure that contains a QuickDraw Point (integral co-ordinates, origin top-left, positive y down) specifying where the icon will appear.

I don't know how you would do this for the Desktop, though. There is a Desktop folder in the Home folder, but examining its contents will probably get you the positions that the Finder will use to display that folder in a window. It also will probably not include anything “on the Desktop” that isn't in the Desktop folder, such as mounted volumes.

like image 37
Peter Hosey Avatar answered Sep 25 '22 16:09

Peter Hosey