Re: Get default icon of document/etc programmatically (Applescript-users Digest, Vol 2, Issue 758)
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: Wed, 16 Nov 2005 14:18:59 -0500
At 10:21 PM -0500 11/15/05, Jonathan Levi MD wrote:
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 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...»}.
Actually, the script returns more than I
realized: the data returned from the clipboard
isn't merely a {picture:«data...»}, but a
{picture:«data...», «class icns»:««data
icns...»}. The second item actually contains the
data for the icon class, formatted as a
hexadecimal stream. Delete the initial "icns"
from the stream, convert the remainder from hex
to binary, and save it as a file <filename>.icns.
This file can be opened by Apple's Icon Composer,
etc.,
------------------------------------------------------------------------------(*
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