NSTextField and Opt+Enter etc for forcing multiple lines - A bug or Feature? - macos

While developing an application, I am asked to remove multi-line text inputs from NSTextField - Which I did.
Again they said users are able to paste multiline texts, then I disabled ⌘+V.
From here...
I have a confusion... Why NSTextField allows opt + Enter and other key shortcuts (like hacking) to insert a new line character. I read somewhere that it is a feature not a bug, but I am unable to find that link.
Is the above correct, and is it mentioned any where in Apple Documentation?

This behavior is documented (or at least mentioned as a feature of NSTextField) here in the Mac developer library: https://developer.apple.com/library/mac/qa/qa1454/_index.html

Here's another doc reference: Working with the Field Editor. Specifically, it says "Users can easily put newline characters into a text field by pressing Option-Return or Option-Enter."

Related

Applescript: Detect double instances

Here's how a text document in Apple Pages might be structured:
CHARACTER #1: Dialogue
CHARACTER #2: Dialogue
CHARACTER #1: Dialogue
Action description.
CHARACTER #1: Dialogue
My question:
Using Applescript, is there a way to detect that the last two dialogue entries stem from the same character, even though there is an action description in between?
CHARACTER names are defined by a paragraph style and always appear in ALL CAPS.
Many thanks for your time!
Disappointingly, the more recent versions of Pages (like 5.5.2, which I have right now) are very limited in AppleScript support. One should be able to access specific properties of paragraphs, including paragraph style (this seemed to be possible in past versions, 5-6 yrs ago), but this is not possible. You'd be better off exporting as an rtf (for example) and using a more complete script-able app -- but guess what? Pages doesn't even support exporting to RTF.
A quick bit of advice: If you do end up exporting as Word document, use the older "doc" version instead of the "docx" (under 'Advanced' setting in export), or at least test between them. docx can kill screenplay-formatted documents (which you seem to be working with).
I'd also suggest that you be more specific with your question, like what the style consists of, and any code you've actually tried (which is considered basic form here on StackOverflow).

Sublime Text autocomplete suggestions looks corrupt, how to fix?

Not sure what is happening to my installation of Sublime Text, when ever autocomplete drop down appears it is populated with a bunch of corrupted looking suggestions, this just started recently. I have Googled around and have not yet seen another person with the same issue. I've already tried uninstalling, throwing out User/me/Library/Application Support/Sublime Text 3 folder, and re-installing, but still the corrupted text shows up in my autocomplete. I am working on a Macbook Air, I also use a Macbook Pro at work with the same setup and have never seen this happen before?
As established in the comments, you have base64-encoded strings (likely an inline image) elsewhere in your file. Sublime's default autocomplete populates its choices menu with elements from your file, and uses fuzzy matching to bring up selections. Since base64 can contain all letters and numbers, chances are that any sequence you're typing may match, and that string will be brought to the top of the autocomplete dropdown.
There are a couple of ways around this. First, if the base64 content is actually scoped as a string (i.e., it's surrounded by single or double quotes), you can add the following line to your settings (Preferences -> Settings-User):
"auto_complete_selector": "source - comment - string, meta.tag - punctuation.definition.tag.begin"
This should hopefully solve your problem for the time being, with the downside that you lose any other string-encoded information that you may wish to be in autocomplete.
You can also try using an autocomplete engine like SublimeCodeIntel (works for multiple languages, including JS) or TernJS. These can have the option of turning off Sublime's internal autocomplete mechanism, and just filling in the choices with their generated content.

How to disable generating special characters when pressing the `alt+a`/`option+a` keybinding in Mac OS (`⌥+a` )? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 4 years ago.
Improve this question
There is a behavior in my mac that I'm trying to disable.
When I'm in any text editor and typing a key combination using the alt/option+any letter, the output will be special characters.
For example:
the combination alt+a will generate å.
the combination alt+x will generate ≈.
I want to cancel this behavior.
I'm a programmer and when I use my code editor I want to map some keybinding (keyboard shortcuts) to the alt key (⌥+a for example) but when I do that it doesn't execute because it generates the special characters.
I guess that the special character has a priority over my code editor shortcuts.
Do you know how can I disable this default behavior?
Thank you
You can create a custom keyboard mapping with option-letters all set to BLANK using online tool from this webpage. You can create a custom mapping in several clicks out of almost any keyboard layout. Proved to work on MacOSX 10.7+ with IntelliJ Idea, Php/WebStorm, NetBeans, Eclipse.
Select "Set blank for option key" radio in the form, submit the form, and download a patched keyboard layout with "option" key feature disabled. I'm sharing the working file for standard US English keyboard layout:
MacOS <= 10.10
MacOS >= 10.11
After enabling this custom mapping, if you type a letter with "option" key pressed, nothing is printed to text output. But, the "option key press" is triggered by OS, and detected by your IDE. So you get exactly the same behaviour as you have for other command keys!
Download the key mapping file My Layout.keylayout.
Move it to ~/Library/Keyboard\ Layouts/
Open System Preferences -> Language Input Methods (or Keyboard -> Input Sources)
Go to Input Sources -> (hit +) -> Select Others
You should find My Layout in the list and select it.
Step 4 can change slightly across MacOS versions. Please be patient to find keyboard layouts list in the settings.
Here are detailed steps to Sebastian Zaha's answer. (I ended up fumbling around a bit before I got this working).
(Alternatively here is a ready made file by me)
Download Ukelele
You can run it directly from the .dmg file
File -> New Based On Current Input Source (I had US selected)
Click Modifiers button
Select each modifier from list that have Left Down or Right Down in the Option column. (There could be some like Either Down OR Up too, but AFAIK you can leave those.)
Press the minus button for each like this
Go to Keyboard menu -> Set Keyboard Name
Change the name somehow to make it easier to identify
Go to File -> Save as
Save to ~/Library/Keyboard\ Layouts/ with suffix .keylayout
Log out from your Mac OS account
Log back in
Go to System Preferences -> Keyboard -> Input Sources
Hit the + button -> Others -> Your new layout should be available
Add the new layout
Possibly leave original keyboard layout too and configure some nice way to switch
I was having the exact same problem, in the exact same IDE.
The solution to this is to download Ukulele from here:
http://scripts.sil.org/cms/scripts/page.php?site_id=nrsi&id=ukelele
In the application you can create a new keylayout using File -> New from current source. Pressing Option will show you in the place for Option-b a red colored key - meaning it's a dead key. Double clicking it will allow you to change it from a dead key to an output key. When prompted for the output you can put in the same thing (by pressing Option-b).
Thus it will output the same character but will not be considered a dead key, so Intellij can bind it as a shortcut.
To enable your new layout you must save it into your ~/Library/Keyboard Layouts (it helps if you give it a new name with Keyboard -> Set Keyboard Name), and then enable it from System Preferences -> Language & Text.
Use Ctrl-Alt-<MNEMONIC>. IMHO much easier than having to install and configure a separate app.
I had the same issue on a new Macbook with VSCode which had worked fine on my old Macbook. When I typed alt-shift-f for format I got unicode instead. I realised the difference was my old Macbook had a British keyboard setup instead of the default "ABC - Extended". Adding the British keyboard fixed the issue for me.
I have a solution!
Place a file at: ~/Library/KeyBindings/DefaultKeyBinding.dict as:
/* ~/Library/KeyBindings/DefaultKeyBinding.dict */
{
/* Additional Emacs bindings */
"~f" = "moveWordForward:";
"~b" = "moveWordBackward:";
"~<" = "moveToBeginningOfDocument:";
"~>" = "moveToEndOfDocument:";
"~v" = "pageUp:";
"~d" = "deleteWordForward:";
"~^h" = "deleteWordBackward:";
"~\010" = "deleteWordBackward:"; /* Option-backspace */
"~\177" = "deleteWordBackward:"; /* Option-delete */
/* Escape should really be complete: */
"\033" = "complete:"; /* Escape */
}
It will hide the original textual input. But you can still get that by using Ctrl-Q before the combination.
So Ctrl-Q Alt-f gives me ƒ for example.
In fact, I'm writing this answer with the option keybindings enabled.
You can also add other keys you like! Official reference:
https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/EventOverview/TextDefaultsBindings/TextDefaultsBindings.html
Here is a good list of things you can bind to:
https://www.hcs.harvard.edu/~jrus/site/selectors.html
Oh, by the way, if you bind a key to an undefined action, your application will have a memory leak and your system will run out of memory in a few seconds. Tested on el capitan, in the hard way.
Using the Apple JRE, the Option key combinations will work as shortcuts instead of inserting special characters.
Download link:
https://support.apple.com/kb/DL1572?locale=en_US
It's an old outdated JRE (based on Java 6) but as of October 2015 it's still what seems to work best w/ my JetBrains RubyMine installation. (Anything else, the keys go back to inserting special characters.)
Use ABC as input method instead of ABC-Extended, then option + [char] would be able to use the application shortcut instead of showing special character.
I have found a decent workaround.
I use the software Karabiner to change my right enter key to control when held down.
So what iv done is remapped the option key to option+cmd+control, as I'm not aware of any commands that use all three modifiers. Now I can map the right shortcuts without any characters. But you could also map to additional keys if required
Add this to your private.xml: (in between root)
<item>
<name>Change option Key to cmd + control + option</name>
<identifier>private.optiontoelse</identifier>
<autogen>__KeyToKey__
KeyCode::OPTION_L,
KeyCode::OPTION_L, ModifierFlag::CONTROL_L | ModifierFlag::COMMAND_L</autogen>
<autogen>__KeyToKey__
KeyCode::OPTION_R,
KeyCode::OPTION_R, ModifierFlag::CONTROL_R | ModifierFlag::COMMAND_R</autogen>
</item>
Then reload the xml and enable the option at the top of the 'Change Key' tab
https://pqrs.org/osx/karabiner/

Reformatting code in text mate to established code conventions - Visual studio's ctrl K+D equivalent on Text Mate

Can anyone tell me if there's a quick way to format your code in Text Mate, similar to pressing ctrl K+D in Visual studio?
Thanks!
Edit by Damien_The_Unbeliever:
For those not familiar with Ctrl K+D, it doesn't just indent code - it reformats it using the generally established formatting conventions in the editor - it may replace spaces with tabs or vice-versa for the indentation, ensure code is consistently indented, move braces to separate lines, etc.
TextMate reindenting and reformatting varies a little depending on the language you're using.
You can generally use the Text menu, that depending wether you have an active selection or not it will show you different commands under it. For example, if you have selected a section of code, there will be a Indent Selection menu item. If you have no active selection, it will be Indent Line.
To have this working properly, be sure to select the current language, if it isn't assigned yet (like on unsaved documents). If you're working with HTML, it will simply indent the lines depending on what's above it. It will keep line breaks intact.
If you need something to break out tags on new lines and properly format the document, you should use the Tidy command that is found in the Bundles menu, under HTML (or simply by using the shortcut CTRL+SHIFT+H. If you have a selection active at the moment that you use it, it will simply reindent that section. If instead you have no selection, it will properly reformat the whole document, including checking for tag validity and other errors.
The Bundles for other language have similar commands, like XML (still Tidy) and Javascript (that has a Reformat Document command).
As an ending note, I simply suggest to look into the Bundles menu; there are many little gems in it. ;)
Did you look in the menu bar? Under Text you have a couple of Reformat… entries that may fit your needs.
Beside these native features, some bundles — like the JavaScript one — have custom Reformat… commands : click on the little cog button at the bottom and explore your current language's bundle's content.

Generic Xcode usage questions

I have 3 general questions related to the usage of xCode. Any help would be greatly appreciated please:
Whenever I open documentation, the left content/index column is always small and I have to drag it wider. Is there a way to permanently set its size?
Is there a way to perform a wildcard search and replace e.g. I have 3 lines:
var1Letter = #"A";
var2Letter = #"A";
var3Letter = #"A";
In the above I would like to replace var?letter in 1 go.
How do I set the default SDK?
Thanks.
re #2: Xcode can use regular expressions. You need to select the regular expression type though (it usually says textual) and that will let you do a search and replace. Xcode uses the ICU regex syntax.
To do the wildcard search, use regular expressions and use \n in the replacement text.
I'm using Xcode 3.2, but I think that older versions use the same regular expression syntax. Use the Find… (cmd-F) command. Choose "Find & Replace" from the pop-up menu. Choose "Regular Expression" mode from the pop-up menu in the search text field. Enter "var(\d+)Letter" for the search text, and "var\1letter" for the replacement text.
The "\d+" syntax matches any sequence of one or more digits. The "\1" is replaced by the text matched by the first set of parentheses in the search text.
Here's all I know:
Not sure; I have seen this problem, too, and don't know of a workaround.
As far as I know XCode doesn't handle regular-expression-based search/replace, which is what you'd need for this situation.
The setting you're looking for is "Base SDK", which can be configured both per-project and per-target (which overrides the project setting) by right-clicking on the project icon or the target icon, respectively, and choosing "Get Info" from the context menu. The Base SDK setting is one of the first under the Build tab.
For #3, There's no way to set new default SDK for all new projects that you create. The easiest way that I've found is to create an .xcconfig file that gets imported to every new project that I make.
An alternative to this would be to edit the default Xcode project (The base template for a base application is found at Developer/Library/Xcode/Project Templates/Application/Cocoa Application/Cocoa Application/__PROJECTNAME__.xcodeprjo/project.pbxproj) and change the SDKROOT value.

Resources