Monday, July 4, 2022

#1 2021-12-23 03:14:00 pm

Titanium
Member
From:: ~/Desktop
Registered: 2005-08-22
Posts: 84
Website

Change the image size in a menu

Hello,

With Xcode:

In a menu, I display an image with the iconForFile method.
Is it possible to reduce the size of this image?

Applescript:


# For example:
set itemMenu to current application's NSMenuItem's alloc()'s init()

set theImage to current application's NSWorkspace's sharedWorkspace()'s iconForFile:"/Applications"
itemMenu's setImage_(theImage)

itemMenu's setTitle_("Applications")
itemMenu's setAction_("menubarApplications:")
itemsMenuBar's addItem_(itemMenu)
...

menu.png


Thanks!


iMac 27" 3,6 Ghz - MacBook Pro 14" M1 - MacOS  Monterey
https://www.titanium-software.fr

Offline

 

#2 2021-12-23 03:47:05 pm

Mark FX
Member
From:: UK
Registered: 2011-08-12
Posts: 162

Re: Change the image size in a menu

The documentation for the NSWorkspace's 'iconForFile:' function, says the the returned NSImage is initially returned at 32 x 32 pixels, so as it's an NSImage, you could change it with one of the NSImage's function's, like this.

Applescript:


set theImage to current application's NSWorkspace's sharedWorkspace()'s iconForFile:"/Applications"
theImage's setSize:(current application's NSMakeSize(16, 16)) --16 x 16 pixels

Regards Mark

Last edited by Mark FX (2021-12-23 03:48:24 pm)

Offline

 

#3 2021-12-23 03:50:42 pm

Titanium
Member
From:: ~/Desktop
Registered: 2005-08-22
Posts: 84
Website

Re: Change the image size in a menu

Great!!

Thanks a lot Mark! smile


iMac 27" 3,6 Ghz - MacBook Pro 14" M1 - MacOS  Monterey
https://www.titanium-software.fr

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)