How do I make certain files accessible in Mac OS X? - macos

I have a db file which I want to open using a firefox plugin.
However, I can't open the file.
I've also got other files like this with other file types.
I'm sure I've had this problem before, any ideas ?
I've tried...
defaults write com.apple.finder AppleShowAllFiles TRUE
killall Finder
But that didn't work.

Mac OS X displays all of the files in a particular folder on your disk in its Open/Save common dialogs, but it grays out the ones that are in a format that can't be opened by whatever program's Open/Save dialog you're browsing from.
The title of the dialog in the screenshot above gives away your problem. It says "Set Default Directory", which means it's only looking for a folder. The file "bc.db" is just that: a file. Whatever program you're trying to open it from isn't willing to accept it because a file is not interchangeable with a folder/directory. That explains why none of your other file types work, either. You need to choose a folder from that dialog to set as the default.
It's also worth nothing that the .DB extension means that file is a database file of some sort. It's very likely that it's in a proprietary format that can only be read by one particular application. Thus, even if you try to open it from the Finder, you're not likely to get very far. You need to figure out what program originally generated that file and try to open/use it there.

Related

mac default application for any unknown extension

I have a series of files that are all text files that i want to open with text editor (let's say Sublime).
The extensions on these files follow the pattern:
file.sff123
file.sff124
file.sff125
file.sff126
and so on...
Every time i go to open one of these files, the dialog pops up to select the default application for this file type, but since they all have varying extensions, i have to navigate and select the new file type each time. I literally have 1000s of these files and would like to be able to open all of them. Further, i want to be able to open any unknown file with something like Sublime by default. 99% of the time its a random text file... the 1% that it's not i'll "open with".
Is there a way to get Mac to recognize any unknown file extension and open it with an application of my choosing by default?
I am not sure if it is possible, but the following (untested) may help you, or someone else work out how to do it.
OSX uses UTIs (Uniform Type Identifiers) to categorise filetypes and map them to applications - and this works in conjunction with Launch Services to launch the appropriate application.
I don't have one of your .sffnnn files available, but I think you need to run mdls on one and see what kMDItemContentType is. You can do that like this in Terminal:
mdls -name kMDItemContentType somefile.sff123
I am hoping you get the same content type for all your .sffnnn files - if you don't, this approach won't work.
You then need to edit your LaunchServices.plist file which, I think, is in ~/Library/Preferences/com.apple.LaunchServices.plist and make an entry corresponding to the filetype you found above that maps to the sublime application. I suggest you look in there, or the system-wide version to see how entries look.
Once you get the hang of it, you may be able to do it from the command-line with a command like:
defaults write com.apple.LaunchServices LSHandlers -array-add '{LSHandlerContentType=xxxType;LSHandlerRoleAll=xxx.yyy.sublime;}'

Windows: tell app to open file

On Windows, how do I get my app to tell another app to open a file that I just generated. For example, "WordPad, please open 'foo.rtf' that I just made." Or Word, or other big apps that may already be open with other files. I have to assume that the app may or may not be open already.
Alternatively, if I could only do the equivalent of double-clicking the file, so as to open it with its default application, that would still be all right.
Depends on how your application handles opening other files.
One would think that assuming filetype associations are configured properly in Windows, it should know what application to open .rtf files with (per your example).
In powershell, you could use gc if you're only looking at plaintext data.
http://www.ats.ucla.edu/stat/mult_pkg/faq/general/powershell_examples.htm
In Python, you would handle the file as an object, per the example here:
https://docs.python.org/2/tutorial/inputoutput.html#reading-and-writing-files
But if you wanted to launch a specific secondary application to open the file, you might try running an outside program (executable) in python?

Redirect default program to another program when a file opens in Windows OS

This is only under windows env.
As I know windows os identifies associated application of a particular file by file extension.
Like wise each file (binary) starting with corresponding symbols ("starting symbols"). For an example .JPG starts with ÿØÿà. Let say I open this .JPG file in a Hex editor or a Text editor and then I change that starting symbols into another file type. for an example I can change ÿØÿà to .Eߣ (.mkv). So when I double click on the .JPG the Windows Photo Viewer says there are some errors or similar message. So I need to get some information about the application that tries to open that kind of a file. If I can, I need to open that file using the application that associated with "starting symbols".
Briefly when I open .JPG I need to open a default video player .mkv files. But It may not work for this example. Because I changed only the "starting symbols" of my .JPG.
Please give me any idea to do this.
Thanks!
When you encrypt the file, give it a new extension. e.g. Picture.jpg becomes Picture.encrypted-jpg. You then register as the handler for encrypted-jpg, decrypt the file, then launch the normal jpg handler.
When the shell is asked to perform a verb on a file, the shell does not use the contents of the file to determine which app to pass it to. The file extension is what determines how the file will be treated.
You wish to use the contents of the file to influence which app processes a shell verb. In order to do so you would need to create a launcher app that reads the file header and then decides which app to pass the file on to. You would assign your launcher app as the handler app for all file extensions that you were interested in.
Although you could do this, it would be much easier just to set the file extension appropriately.
The proper way to do this sort of thing is to replace the files with reparse points.
The downside is that this involves writing a file system filter driver, i.e., an operating system extension, which is a whole level of trouble above and beyond ordinary application programming. (Since Windows already does file encryption, I doubt it would be worth the effort.)

Open dot-file with dialogue in OSX

Since the GUI-side of OSX treats all dot-files (such as .htaccess) as hidden, it doesn't display them in any of the graphical UI:s, e.g. Finder or the Open-dialogues.
How can I open a dot-file (.htaccess in this case) in a graphical editor, without doing that thing for all hidden files, universally and without going through Terminal.app?
Edit: I'm on Leopard, if that makes a difference.
Edit2: TextWrangler and TextMate seem to have features that allow you to open hidden files, which partly answers my question.
In an "Open File" dialog you can use Command-Shift-. to see dot files.
You could tell Finder to display hidden files as well (enter in Terminal):
defaults write com.apple.finder AppleShowAllFiles TRUE
But that’s not really nice since there are a lot more hidden files. So I recommend to use an editor that allows you to view those in the open dialog like Chuck mentioned.
If you only want to do this for one specific file, you can create a symbolic link to the dot-file. Open up Terminal.app, cd to the directory containing your dot-file, and run
ln -s .htaccess dot_htaccess
Then you should be able to double-click the file dot_htaccess as a regular file, and any edits you make will really go into .htaccess.
TextMate (a really nice text editor for OS X) open dialog has a "Show hidden files" option, and TextWrangler (and its big brother BBEdit) has it has a menu item.
In the command line, for a file named FILE, type:
open -e FILE
The open command will open the file in TextEdit (-e flag). Check out "man open" for more flags (e.g., specify the app to open with -a)
Smultron (another nice OS X editor mentioned in the comment above and similar to TextMate, but free) has an "Open Hidden..." file menu item that works splendidly for this purpose.
Sad news: Smultron is apparently no longer being developed further beyond v3.5.1 (which requires Leopard), according to a post from its author at its homepage: http://tuppis.com/smultron/
jEdit is another free option that has hidden file support: www.jedit.org/users-guide/vfs-browser.html (sorry for the lack of 'http' in the link -- being a new user, my posts are limited to just one link. Alas...)

Preferred path to applications on OSX?

I want to be able to run a text editor from my app, as given by the user in the TEXT_EDITOR environment variable. Now, assuming there is nothing in that variable, I want to default to the TextEdit program that ships with OSX. Is it kosher to hardcode /Applications/TextEdit.app/Contents/MacOS/TextEdit into my app, or is there a better way to call the program?
Edit: For the record, I am limited to running a specific application path, in C. I'm not opening a path to a text file.
Edit 2: Seriously people, I'm not opening a file here. I'm asking about an application path for a reason.
In your second edit it makes it sound like you just want to get the path to TextEdit, this can be done easily by using NSWorkspace method absolutePathForAppBundleWithIdentifier:
NSString *path = [[NSWorkspace sharedWorkspace] absolutePathForAppBundleWithIdentifier:#"com.apple.TextEdit"];
Mac OS X has a mechanism called "uniform type identifiers" that it uses to track associations between data types and applications that can handle them. The subsystem that manages this is Launch Services. You can do one of two things:
If you have a file with a reasonably well-known path extension, e.g. .txt, you can just ask NSWorkspace to open the file in the appropriate application.
If you don't have a well-known path extension, but you know the type of data, you can ask Launch Services to look up the default application for that type, and then ask NSWorkspace to open the file in that specific application.
If you do it this way you'll get the same behavior as the Finder, and you won't have to fork()/exec() or use system() just to open a file.
I believe hardcoding "Applications" will not work if the user's language setting is not English. For example in Norsk the "Applications" folder is named "Programmer".
The Apple document on internationalization is here. Starting on page 45 is a section on handling localized path names.
I believe that Mac OS X provides a default application mechanism, so that .txt will open in TextEdit.app or Emacs or GVim or whatever the user has specified. I couldn't find anything online however.
You could run following command from your application:
open <full path to text file>
This will open the text file in the default text editor. You can open any file type using open command.

Resources