Preferred OSX Application Path?

I want to be able to run a text editor from my application, set by the user in the TEXT_EDITOR environment variable. Now, considering that there is nothing in this variable, I want to use the TextEdit program that comes with OSX by default. Is it kosher for hardcode / Applications / TextEdit.app / Contents / MacOS / TextEdit in my application or is there a better way to invoke the program?

Edit: for writing, I am limited to running a specific application path in C. I do not open the path to the text file.

Edit 2: Seriously people, I do not open the file here. I ask for the application path for some reason.

+4
source share
5 answers

In the second edit, it sounds like you just want to get the path to TextEdit, this can be done easily using the NSWorkspace absolutePathForAppBundleWithIdentifier method:

NSString *path = [[NSWorkspace sharedWorkspace] absolutePathForAppBundleWithIdentifier:@"com.apple.TextEdit"]; 
+4
source

Mac OS X has a mechanism called “uniform type identifiers,” which it uses to track associations between data types and applications that can handle them. The subsystem that controls this is Launch Services. You can do one of two things:

  • If you have a file with a fairly well-known path extension, for example. .txt , you can simply ask NSWorkspace to open the file in the appropriate application.

  • If you do not have a well-known path extension, but you know the data type, you can ask Launch Services to find the default application for this type, and then ask NSWorkspace to open the file in this particular application.

If you do this like this, you will get the same behavior as Finder, and you won’t need fork () / exec () or use system () to open the file.

+4
source

I believe that hard coding of the "Application" will not work if the user's language is not English. For example, in Norsk, the Applications folder is called Programmer.

Apple's internationalization document is here . Starting on page 45, this is the section for processing localized path names.

+2
source

I believe that Mac OS X provides a default application engine, so .txt will open in TextEdit.app or Emacs or GVim or whatever the user has specified. However, I did not find anything on the Internet.

0
source

You can execute the 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 type of file using the open command.

-1
source

Source: https://habr.com/ru/post/1277292/


All Articles