Get the folder's icon path

Hello,


I need to get the path of a folder's icon to do a thing, but I don't know where the icons are located.

Can anyone help me?


Thanks!

Posted on Sep 1, 2014 4:20 AM

Reply
20 replies

Sep 3, 2014 5:57 AM in response to Matteo_999

Hi,


Matteo_999 wrote:


Just a thing, the icon of the folder is pretty small, is there a way to make it bigger? T

Because the returned image has an initial size of 32 pixels by 32 pixels.

You can increase the size of the image with setSize, like this:


set myImage to current application's NSWorkspace's sharedWorkspace()'s iconForFile:posixPath -- get an image of 32 pixels by 32 pixels
myImage's setSize:{256, 256} -- resize the image to 256 pixels by 256 pixels

Sep 3, 2014 7:29 AM in response to Frank Caggiano

Hi Frank, this is what i've done so far:


1) Create a new AppleScriptObjC file and name it as you want, mine is MSDropBox

User uploaded file

2) Replace all the code with the following:


--

-- MSDropBox.applescript

-- Sync Folders

--

-- Created by Matteo La Mendola on 19/08/14.

-- Copyright (c) 2014 Matteo La Mendola. All rights reserved.

--

script MSDropBox


propertyparent : class"NSBox"

property theItem1 : missing value

property dropBox1 : missing value

property theURLs : missing value

on draggingEntered_(sender)

log "entered"

set pb to sender's draggingPasteboard()

set theOptions to {NSPasteboardURLReadingFileURLsOnlyKey:1}

return pb's canReadObjectForClasses_options_({current application's |NSURL|}, theOptions)

end draggingEntered_

on performDragOperation_(sender)

log "perform"

-- Get the file paths

set pb to sender's draggingPasteboard()

set theOptions to {NSPasteboardURLReadingFileURLsOnlyKey:1}

set theURLs to pb's readObjectsForClasses_options_({current application's |NSURL|}, theOptions)

log theURLs

set theURLs to theURLs's valueForKey:"path"

set theURLs to theURLs as list

current application's NSApp's delegate()'s wasDropped_sender_(theURLs, me)

returntrue

end performDragOperation_


endscript


3) Make a new outlet in the AppDelegate named dropBox1

4) Drag an NSBox into your XIB file and connect dropBox1 as outlet

5) Go to the AppDelegate.applescript file and insert this code in the applicationWillFinishLaunching handler:

on applicationWillFinishLaunching_(aNotification)

my dropBox1's registerForDraggedTypes_({"public.file-url"})

end applicationWillFinishLaunching_


6) In the AppDelegate insert this handler:

on wasDropped_sender_(itemDropped, sender)

log itemDropped

if sender's title() as text = "Box1" then

log "dropBox1"

else

log "dropBox2"

end if

end wasDropped_sender_


The if statement is only if you have more than one box


7) Select MSDropBox as custom class of the NSBox


User uploaded file



And that's done!

This is how mine looks like:

User uploaded file

User uploaded file

Reply for any question 😉

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Get the folder's icon path

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.