开发者

Get the position of icons on the desktop

开发者 https://www.devze.com 2022-12-30 17:41 出处:网络
How can I get the positio开发者_Python百科n 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?Try this AppleScript code

How can I get the positio开发者_Python百科n 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?


Try this AppleScript code

tell application "Finder"
    get desktop position of every item of desktop
end tell


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.


following apple script will get those positions (use either scripting bridge or NSAppleScript)

tell application "Finder"
    tell every item of desktop
        get position
        get name
    end tell
end tell


Another solution (Very similar to the one of @Vaskravchuk)

tell application "Finder"
    repeat with anItem in desktop
        get {desktop position, name} of anItem
    end repeat
end tell
0

精彩评论

暂无评论...
验证码 换一张
取 消