Monday, July 4, 2022

#1 2021-12-10 08:35:03 am

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

Space before a menu item containing an image

Hello,

Is it possible to add a space before a menu item containing an image?

Applescript:


set itemsMenuBar to current application's NSMenu's alloc()'s init()

set theImage to current application's NSImage's imageNamed:"icnutilities"
itemMenu's setImage_(theImage)

itemMenu's setTitle_("Utilities")
itemMenu's setAction_("menubarUtilities:")
itemsMenuBar's addItem_(itemMenu)

Thanks a lot!


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

Offline

 

#2 2021-12-10 02:18:19 pm

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

Re: Space before a menu item containing an image

I would like to help you, but I don't understand You're question.

are you working in Xcode with a xib file ?
Or are you creating the menu user interface in code in Script Editor ?
You're using an object named "itemMenu", where is this object created ?
Is the menu item a sub menu of of an application's main menu ?

As I understand it the menu item is suppose to have an image and a title.
is the image left or right of the title ?

Do you meen a separator bar, and not a space ?

Regards Mark

Last edited by Mark FX (2021-12-10 04:31:50 pm)

Offline

 

#3 2021-12-10 05:32:41 pm

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

Re: Space before a menu item containing an image

Sorry...

Yes it's a project in Xcode.

Do you meen a separator bar, and not a space ?


Not a separator bar, It's just an interval before the image (see the screenshot). Sorry for my bad English...

Applescript:


set itemsMenuBar to current application's NSMenu's alloc()'s init()

set itemMenu to current application's NSMenuItem's alloc()'s init()
set theImage to current application's NSImage's imageNamed:"icnapps"
itemMenu's setImage_(theImage)
itemMenu's setTitle_("Applications")
itemMenu's setAction_("menubarApplications:")
itemsMenuBar's addItem_(itemMenu)

set itemMenu to current application's NSMenuItem's alloc()'s init()
set theImage to current application's NSImage's imageNamed:"icnutilities"
itemMenu's setImage_(theImage)
itemMenu's setTitle_("Utilities")
itemMenu's setAction_("menubarUtilities:")
itemsMenuBar's addItem_(itemMenu)

Thanks!

image.png


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

Offline

 

#4 2021-12-10 05:45:41 pm

technomorph
Member
Registered: 2017-12-14
Posts: 254

Re: Space before a menu item containing an image

I think you need to set the imageAlignment property.
If you view a menuItem in interface builder it will show you
The available options.  Such as trailing, leading, left, right etc.

https://developer.apple.com/documentati … guage=objc

Offline

 

#5 2021-12-10 05:47:45 pm

technomorph
Member
Registered: 2017-12-14
Posts: 254

Re: Space before a menu item containing an image

Offline

 

#6 2021-12-10 06:25:05 pm

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

Re: Space before a menu item containing an image

I understand now!

I don't have access to "Monterey", so you may need help from those who do.

But this should work for you.

Applescript:


set itemsMenuBar to current application's NSMenu's alloc()'s init()
set theImage to current application's NSImage's imageNamed:"icnapps"

set itemMenu to current application's NSMenuItem's alloc()'s initWithTitle:"Utilities" action:"menubarUtilities:" keyEquivalent:"u"
itemMenu's setImage:theImage
itemMenu's setIndentationLevel:2
itemMenu's setTarget:me
itemsMenuBar's addItem:itemMenu

The "indentationLevel" parameter is not documented very well, but can be a integer value between 0 and 15, but the Apple documentation doesn't inform how this value relates to the screen resolution or dimensions, so experimentation might be needed for different screen resolutions.

Regards Mark

Last edited by Mark FX (2021-12-10 06:57:26 pm)

Offline

 

#7 2021-12-10 11:58:32 pm

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

Re: Space before a menu item containing an image

Hello,

Great!!

you're the best, it's perfect.
Thanks Mark FX, thanks technomorph!

cool


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)