How to automate or programmatically make changes to System Preference settings on Mac OS X - objective-c

I am trying to figure out how to programmatically change System Preference settings on the Mac OS X. If that is not possible, create some post-installation automation script (using Apple Script or other means) and run it as part of the installer. I am particularly interested in making changes to the "Language & Text" settings which are part of the "personal" settings in System Preferences.
Here is more description of my problem:
I am trying to create an installer for a custom keyboard layout I wrote for Mac OS X. The keyboard layout basically allows people to transliterate ASCII keboard input to foreign letters. The foreign language does not exist on Mac OSX*. I was able to use Apple's PackageMaker to create a basic installer that dumps all the necessary files (.keylayout file, icons and the custom fonts) in their respective directories in the target computer. But there are a couple of personal settings that need to be configured in System Preferences before the keyboard layout can be selected and used. I would like to auto-configure these "one-time" settings for the user during the installation process. Is it possible to make changes to the settings using Cocoa/Objective-C. If not, I would like your help on how I can use Apple Script to automate the configuration. Please include some sample code or pointers to examples if possible. Thank you.
Here are the settings that need to be configured on System Preferences
Select System Preferences --> Language & Text -- Input Sources
Select "The Language Name" from the list
Click on "Keyboard Shortcuts" and enable "Select the previous input source" and "Select next source in Input Menu".
Double click on the shortcut combinations "⌘ space" and change them to "⌘ L" for the "Select the previous input source" and "ctrl⌘L" for "Select next source in Input Menu"
Exit systems preference. Done
NB: *The system language need not be changed. Only the input source (keyboard layout).

See NSUserDefaults. The values you want to set are probably in NSGlobalDomain.

Related

Making localization work

I have an app that needs to be localized.
After fiddling with the settings for a while, I managed to get the project to the state where it builds a nl.lproj (amongst others) directory in the Resources directory of the app bundle, which contains a MainMenu.strings file that contains all my translations; they seem correct at first glance.
The XIB file is marked as translatable, and seems to be part of the right target:
However, if I run the app in a dutch environment, the localized strings are not shown in the UI. I added
NSLocale *loc = [NSLocale autoupdatingCurrentLocale];
NSString *lang = [loc languageCode];
NSLog(#"Current language: %#",lang);
to verify that the Dutch language is active, and it is.
This question suggests that doing a clean followed by a rebuild of the app should fix such issues. I've tried that, but it did not resolve the issue.
How can I figure out why my app isn't being translated? What else could go wrong? Are there any diagnostics I could be checking?
The application in question is open source, and can be found at https://github.com/Fedict/eid-mw. Select the "eID Viewer" target, and build that, to see what's happening.
There are two different things with the localization. One is localization the UI. This is done by checking those boxes and then editing the string files in the dialog underneath the xib file.
The second is the localization of the Userfacing strings in code. This is done by the Macro NSLocalizedString(#"*key*", *comment*); where key is the key and comment is a provided comment for localization purpose.
These strings are the to edit in the File Localizable.strings.
Here a link with a Beginner Tutorial. And the Apple Docs
To activate the debug function in Xcode for localized strings: pass in -NSShowNonLocalizedStrings YES as launch argument in Xcode. You find it under Product/Scheme/Edit Scheme -Arguments
Hope this helps
You need called .strings file with name "Localizable.strings".
And add language target ( in inspector ) and fill target language file.
Have you tried a check with pseudolocalozations?
Are you setting properly the language and region on your mac?
Are you also trying launching it specifically in Dutch from XCode:
To launch your app in a specific language and region
Click the target in the Run destination menu and choose Edit Scheme.
On the right, select Options.
Optionally, choose a language from the Application Language pop-up menu.
Optionally, choose a region from the Application Region pop-up menu.
Click the Close button.
Click Run to launch your app in the language and region you specified.
It turns out that localisation is supported with OSX 10.8 and above. My app had selected 10.7 as deployment target (we do need to support a few older versions of OSX). Switching the deployment target to 10.8 makes the translations appear.

How to Show Review Bar in Okular by Default?

I use okular on Linux Mint.
Unfortunately the review bar which contains the annotation tools has to be manually loaded up each time okular is opened.
This is outrageously annoying if you open many hundred documents a day you need to highlight!
I neither found any option to show the review bar by default in the program's settings or via web search. I did not even found a shortcut that could be bound to a mouse key for easier opening. (The standard F6 shortcut does not do the trick for me.)
Is there any solution you can recommend?
Based on the information available on the official KDE Okular Handbook (currently at version 0.26) there is no functionality associated with this feature, so it technically can't be done by default from inside Okular.
To access the "Review" function (which includes highlighters, etc) you should press F6 or choose the Review option from the tools menu. At the moment all you can do in regards to tool configuration is change the available components of the review tool, adding or removing highlighter/marker tools. You can also configure shortcuts for the Review function, assigning an additional/alternate shortcut to open the review tool panel (Relevant to those with multimedia keys associated with their F-keys).
If the lack of this feature bugs you, you can always post a feature request to the KDE Bug Traker; Remember to search for existing requests before posting to avoid duplicates.

How to have folders first before any file in finder (Mac) programmatically?

I am new to Mac OS. I want to have the folders first before any other file in finder through my cocoa app.
Can anyone suggest me a way of doing this like xtraFinder, PathFinder etc apps do?
I have gone through the followings links. One way is this:
http://hints.macworld.com/article.php?story=2011072120153685
http://mygeekdaddy.net/2013/10/24/change-mavericks-finder-app-sort-order/
And the other way I got is to drag the folders to first in the spotlight (in system preferences) then sort by kind.
But in both ways I don't know how to do this programmatically. Can anyone tell me step by step how to do this through my app?
OS X Sierra finally has an option for this:
Open Finder
Go to Finder Menu -> Preferences
Go to "Advanced" tab
Check the "Keep folders on top when sorting by name"
Now, When you sort by name, can see folders at top of files (like as windows)
Good Luck ;)
For Mavericks and Yosemite: From any Finder window either right-click in the window or select the icon that looks like a gear from the menu bar.
Next, select "Show View Options".
Set "Arrange by" to Name.
Set "Sort by" to Kind.
Optionally, you can save these settings as a default.
Also note that you may need to do this for each drive and/or "top" folder.
I pretty much like everything mac, but this windows-like feature is kinda nice to your eyes.
thanks
Memariaan solutions also works in 10.14.2 Mojave but there are two selections now instead of one.
According to crunchgeek (And validated myself on Mac OSX 10.9.5)
cd /System/Library/CoreServices/Finder.app/Contents/Resources/English.lproj/
sudo plutil -convert xml1 InfoPlist.strings
sudo nano InfoPlist.strings
Now change <string>Folder</string> by adding a space to get <string> Folder</string>. Finally "encode [the] file back into binary format."
sudo plutil -convert binary1 InfoPlist.strings
Now open Finder View Options via Command+J and select Kind under "Sort by".
To make the folders come first in finder, change the order of data categories in spotlight.
Hit Command plus spacebar and then type spotl. That opens spotlight preferences. You will see all the data categories you have checked, or are checked by default. Simply drag "folders" to the top of the list. You can also arrange all the data categories in the order you want. So when you are looking in Finder and opt to arrange by "kind" the folder show up first together with any other changes in the order that you made.
Thanks to David Pogue's OSX Yosemite, the missing manual, Page 132.

Get key used to change Spaces

Is there any way to programatically determine what key is set in System Preferences to change to a specific Space.
This setting is configured in the Expose & Spaces preference, under the Spaces tab. The last drop down box is titled "To switch directly to a space" and you can choose from the control key, the command key, the option key or no key.
This is the value I'd like to programatically determine.
Possible?
You could try using AppleScript's GUI scripting to programatically open the preferences pane and see what is in the drop down box. An example is here. To invoke it from Objective-C, check out Scripting Bridge if you're using OS 10.5 or later, otherwise there's an older API but I can't seem to find it at the moment.
If you want a solution that doesn't require popping up the System Preferences window and showing all its animations to the user, the actual value is stored somewhere in ~/Library/Preferences/com.apple.symbolichotkeys.plist, but the format is not human-readable. You could change the key binding from System Preferences and compare that file before and after. Keep in mind that this may be different between versions of OS X.
Hope this helps, and welcome to Stack Overflow!

VB.NET call desktop application from 2 shortcuts - supply different parameters

I have a desktop application which reads files from a specified folder, then deposits the files to a folder in a third party document management system based on criteria that the user provides.
My question is:
is it possible to somehow provide different parameters to the code, depending on which shortcut of the application the user clicked on to start it up?
You can add command line parameters to a shortcut icon. Here's how you can do it in Windows:
On the Start Menu, navigate to Notepad.
Right click on Notepad and choose Send To > Desktop (Create Shortcut)
Right click on the newly-created desktop icon and choose Properties
Add your command line parameters to the Target text box.
For example, if you want notepad to open up the hosts file, this would be the content of Target property:
%SystemRoot%\system32\notepad.exe "C:\WINDOWS\system32\drivers\etc\hosts"
You can put pretty much anything into the Target property of a shortcut that you would put into a command line.
Yes.
The easiest way would be to have the shortcut pass those parameters in via the command line.
You could also use conditional compilation variables, and have 2 different .exes. You should be able to find samples of both approaches (command line and conditional compilation variable) in help.