3
votes

I need to fetch the currently selected item on the desktop or the desktop item that was right clicked . Depending on the path for this item(s) I will have to perform some action. Can this be done using applescript ???

I am currently using the logic given here(using scripting bridge)

But this seems to fetch the selection from any of the finder windows and not just the desktop view. Can anyone please provide any alternative ??

2

2 Answers

3
votes

If you focus the desktop first, the selection property will contain only items selected on the desktop.

tell application "Finder"
    select window of desktop
    selection
end tell
0
votes

The finder can't tell which items are selected in from the desktop. It can only tell you from the active window. If you don't want to change the order of the windows you can consider the using GUI scripting. You will get the selected item(s) then like this

tell application "System Events"
    tell process "Finder"
        tell group 1 of scroll area 1
            get name of every image whose selected is true
        end tell
    end tell
end tell