admin管理员组文章数量:1026989
I’m working on a menubar extra, and I would like to fetch the name of the current application. I have the following code:
var app: NSRunningApplication = NSWorkspace.shared.frontmostApplication!
var bundleIdentifier: String = app.bundleIdentifier!
var name: String = app.localizedName!
var icon: NSImage? = app.icon
The code mostly works, but in a few cases, the localizedName
property is an empty string. The other properties aare fine.
I can’t find any other property which has the application name. One such application is SQLPro for SQLite which is a legitmate App Store application. It clearly has name which appears in all the right places except as above.
Is there an alternative way of getting the application name?
A Possible Solution
Thanks to @Sweeper, I’ve got something that works:
let bundle: Bundle = Bundle(url: app.bundleURL!)!
let appName: String = app.localizedName!.isEmpty ? bundle.infoDictionary!["CFBundleName"]! as! String : app.localizedName!
I’m working on a menubar extra, and I would like to fetch the name of the current application. I have the following code:
var app: NSRunningApplication = NSWorkspace.shared.frontmostApplication!
var bundleIdentifier: String = app.bundleIdentifier!
var name: String = app.localizedName!
var icon: NSImage? = app.icon
The code mostly works, but in a few cases, the localizedName
property is an empty string. The other properties aare fine.
I can’t find any other property which has the application name. One such application is SQLPro for SQLite which is a legitmate App Store application. It clearly has name which appears in all the right places except as above.
Is there an alternative way of getting the application name?
A Possible Solution
Thanks to @Sweeper, I’ve got something that works:
let bundle: Bundle = Bundle(url: app.bundleURL!)!
let appName: String = app.localizedName!.isEmpty ? bundle.infoDictionary!["CFBundleName"]! as! String : app.localizedName!
本文标签: Getting the name of the current application on macOS SwiftStack Overflow
版权声明:本文标题:Getting the name of the current application on macOS Swift - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745665989a2162179.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论