Mac Os X Run App From Command Line

  • This thread is locked. You can follow the question or vote as helpful, but you cannot reply to this thread.
  • The program is actually installed in the TWAIN directory tree on the Mac. (Library/Image Capture/TWAIN Data Sources) When I log on to a 'regular' admin level account (that is, the account does have administrative privileges) the program will not run; it thinks for a bit, and then says 'please run as administrator'.

Calling Command-Line Tools

Feb 06, 2013 Launching OS X GUI Apps as root user. The command syntax is as follows: sudo /Path/To/Application/ApplicationName.app/Path/To/Executable. In most cases, that will be applications stored in the /Applications/ directory, and the executable is almost always stored in Package/Contents/MacOS/ as whatever the applications name is.

In AppleScript, the do shell script command is used to execute command-line tools. This command is implemented by the Standard Additions scripting addition included with OS X.

Note

The Terminal app in /Applications/Utilities/ is scriptable and provides another way to execute command-line tools from scripts.

Executing Commands

Mac Os X Run App From Command Line Linux

The direct parameter of the do shell script command is a string containing the shell code you want to execute, as demonstrated in Listing 39-1, which simply lists a directory.

APPLESCRIPT

Listing 39-1AppleScript: Executing a simple shell command that lists the contents of a directory
  1. do shell script 'ls /Applications/'
  2. (*
  3. --> Result:
  4. 'App Store.app
  5. Automator.app
  6. Calculator.app
  7. Calendar.app
  8. ...'
  9. *)

Since the direct parameter of do shell script is a string, you can concatenate it with other strings at run time. Listing 39-2, for example, concatenates a shell command to a previously defined parameter value.

APPLESCRIPT

Listing 39-2AppleScript: Concatenating a command with a value

Mac Os Command Line Tools

  1. set theHostName to 'www.apple.com'
  2. do shell script 'ping -c1 ' & theHostName

Quoting Strings

The shell uses space characters to separate parameters and gives special meaning to certain punctuation marks, such as $, (, ), and *. To ensure that strings are treated as expected—for example, spaces aren’t seen as delimiters—it’s best to wrap strings in quotes. This process is known as quoting. If your string contains quotes, they must also be escaped (preceded by a / character) so they are interpreted as part of the string. Listing 39-3 shows an example of an error occurring as a result of a parameter that contains a space.

APPLESCRIPT

Listing 39-3AppleScript: An error resulting from a string containing a space
  1. set thePath to '/Library/Application Support/'
  2. do shell script 'ls ' & thePath
  3. --> Result: error 'ls: /Library/Application: No such file or directoryrls: Support: No such file or directory' number 1

The easiest way to quote a string is to use the quoted form property of the text class, as demonstrated in Listing 39-4. This property returns the string in a form that’s safe from further interpretation by the shell, regardless of its contents.

APPLESCRIPT

Listing 39-4AppleScript: Quoting a string to prevent errors
  1. set thePath to quoted form of '/Library/Application Support/'
  2. --> Result: '/Library/Application Support/'
  3. do shell script 'ls ' & thePath
  4. (*
  5. --> Result:
  6. 'App Store
  7. Apple
  8. ...
  9. '
  10. *)

More Information

For more information about the do shell script command, see Commands Reference in AppleScript Language Guide and Technical Note TN2065.

Copyright © 2018 Apple Inc. All rights reserved. Terms of Use | Privacy Policy | Updated: 2016-06-13

How to Launch GUI Applications from the Terminal - OS X Daily

Reference

Hi,
How can I invoke a program like Internet Explorer from the command line? On Linux, you can, for example, just type netscape & in your terminal. Well, my reason for asking this is that forte wants to invoke netscape when I run a jsp. I don't have netscape and not in the mood to install the beta version of netscape for OS X. Since Forte is calling a function similiar to the way I invoke netscape from linux from command line, I am wondering if that's possible for IE. If it is possible, how do I find out what that command is? I tried IE and InternetExplorer, neither worked. When I tried to call the full path to Internet Explorer (from the Application dir) I get a permission denied error.
So, as a non-root user, how do I call Internet Explorer from command line?
Thanks!
G