Documentation Archive Developer
Search

ADC Home > Reference Library > Technical Q&As > Carbon > Interapplication Communication >

Deselecting Icons in the Finder


Q: Is there any way to programmatically deselect icons that were previously selected in the Finder?

A: Yes, actually, there are a few different methods you can use. You can deselect all icons that are selected in the Finder by doing the following:

  1. You can do this through AppleScript by doing the following: ignoring application responses tell application "Finder" to set selection to {} end ignoring. This is equivalent to sending the event with kAENoReply.
  2. If you want to do this from within your application and don't want to go through the trouble of building up the proper AppleEvents to send to the Finder, you can pre-compile the above script and use OSALoadExecute() to invoke it. You can pre-compile the script and use OSALoadExecute() to invoke it. This is covered in Inside Macintosh - Interapplication Communication pages 10-61 thru 10-63.

These two methods will deselect ALL icons that are selected in the Finder. On the other hand, if you only want to deselect the icon for a particular item, you would need to ask the Finder for the selection, walk through the list of selected items, remove your item, then set the selection to the resulting list. Check out the develop issue 20 article "Scripting the Finder From Your Application" for details on getting and setting the Finder selection. An alternate way of performing the action would be to build an Apple event procedurally and send the event by calling AESend.


[Jul 11 1997]