• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Get default icon of document/etc programmatically (Applescript-users Digest, Vol 2, Issue 758)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Get default icon of document/etc programmatically (Applescript-users Digest, Vol 2, Issue 758)


  • Subject: Re: Get default icon of document/etc programmatically (Applescript-users Digest, Vol 2, Issue 758)
  • From: Jonathan Levi MD <email@hidden>
  • Date: Tue, 15 Nov 2005 22:21:56 -0500

On Sun, 13 Nov 2005 16:48:59 -0500, Kevin Walzer <email@hidden> wrote:
Does anyone know if it's possible to get the default icon of a
file/application/folder via AppleScript? I know there are functions at
the C level in Carbon for this, but I'd rather access it in AS if possible.

I once managed to get it using System Events and the image from the item's Info window, as is shown in the script below. It shows the icon in the window of the Clipboard and gets the icon data as a one-item list, {picture:«data...»}.


Perhaps someone else on this list knows how to manipulate that picture data directly. If not, once one has the picture on the clipboard, there are other ways to convert it to a graphic file. I can supply details on line or off if you're interested.

HTH,

Jonathan

--------------------------------------------------------------------------------
(*
getPictureInInfoFileIcon.scpt
Script to get the picture in the "General Info panel" of an item's info window.
Shows the icon in the Clipboard's window and gets the picture data as result.
JL 1/24/2005; revised 11/15/2005
*)

set theItem to getYourFinderItem()
SelectItemsInfoFileIcon(theItem)

on getYourFinderItem()
set itemType to button returned of (display dialog ¬
"Show Info window of what kind of item?" buttons {"Cancel", ¬
"Folder", "File"} default button "File")
if itemType is "File" then
set theItem to choose file with prompt "Show Info window of which file?"
else
set theItem to choose folder with prompt "Show Info window of which folder?"
end if
end getYourFinderItem


on SelectItemsInfoFileIcon(theItem)
   tell application "Finder"
      open information window of theItem
      tell front information window
         set current panel to General Information panel
         activate
         tell application "System Events" to tell process "Finder"
            keystroke tab -- should select the icon; if it doesn't, then:
            if enabled of menu item "Copy" of menu "Edit" of ¬
               menu bar 1 is false then repeat until ¬
               enabled of menu item "Copy" of menu "Edit" of ¬
               menu bar 1 is true
               keystroke tab
            end repeat
            keystroke "c" using command down
            keystroke "w" using command down --close info window
            click menu item "Show Clipboard" of menu "Edit" of menu bar 1
            tell application "Finder" to ¬
               get the clipboard --result <- picture data
         end tell --System Events
      end tell
   end tell
end SelectItemsInfoFileIcon
--------------------------------------------------------------------------------

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Get default icon of document/etc programmatically (Applescript-users Digest, Vol 2, Issue 758)
      • From: Jonathan Levi MD <email@hidden>
  • Prev by Date: Web text to word
  • Next by Date: Re: Adobe InDesign placing text or picture box on a layer? -> apply object style
  • Previous by thread: Re: Web text to word
  • Next by thread: Re: Get default icon of document/etc programmatically (Applescript-users Digest, Vol 2, Issue 758)
  • Index(es):
    • Date
    • Thread