Strings in Applescript depends on the system language - are there universal names?

二次信任 提交于 2019-12-22 00:34:01

问题


I write some Applescripts that are gonna be deployed on machines set to different languages. I just realised that when I, for example, is waiting for an application to open a window (e.g., a Save/Open dialog) my scripts fail because on systems set to other languages these windows are not called Save or Open anymore, but rather have a translated name.

How do I handle this? Do windows have "universal base name" I can look for rather than the name I Accessibility Inspector shows? And I guess there are other strings that also are translated that I might need to access (menus, menu commands and so on) - my problem is not limited to just Open/Save dialogs.


回答1:


AppleScript supports NSLocalizedString (localized string). You need to refer to and pull out the strings from the corresponding framework bundles.

For example:

set finderPath to path to application "Finder"
(localized string "A16" in bundle finderPath)

The result is:

  • in English: You can’t undo this action.
  • in German: Diese Aktion kann nicht widerrufen werden.

localized string has two optional parameters:

  • from table : The name of the strings file excluding the “.strings” suffix (default is “Localizable”)
  • in bundle : An alias or file reference to the bundle containing the strings file (default is the current application/script bundle)


来源:https://stackoverflow.com/questions/42638429/strings-in-applescript-depends-on-the-system-language-are-there-universal-name

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!