How to get NSImage.Name.cautionName
in AppleScriptObj.
I tried:
set cautionName to aN of NSImage.Name
but that does not work.
It looks like what you are after is NSImageNameCaution, which is a constant for the name of a system image. Your example (and link) appear to be using Swift, changing the documentation language to Objective-C gives you the proper term.
AppleScriptObjC uses names from the Objective-C documentation (it also does not use dot notation), so it would be something like:
use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "AppKit"
use scripting additions
# get the name
set imageName to (current application's NSImageNameCaution) as text
# get the image
set theImage to current application's NSImage's imageNamed:(current application's NSImageNameCaution)
It needs pipes to indicate that it is method
set cautionName to (anImage's |name|()) as text
NOTE: if the Image has not the associated name, then of course you will get missing value.
Related
Background
I am working on an AppleScript application (ASOBJ) through Xcode and frequently access (update/retrieve) various entries from a .plist file that I have created.
Whenever I need to access the data, I use the following command:
set thePropertyListFilePath to POSIX path of (path to resource "Data.plist")
tell application "System Events"
tell property list file thePropertyListFilePath
set myAge to value of property list item "userAge" as text
end tell
end tell
The problem
My project is in development and file names / paths change all too frequently.
I want to make a property thePropertyListFilePath : [...] at the top of my project to be able to change the path and name of the file in one place, rather than multiple.
I would like to use property over set as it just works better in my case.
At the top of my code:
property thePropertyListFilePath : POSIX path of (path to resource "Data.plist")
Does not compile because:
Error: Resource not found.
Analysis
I know for a fact that the resource Data.plist is where it is supposed to be and the paths correct because it works fine from inside my top code snippet.
Leaving me with the question:
How do I set a property to a file path?
Any insight into why this error is thrown and how to correctly set the property to this (relative) file path is greatly appreciated. I am aware of this question, but it does not present an applicable solution. Cheers.
Edit
I now seem to be getting a related error:
System Events got an error: 'This
Mac:Users:myuser:Library:Developer:Xcode:DerivedData:ProjectName:Build:Products:Debug:ProjectName.app:Contents:Resources:Data.plist'
is not a property list file. (error -1728)
Some validation needs to take place before app has launched so I wrote my code in the applicationWillFinishLaunching_ section - this shouldn't present any problems.
I know that the file is there and a .plist format so I am thinking it could simply be the tell ... statements around it.
In the past, I used set currentVersion to (current application's class "NSBundle"'s mainBundle()'s objectForInfoDictionaryKey:"CFBundleShortVersionString") as text to access the version number from the Info.plist in one go. Is it possible to use a similar one-liner without the tell statements to retrieve userAge from my own plist file?
Don't do that. Never declare a property with a relative path. The value will set at compile time and will never change. That makes the benefit of the relative path useless.
Declare the property as empty string
property thePropertyListFilePath : ""
and set it in applicationDidFinishLaunching
on applicationDidFinishLaunching_(aNotification)
set thePropertyListFilePath to POSIX path of (path to resource "Data.plist")
end applicationWillFinishLaunching_
However as you are developing AppleScriptObjC I recommend the Cocoa way (longer but more efficient)
set thePropertyListFilePath to (current application's NSBundle's mainBundle()'s pathForResource_ofType_("Data", "plist")) as text
I want to localize buttons of MesssageBox, MessageDlg, InputQuery, etc.
I see resourcestring exist for this in lclstrconsts: "OK"/"Cancel".... but I want to set button strings using asssignments.
How to do it?
I need it on Win32. I see that German/Rus OS shows En buttons.
That's how it is done for MessageDlg: http://delphi.xcjc.net/viewthread.php?tid=47562.
Variables with rs prefix should be defined.
Other components could be localized the same way.
There are several articles in the wiki about localization:
Translating/Internationalization/Localization
In short:
Set "Enable i18n" at the project options -> i18n, set PO Output Directory (locale for example)
Recompile project
Copy created yourproject.po file to yourproject.de.po, yourproject.it.po and so on for desired languages into the same directory.
Copy to locale directory of your project *.po files from lazarus/lcl/languages to translate LCL.
Add unit LCLTranslator to the uses clause of your main form.
Call SetDefaultLang('it'); somewhere to set desired translation (Italian in this example). Check is all Ok by inspecting GetDefaultLang function result.
Note that (3) is required.
You may find ready to use POs in other thirdparty libraries if any.
Installer.ProductInfo is this.
I take this script, and I want to get various information (ex: UpgradeCode), where I can see all parameters, witch I cat set instead of "Version" (here installer.ProductInfo(product, "Version")). Yes, I see For Each property In Array..., but it is not enough for me (where "UpgreadeCode"?)). And where did this Array?
For a full list of supported properties check the description of the szProperty parameter of the MsiGetProductInfo function.
Most properties in this article are specified using predefined constants (e.g. INSTALLPROPERTY_HELPLINK instead of "HelpLink"); the actual string names of these properties are defined in the msi.h header file that is part of Windows SDK. A copy of msi.h v.4.0 can also be found online here.
Is there a reliable way to identify the filetype of a file across Windows platforms?
I've inherited a program which queries filetypes using the Shell32 GetDetailsOf function, which returns localized strings and causes an error if a non-english system is used (for example, on a german system GetDetailsOf(item,9) returns "Bild" instead of "Image").
Using the textual description of a filetype is not a reliable way of identifying particular types of file. As you've noticed the description strings change from language to language, but they can also change within the one language depending on the software the user has installed (as a made up example, a .jpg file might have the description "JPEG image" on one system, and "Adobe Photoshop Image" on another system if the user has installed software that claims the filetypes and changes the description).
Instead, your best way of identifying the filetype is to look at the file's extension (.jpg in our example). What you do with it then is up to you and depends on your application. You might just have a hard-coded list of extensions that you work with, or to be more generic you could look in the registry for the filetype's "perceived type":
HKEY_CLASSES_ROOT\.jpg\PerceivedType
To see if that value is set to "image", "audio", etc.
I am using Doxygen for generating documentation for my project, which generates docsets that work almost perfectly with dash.
What I want to know is how to set the search keyword in dash; the default is "unknown:"
What do I need to change so that it reads something other than "unknown:". Can I change this in Doxygen?
I'm Dash's developer. Dash uses the DocSetPlatformFamily key in the Info.plist file inside the docset to determine the default keyword. Unfortunately, Doxygen has no option as far as I'm aware to set this value. I will contact the Doxygen team and ask them to add this option. Feel free to do the same.
For now, my best recommendation would be to write a post-generation script that would add the required key in the Info.plist file (it's just a text file).
For example, this should work:
perl -pi -w -e "s/<\/dict>/<key>DocSetPlatformFamily<\/key><string>__DESIRED KEYWORD__<\/string><key>DashDocSetFamily<\/key><string>doxy<\/string><\/dict>/s" Info.plist
Note: I've also added a "DashDocSetFamily" entry with a value of "doxy". This will cause Dash to handle the docset as a Doxygen-generated one and display the filterable table of contents.
In case you haven't found them already, here are some recommended settings for generating a Doxygen docset for use in Dash:
SEARCHENGINE = NO
DISABLE_INDEX = YES
GENERATE_TREEVIEW = NO