Disable substitution in Lion - cocoa

My Cocoa application uses NSTextView. It is sort of an editor application. Now in 10.6 there is character substitution so (c) becomes copyright. My application was not doing the substitution in 10.6. And I did not add any additional code for that. But in 10.7 the substitution is taking place. This is causing confusion to clients who have just migrated to lion. I know that I can write an applescript to disable the checkbox in language and text. But is there any other option ?.
I also tried
defaults write -g WebAutomaticDashSubstitutionEnabled -bool false.
but this also did not work.

In Cocoa, the substitutions feature is called “automatic text replacement”. To disable it in an NSTextView, send the text view a setAutomaticTextReplacementEnabled: message.
You should consider whether it's really appropriate to disable that in your application, though. If your editor is intended to be used on code or data files, then yes, you probably should disable it. If it's for editing text files, however, it's probably better to leave it set to the default and let users discover the feature on their own (and turn it off themselves if they don't want it). If your application is a text editor that may be used on text or code, you can probably set it based on what format the file is in—for example, enable it for Markdown but disable it for Python.
The WebAutomaticDashSubstitutionEnabled preference is not relevant because, as its name says, it's a WebKit feature. NSTextView is part of AppKit and does not use WebKit. Also, automatic dash substitution, which is supported in NSTextView as well, is a different feature.

Related

Setting Default Keyboard Layout for Electron Application on Windows (Unable to copy UTF-8 text propely)

We have this problem where a Farsi UTF-8 text that is programmatically copied from an electron application, loses encoding when pasted into one specific application and is displayed as a set of ? characters. The issue persists even with manual text selection and copy command invoked via either context menu or Ctrl+C. Texts copied from other sources such as browsers or text editors are transferred just fine.
We tried clipboard API of electron. We also implemented our own helper to verify the issue is not with the clipboard itself.
We also prepended the text with UTF-8 BOM character before writing it to the clipboard.
One interesting observation was that once the text is pasted into some text editor and then recopied, target app received the text properly. We also noticed that changing the keyboard layout to target language when the electron app is focused, resolves the issue as well. In addition, we realized that Windows changes default keyboard layout to English when the application is launched.
Following on these clues, we configured NSIS bundler to set the default language to Persian so that maybe Windows detects it as default keyboard language as well. Description of the application shows Persian as the language but Windows does not respect it and reverts the language to system default upon launch.
We tried running a script on application startup to mimic a Farsi character keyboard input, creating temporary input fields, and a set of other hacks to maybe trick the Windows/application into properly handling these texts. Keep in mind we can't rely on user to perform idiotic actions on every application launch, to fix a problem that shouldn't exist in first place. That's why we need this issue to be resolved programmatically.
Right now the only solution that comes to mind is to force Windows to set the keyboard layout for our application to Persian via registry entries by some separate script that user need to run only once, or can be run after each installation. I'm not familiar with the windows registry entries. My searches came up empty and the results were focused on how to do it for the whole system, but we don't wanna mess with their whole system configurations since.
Any other suggestions regarding this issue is highly appreciated.
Other information that you might find relevant:
OS is Windows 7.
Target app is an accounting software and the vendor rejects to provide any support with the integration, so I have very little information about inner workings of that application.
html lang attribute of electron template is set to fa.
meta charset attribute is set to utf-8.
Application is bundled with electron-builder and NSIS.

Trouble making customized DefaultKeyBinding.dict work throughout

I'm running OS X 10.11. I've been creating customized key binding by editing my ~/Library/KeyBindings/DefaultKeyBinding.dict file, and I've successfully got a bunch of emacs-like shortcuts to work in parts of some applications, but for the most part, my User-specific keybindings have been overridden by app-specific shortcuts.
For example, Command-a in Mail moves to the beginning of the line. But Command-a in textedit or notes doesn't move to the beginning of the line. Instead, it selects all. Command-e moves to the end of the line (as I want it to), I'm guessing because Command-e is not already a predefined app-specific shortcut...
Anybody had experience with this problem? My understanding was that any bindings defined in DefaultKeyBinding.dict were supposed to supersede app-specific bindings...
Thanks!
Nope, afaik app specific shortcuts supersede global ones. Also, personally I think it's better to use ctrl+KEY for navigation and remap the existing ones. See OS X Human Interface Guidelines for Keyboard Shortcuts and the official os x shortcuts.

How can I turn off OS X's Smart Quotes replacement in my WKWebView?

I'm developing a Mac application that contains a WKWebView. The HTML in the web view contains an input field into which the user types code (Ruby, in fact). When I type a quote (") into this field, it is automatically turned into a fancy curly quote (“). Since Ruby strings use ASCII quotes as delimiters this is wrong.
At the moment I'm taking what the user enters and substituting from curly quotes to ASCII quotes before using the code, but obviously this is not ideal.
I can't figure out how I can disable this OS X feature. Obviously it's possible for the user to do in System Preferences at a global level, but I just want to turn it off in my app.
Is there some configuration on the WKWebView, or on the app bundle itself, or somewhere, that can turn this off? Is there an HTML or CSS option? Should I be using a different type of HTML input field? Basically where in the whole stack can I intervene to turn this feature off?
When you toggle the setting in System Preferences (Keyboard > Text > Use smart quotes and dashes), it sets a value for the key NSAutomaticQuoteSubstitutionEnabled in the user's global preferences domain. I determined this by comparing the output of defaults read -g from before to after.
You can try setting that to false for your app domain early in your app's start-up to see if that disables it for your app:
[[NSUserDefaults standardUserDefaults] setBool:NO forKey:#"NSAutomaticQuoteSubstitutionEnabled"];
Try that in -applicationWillFinishLaunching: or even main().
Of course, if that works it will disable it throughout your app, rather than just your WKWebView.
After some experimentation while having this issue with a <textarea> in a web view, I found out that the smart/fancy quotes replacement will be disabled by adding the spellcheck attribute.
<textarea spellcheck="false" ...>
AFAIK it is (at the writing moment) not documented anywhere and MDN currently makes no mention of spellcheck attribute "auto correcting" quotes. I'd imagine autocorrect or autocapitalize would do this, but setting these in context of a web view doesn't apparently do anything.
Since I was working on a React app at the time, the attributes are camel-cased and in that case it is <textarea spellCheck="false" ...> instead.
If you're using Xcode's Interface Builder, open up the the utilities pain with your textfield/textbox selected. Under 'Attributes Inspector' you are able to set the Keyboard Type to ASCII.
To do so programmatically, checkout this previous question & answer.

Intellisense in notepad++

It is possible configure notepad++ to the Intellisense show options about firefox os api?
e.g. To can see all methods
var battery = navigation.battery;
battery.level;
I don't know if this is exactly what you're looking for, but Notepad++ (current releases) have a form of this known as AutoComplete - go to Settings > Preferences > Auto-completion and tick the enable auto-completion for each input* button.
As for the Firefox OS API specifically, I don't know if that works. But I know you can achieve the intellisense effect with languages themselves, anyway.
Keep in mind the differences between "Function Completion" and "Word completion" inside auto-complete: Function Completion uses external cues to tell you exactly what you're trying to write in, as it autocompletes functions from an API.
Word completion meanwhile may be more helpful in your case; If Firefox OS API can't be worked into NPP, you can at least auto-complete functions that you've already written into your script, as Word completion scans your document and suggests words that already exist; It's sort of useful as a text expansion engine.
I hope I've been of help; Best of luck to you.

OSX Application or Web App for converting text to plain text (unicode)

I am looking for ways to quickly converting blocks of text created in Word, etc. into plain text (i.e. turning right and left quotation marks into "plain text" quotation marks) for quickly transferring content to code with as few headaches as possible.
I came across this:
http://www.softpedia.com/get/Office-tools/Other-Office-Tools/Keith-Fenske-Plain-Text.shtml
...but it is Windows only and I prefer to dev on a Mac. Does anyone have a suggestion for an OSX tool or better yet a web app?
If you're using Snow Leopard, it's easy to create a Service to clean text. Run /Applications/Automator, choose the Service template, set it to receive text in any application, and enable replacing the selected text. Add a Run Shell Script action to the workflow, with Pass Input set to stdin. For the actual script, paste this in in place of the template (cat):
LC_CTYPE=en_US.UTF-8 tr '‘’‛❛❜“”‟❝❞‐–—­‒‑' "['*5]"'["*5][-*6]'
(note: hopefully all the various funny characters I included in the first string will pass through our various web interfaces intact... if not, edit the collections of quote marks to include whatever you need to squash in the first string, and matching numbers of their plain-text equivalents in the second string. And feel free to add other replacements as needed.)
Anyway, save this Service with some reasonable name, and then to invoke it just select some text (in any Cocoa app -- not, unfortunately, MS Word), and select your service from the application menu -> Services submenu. Also, you can use the Keyboard preference pane to assign it a keyboard shortcut if you like.
Text Wrangler from Bare Bones Software. This is BBEdit's free little brother (which will also do what you want).
The "Plain Text" Java application will run on Linux, Mac OS, and Windows.

Resources