A scripted solution for getting file icons (Mac only)

Terry Judd tsj at unimelb.edu.au
Mon Mar 16 06:39:52 EDT 2009


On 16/03/09 8:49 PM, "Mark Schonewille" <m.schonewille at economy-x-talk.com>
wrote:

> Hi Terry,
> 
> I did this too, a few years ago. The problem I'm still having is that
> it only works if a corresponding icns file is available somewhere on
> disk. My solution didn't work with applications that aren't
> application packages. Does your solution work with applications that
> are not applications packages (such as MS Office 2004 applications)?

Hi Mark - it should work with apps that aren't packages. It uses the
getResources and getResource functions to check for the existence of an icns
resource inside the app and extracts that.

Terry...

> 
> --
> Best regards,
> 
> Mark Schonewille
> 
> Economy-x-Talk Consulting and Software Engineering
> http://economy-x-talk.com
> http://www.salery.biz
> Dutch forum: http://runrev.info/rrforum
> 
> Snapper Screen Recorder is now available for Windows! Download it at
> <http://snapper.economy-x-talk.com
>> .
> 
> On 16 mrt 2009, at 10:42, Terry Judd wrote:
> 
>> I really didn't think this was possible until I stumbled across the
>> AppleScript 'Image Events' dictionary a couple of days ago but here
>> (below)
>> is a scripted solution for creating a PNG image of a file's icon
>> based on
>> its filepath. It uses a couple of applescript snippets plus the revXML
>> external to parse application pList files but you could undoubtedly
>> forgo
>> the XML external with a bit of extra scripting effort.
>> 
>> The getIconToFile_Mac function has 4 parameters...
>> 
>> # pSourceFilePath = path of the file you're getting the icon of
>> # pDestFilePath = path of the image file you're creating
>> # pIconSize = pixel dimensions of output image (e.g. 16 or 32 etc)
>> # pReturnImageData = true or false/empty - if true the image
>> contents are
>> returned by the function
>> 
>> The routine works on files and applications (including application
>> bundles)
>> and the output is a PNG image which retains transparent regions and
>> is ready
>> to be sucked up into your project.
>> 
>> There doesn't seem to be any way to capture 'standard' volume and
>> folder
>> icons (custom folder and volume images are possible) so I've left
>> them out
>> for now.
>> 
>> I've included a couple of drag and drop handlers that you can place
>> in an
>> image object to test the routines out.
>> 
>> Anyway, I hope this is useful to someone (it's a bit long and
>> messy). Feel
>> free to improve or modify as you see fit.
>> 
>> --  
>> ####################################################################
>> -- ## create an image and put the following 2 handlers in its script
>> ##
>> -- ## watch out for line wraps
>> ##
>> 
>> ON dragEnter
>>  set the acceptdrop to true
>> END dragEnter
>> 
>> ON dragDrop
>>   put dragData["files"] into tFile
>>   IF tFile = "" THEN
>>      put dragData["text"] into tFile
>>      if tFile is not empty then
>>         if not ((there is a folder tFile) and char -4 to -1 of tFile =
>> ".app") then
>>            exit dragDrop
>>         end if
>>      else
>>         exit dragDrop
>>      end if
>>   end if
>>   get getIconToFile_Mac(tFile,,128,true)
>>   if it contains "error:" then
>>      put "" into me
>>   else
>>      put it into me
>>   end if
>> END dragDrop
>> 
>> -- ###############################################################
>> -- ## put the following 2 functions in the card or stack script ##
>> -- ## watch out for line wraps                                  ##
> 
> <snip>
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription
> preferences:
> http://lists.runrev.com/mailman/listinfo/use-revolution




More information about the use-livecode mailing list