You are not logged in.
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
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
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!
iMac 27" 3,6 Ghz - MacBook Pro 14" M1 - MacOS Monterey
https://www.titanium-software.fr
Offline
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
Oh sorry look
At indentationLevel
https://developer.apple.com/documentati … guage=objc
Offline
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
Hello,
Great!!
you're the best, it's perfect.
Thanks Mark FX, thanks technomorph!
iMac 27" 3,6 Ghz - MacBook Pro 14" M1 - MacOS Monterey
https://www.titanium-software.fr
Offline