This morning I installed, compiled, and ran a simple example program using the GNU Scientific Library. This took me a while to figure out, so I'll share the process here. I am assuming that the reader, like the author, has only vague familiarity with C.
- Install Homebrew, their site has a line of code you can run from the command line.
- Install Xcode from the Apple Applications menu.
- Install GSL, the GNU Scientific Library, using Homebrew. This will install GSL at
/usr/local/include
.
- Hammer out a sample program on your favorite editor (Vim) and name it
main.c
or something.
Description: I show you how to show the /Library folder three different ways.Retweet: http://www.idownloadblog.com/2015/03/12/li. Make sure to select a released version of the library. Some library repositories are still in development, and may contain unreleased or untested code. The 'Releases' button takes you to the tested and released versions. Click the 'Releases' button on the Github repository page to find the released version of the library.
- Compile the code. This should produce an object file in your working directory called
main.o
.
- Link the object file to produce an executable,
a.out
. Here, the-L
flag provides the path to the library, and the-l
flag provides the name of the library that you'd like to link.
- Run the executable
a.out
from the command line.
This should produce the following output:
The lsregister command is used to query and manage the Launch Services database, or the database that is used to determine the default application used to open files of various types. lsregister is part of Core Services, and stored in /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support. To see the options available to lsregister, run the command with no operators:/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister
You can dump the database to the screen using the -dump option:/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -dump
You can then grep the database or redirect the output into a text file for parsing:/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -dump > dump.txt
Sometimes applications don't open with a given file type. When this happens, you can quickly and easily check if the problem has to do with the launchservices database. To do so run the open command and define the application (using the -a option) followed by the app and then the file. For example, to open an XML file called daneel.xml in TextWrangler (assuming your working directory contains bob.xml):open -a TextWrangler.app bob.xml
You can force an application to re-register file types for that application using the -f option followed by the application path. For example, to re-register Xcode:/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -f /Developer/Applications/Xcode.app
You can also unregister a specific application using the -u option. To unregister Xcode you would use the -u option:/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -u /Developer/Applications/Xcode.app
The lsregister command is actually just a front-end management tool for the ~/Library/Preferences/com.apple.LaunchServices.plist file. The file's contents can be read (in an unparsed form) using defaults:defaults read ~/Library/Preferences/com.apple.LaunchServices
The launchservices database is also responsible for determining whether a file type is quarantined by default (and those files that are quarantined throw a message to users when opened for the first time). To disable such a feature:defaults write com.apple.LaunchServices LSQuarantine -bool NO
The database can become pretty large and unwieldy. There are applications registered in the local domain, system domain and each user's domain. You can always clear these out using the following command, which also recursively rebuilds based on the output of a -lint option:/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -kill -r -domain local -domain system -domain user
To check the progress:/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -v
To set a specific application to open a file type, use the application's domain out of the -dump output in an LSHandlerRoleAll and the file extension in an LSHandlerContentType in the LSHandlers array of com.apple.LaunchServices, as follows (to change txt for Text Edit – aka com.apple.textedit):defaults write com.apple.LaunchServices LSHandlers -array '{ LSHandlerContentType = 'txt'; LSHandlerRoleAll = 'com.apple.textedit'; }';
You can also set the default application for a network protocol (e.g. smb://, rdp://, vnc://, http:// and https://). Because the options for lsregister leave one wanting in some ways (the commands to set file types to a specific application are a bit overly complicated one could argue), there is an awesome front end app from Andrew Mortensen, aptly called duti, available at http://duti.sourceforge.net/index.php. With duti installed, the command to set the default browser for http would be:The Library Overseer Mac Os X
/usr/local/bin/duti -s com.apple.safari http