mac default application for any unknown extension - macos

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;}'

Related

How to create .lisp files and run them on mac?

As can be seen on the picture TextEdit on mac gives only limited options of file extensions in which I can safe a file. Lisp not included.
Create .lisp files
https://www.tutorialspoint.com/lisp/lisp_environment.htm is describing everything step by step, but it says TextEditor on Mac can save .lisp files, which I wasn't able to do.
Load .lisp file
(load "filename.lisp") leads to error: file with such name doesn't exist
TextEditor on mac has limitations to how file can be saved (.txt, etc.). You can use any other editor, ex: TextWrangler, which allow you to write file extension. Or you can use editors specific for lisp, ex: Emacs (more massive)
It's possible that when you type (load "filename.lisp") it searches in some specific directory, where it's not present. So, to avoid this, you should type full path to the file you want to open. Ex: (load "/Users/macbook/Desktop/foldername/filename.lisp")

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?

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

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.

Files with the same name in a TextMate project

One of the few things that bothers me about TextMate is that it can be difficult to differentiate between files that share the same name in a project, e.g:
alt text http://img530.imageshack.us/img530/6791/bild1r.png
In this case, the file on the right is located in the project relative path model/realtimemodel.py, while the other file contains unit tests for that code. Sure, you can command-click the name in the title bar to see a directory list, but it feels sub-optimal. What I would like is something along the lines of:
alt text http://img240.imageshack.us/img240/1783/bild3.png
This gives a quick at-a-glance idea of what file you're working on. Has anyone seen any plugin or bundle that makes this possible?
Edit: Here is a ticket in Macromates tracker that requests this feature (although I would prefer a project-relative path).
This is a start: http://snipplr.com/view/11490/textmate-command-snippet--show-document-path-in-window-title/
I think vasi's solution is the closest you can get to what you want (+1 for him)
I don't think that the bundle can be automatically ran on open, and also, the title changes back to default when switching between tabs, so even if it could, it would be useless.
I've searched for a defaults key (like the one from Finder, _FXShowPosixPathInTitle editable with
defaults write com.apple.finder _FXShowPosixPathInTitle -bool YES)
but there isn't any. Here's the list of available keys for Textmate.
Maybe you can write feature request somewhere as it is very useful and not so hard to impletement.

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