Default location for configuration files - MacOS? - macos

In a cross-platform application, I am working with a configuration file that allows the user to override various defaults if he wishes to.
The problem I have is... where to place / look for this configuration file, especially with regards to MacOS X (which I never used and have no access to)? I know that MacOS X is based on Unix, but I also know that many things are done very much differently there...
My current choices:
Unix:
~/.config/<appname>/<appname>.cfg
Windows (shomewhat unsure about this one too, things seem to be all over the place here - %LOCALAPPDATA% or %USERPROFILE% seem to be valid choices too):
%APPDATA%/<appname>/<appname>.cfg
MacOS:
...?
Any comments, on MacOS or my other choices?

I think it must be ~/Library/Application Support/<appname>/<appname>.cfg
See the table in Mac App Programming Guide : "The Mac Application Environment" -> "Low-Level Details of the Runtime Environment" -> "The File System".

You can store it in the same manner you show for Unix/Linux above.
~ works the same way for home directories on OS X as UNIX platforms. Same goes for . in names for hidden directories.
Given the cross-platform needs you describe, I would do it exactly the same way on OS X as in your UNIX example.

Related

Mac OS X app sandbox issue

I am writing a command line tool. There I'd like to create a directory in the /Users/user_name/Library directory. When I run that program from Terminal as a root, then everything is ok, but the problem is when I want to use that tool as a backend for cups (that program is called, also as root, when I print something). The program is called, but in the system.log file I found the error: sandboxd: deny file-write-*. I'm a new Mac OS X programmer and I'm not sure how to fix it. Anybody can help me?
Since Snow Leopard cups is running in a sandbox that prevents it from misbehaving - like accessing user's home. Depending on your OS X version you can get away by using another directory, not user's home. On Lion it is even more restrictive than that. The sandboxing rules are built-in to the cups binary (as opposed to sb scripts), so your only luck may be replacing cups with a version that specifically allows access to what you need in the sandbox (if you really want to go there, the rules are defined by cupsdCreateProfile in cups/scheduler/process.c). AFAICT there is nothing you can do in your application, because sandboxing is designed to prevent exactly what you are trying to do.
Another alternative is to not run cups as root, because sandboxing is only used when cups is run as root.

How to determine whether a file or folder is hidden in Mac OS X?

How to determine whether a file or folder is hidden in Mac OS X, like we have GetFileAttributes in Windows?
See Is the file hidden?
(The matter is complicated because there are multiple factors that can cause a file to be "hidden" - the Launch Services approach described in the linked post ought to cover all of them.)

How can I convince OS X to open txmt:// URLs in MacVim?

I guess there's not much else to the question. OS X 10.5.
If possible, use the mvim://-protocol instead. It should be compatible with the txmt://-protocol.
If you are not able to change the links themselves, you could try editing the Info.plist for MacVim.
I do not know whether plugin for this «protocol» already exists, but if you want to write your own, you should take a look at BufReadCmd event (and also BufWriteCmd). If you don't want to start from scratch, some such events are defined in $VIMRUNTIME/plugin/netrwPlugin.vim (for example, for ftp:// protocol) file which should come with your vim installation.

Is there something like filter driver for Mac OS X?

Windows lets you develop a filter driver to catch file I/O's on VFS. But I can't seem to find something similar for Mac. It does have something called Filter Schemes, but those are for HFS+. Anyone know if there is a way for me to intercept file I/O's on Mac without using programs like MacFUSE?
I found out that Mac OS X does not allow filter drivers at all.
“A stacking file system (sometimes called a filter file system) sits on top of another file system and modifies its behavior in some way. The canonical example of a stacking file system is an encryption file system. You could stack this file system on top of any existing file system to provide encryption support. Apple does not support the development of stacking VFS plug-ins on Mac OS X” (http://developer.apple.com/mac/library/qa/qa2001/qa1242.html)
kauth (introduced in OS X 10.4) is the closest thing to FS filter drivers.
Here is a nice write-up on the various APIs present on Mac OS X. It should be a good starting point.
Link
I'm not at all familier with the Windows technologies that you mention, but it sounds like you might be looking for FSEvents.
http://developer.apple.com/mac/library/documentation/Darwin/Conceptual/FSEvents_ProgGuide/Introduction/Introduction.html
The file system events API provides a
way for your application to ask for
notification when the contents of a
directory hierarchy are modified. For
example, your application can use this
to quickly detect when the user
modifies a file within a project
bundle using another application.
It also provides a lightweight way to
determine whether the contents of a
directory hierarchy have changed since
your application last examined them.
For example, a backup application can
use this to determine what files have
changed since a given time stamp or a
given event ID.
You should read this document if your
application works with a large number
of files—particularly if your
application works with large
hierarchies of files.

Which command line tools can I use to get the currently active application / window on each platform?

I'm trying to create an AIR application to log application usage and the only easy way to get information from the system with AIR is using command line tools and scraping stdout.
I know about tools like top and ps for OS X, but neither of them seems to tell me which application / window is active, maybe I shouldn't even be looking for processes? For my logging purposes I`d like to get the name and title of the currently active window (and application) as a start.
I`m primarily interested in OS X, but would be great to have Windows and Linux equivalents too for the future.
If no such tools exist yet, it would be great to get some pointers how to make them. I haven't done any OS level programming yet, but I'd think creating a command line tool should be one of the easier things to do (completely ignoring GUI frameworks).
These two questions seem to be asking the same thing, unless I've misunderstood your question. Should be a good start for OS X:
Get the title of the current active Window/Document in Mac OS X
Finding the Current Active Window in Mac OS X using Python

Resources