[265] | 1 | launch 1.1d2 [unreleased] |
---|
[166] | 2 | ============ |
---|
[3] | 3 | |
---|
| 4 | A command-line launcher for Mac OS X in the spirit of open(1). |
---|
| 5 | |
---|
| 6 | Written by Nicholas Riley <mailto:launchsw@sabi.net>. |
---|
| 7 | Obtain updates from <http://web.sabi.net/nriley/software/>. |
---|
| 8 | |
---|
| 9 | WHAT IS IT? |
---|
| 10 | ----------- |
---|
| 11 | |
---|
| 12 | Apple provides a simple command-line launching program called 'open' |
---|
| 13 | with Mac OS X. It offers few options - launching applications by name |
---|
| 14 | or by path, launching TextEdit, or opening a number of applications, |
---|
[52] | 15 | documents, folders, or URLs. With the exception of special support for |
---|
[214] | 16 | TextEdit (open -e), 'launch' does all this and: |
---|
[3] | 17 | |
---|
| 18 | - opens URLs, directly or in your preferred helper application (-l) |
---|
| 19 | - lets you specify applications by their four-character creator |
---|
| 20 | (e.g. 'ToyS') or Java-style bundle ID (e.g. com.apple.scripteditor), |
---|
| 21 | both of which allow you to move or rename an application without |
---|
| 22 | changing references to it |
---|
| 23 | - asks applications to print documents, something the OS X Finder |
---|
[214] | 24 | didn't get until Mac OS X 10.4 |
---|
[52] | 25 | - allows you to pipe output to GUI applictions |
---|
[3] | 26 | - launches applications in the background |
---|
| 27 | - launches Carbon applications in Classic |
---|
| 28 | - displays file information including type, creator, bundle ID, |
---|
[146] | 29 | data and resource fork sizes, dates and version |
---|
[3] | 30 | - reports errors intelligibly |
---|
| 31 | - and much more! |
---|
| 32 | |
---|
| 33 | 'launch' is useful by itself, but is even better when used in scripts. |
---|
| 34 | Assign a shell command to your favorite Mac OS text, graphics or |
---|
| 35 | resource editor. Go to your favorite Web site with a few keystrokes. |
---|
| 36 | |
---|
| 37 | Like 'open', 'launch' provides one half of the round-trip between |
---|
| 38 | Terminal.app and the Finder. You can drag and drop icons or proxy icons |
---|
| 39 | into Terminal.app to insert their paths into command lines. To go in the |
---|
| 40 | other direction, just type 'launch .' (or 'open .') to open a Finder window |
---|
| 41 | showing the current directory. |
---|
| 42 | |
---|
| 43 | INSTALLATION |
---|
| 44 | ------------ |
---|
| 45 | |
---|
| 46 | The commands below install the 'launch' tool in /usr/local/bin, which |
---|
| 47 | is in the default path. You should subsequently be able to use |
---|
| 48 | 'launch' by typing its name. If you wish to install it somewhere else, |
---|
| 49 | modify the install line as appropriate. |
---|
| 50 | |
---|
[146] | 51 | % sudo /usr/bin/install -d /usr/local/bin /usr/local/man/man1 |
---|
[267] | 52 | % sudo /usr/bin/install -c launch /usr/local/bin |
---|
[146] | 53 | % sudo /usr/bin/install -c launch.1 /usr/local/man/man1 |
---|
[3] | 54 | % rehash |
---|
| 55 | |
---|
| 56 | Uninstallation: |
---|
| 57 | |
---|
[166] | 58 | % sudo rm -f /usr/local/bin/launch /usr/local/man/man1/launch.1 |
---|
[3] | 59 | |
---|
| 60 | COMPILATION |
---|
| 61 | ----------- |
---|
| 62 | |
---|
[214] | 63 | An Xcode project, 'launch.xcodeproj', is included. A precompiled Universal |
---|
| 64 | binary is also provided. 'launch' was developed and tested under Mac OS X |
---|
[265] | 65 | 10.4.7 with Xcode 2.3, and does not require any additional software to |
---|
[214] | 66 | build. |
---|
[3] | 67 | |
---|
| 68 | USAGE |
---|
| 69 | ----- |
---|
| 70 | |
---|
| 71 | Just type 'launch' by itself to receive usage information. |
---|
| 72 | |
---|
| 73 | Some examples: |
---|
| 74 | |
---|
| 75 | % launch -c 'R*ch' |
---|
| 76 | [BBEdit opens] |
---|
| 77 | |
---|
| 78 | % launch -pbc 'R*ch' test.txt |
---|
| 79 | [BBEdit starts printing test.txt in the background] |
---|
| 80 | |
---|
[54] | 81 | % ls -l | launch -c CWIE - |
---|
[52] | 82 | [CodeWarrior IDE opens with an untitled document containing the file list] |
---|
[3] | 83 | |
---|
[214] | 84 | % launch -i org.mozilla.camino http://www.apple.com/ |
---|
[146] | 85 | [Camino opens Apple's Web site] |
---|
[52] | 86 | |
---|
| 87 | % launch -l launchsw@sabi.net |
---|
| 88 | [Your preferred email client opens a new message to comment on launch] |
---|
| 89 | |
---|
| 90 | % launch -f /Applications/Preview.app |
---|
[3] | 91 | /Applications/Preview.app: Mac OS X application package |
---|
| 92 | type: 'APPL' creator: 'prvw' |
---|
| 93 | bundle ID: com.apple.Preview |
---|
[146] | 94 | version: 2.1.0 |
---|
[3] | 95 | kind: Application |
---|
[146] | 96 | contents: 1 item |
---|
[3] | 97 | [...] |
---|
| 98 | |
---|
[146] | 99 | A scripting example: a zsh function which provides an OS X wrapper |
---|
| 100 | around emacsclient and the Carbon build of GNU Emacs, using launch and |
---|
| 101 | appswitch (another one of my command-line tools). |
---|
| 102 | |
---|
| 103 | e() { |
---|
| 104 | ( emacsclient -n $@ >&/dev/null && \ |
---|
| 105 | appswitch -a Emacs ) || \ |
---|
| 106 | ( launch -ba Emacs && \ |
---|
| 107 | until { emacsclient -n $@ >&/dev/null } do sleep 1; done; |
---|
| 108 | appswitch -a Emacs ) |
---|
| 109 | export EDITOR=emacsclient |
---|
| 110 | } |
---|
| 111 | |
---|
[3] | 112 | FREQUENTLY ASKED QUESTIONS |
---|
| 113 | -------------------------- |
---|
| 114 | |
---|
| 115 | Q. How do I discover bundle IDs for applications? |
---|
| 116 | |
---|
| 117 | A. The -f option to launch can help. Say you have OmniWeb in the |
---|
| 118 | /Applications/Internet folder, and want to find out its bundle ID. |
---|
| 119 | Type 'launch -f', and drop the OmniWeb icon on Terminal: |
---|
| 120 | |
---|
| 121 | % launch -f /Applications/Internet/OmniWeb.app |
---|
| 122 | /Applications/Internet/OmniWeb.app: Mac OS X application package |
---|
| 123 | type: 'APPL' creator: 'OWEB' |
---|
| 124 | bundle ID: com.omnigroup.OmniWeb |
---|
[146] | 125 | version: 4.5 |
---|
[3] | 126 | kind: Application |
---|
| 127 | |
---|
| 128 | Note that bundle IDs are not case-sensitive: com.barebones.BBEdit is |
---|
| 129 | the same as com.barebones.bbedit. |
---|
| 130 | |
---|
| 131 | |
---|
[52] | 132 | Q. Why does application X open a file with a name beginning with |
---|
| 133 | 'launch-stationery-'? |
---|
| 134 | |
---|
| 135 | A. Your application does not support stationery. Applications which |
---|
| 136 | support stationery respond to it by creating a new untitled document |
---|
[146] | 137 | with the contents of the stationery. Most Cocoa applications, such as |
---|
| 138 | TextEdit, do not support stationery. (Omni Group applications are a |
---|
| 139 | notable exception.) If you're looking for a text editor which |
---|
| 140 | supports stationery, try BBEdit, Tex-Edit Plus, the CodeWarrior IDE, |
---|
| 141 | or almost any other Carbon editor. |
---|
[52] | 142 | |
---|
| 143 | For the curious: launch processes input by simultaneously reading it |
---|
| 144 | and writing to a temporary stationery file. Once reading is complete, |
---|
| 145 | launch opens the stationery file with your selected application, and |
---|
| 146 | deletes the stationery after one minute (as a safeguard, it is not |
---|
| 147 | possible to accurately gauge how long it will take for the application |
---|
| 148 | to open the stationery). |
---|
| 149 | |
---|
| 150 | |
---|
[3] | 151 | Q. Why can't I use -f with -c to get info on an application with a |
---|
[52] | 152 | given creator (or -f with -i for a bundle ID)? |
---|
[3] | 153 | |
---|
| 154 | A. This feature may be added to a later version (or add it yourself!), |
---|
| 155 | but there is a workaround. Instead of: |
---|
| 156 | |
---|
| 157 | % launch -f -c 'Doug' |
---|
| 158 | launch: can't get information (-f) on item(s) using an application (-u, -c, -i, -a) |
---|
| 159 | |
---|
| 160 | use: |
---|
| 161 | |
---|
| 162 | % launch -f "`launch -nc 'Doug'`" |
---|
| 163 | /Volumes/GrayApps/Utilities/Resorcerer 2.4/Resorcerer: scriptable Mac OS X application [Carbon, prefers native OS X] |
---|
| 164 | type: 'APPL' creator: 'Doug' |
---|
[146] | 165 | bundle ID: com.mathemaesthetics.resorcerer |
---|
| 166 | version: 2.4 [0x2418010 = 37847056] |
---|
[3] | 167 | kind: Application |
---|
[146] | 168 | [...] |
---|
[3] | 169 | |
---|
| 170 | |
---|
| 171 | Q. Why doesn't launch support opening items as root? |
---|
| 172 | |
---|
| 173 | A. Apple eliminated this capability with the Mac OS X 10.1 Security |
---|
| 174 | Update. If at some point Apple restores this capability, 'launch' |
---|
| 175 | will be ready to support it. |
---|
| 176 | |
---|
| 177 | |
---|
| 178 | Q. Why do I get an error -600? |
---|
| 179 | |
---|
| 180 | A. A typical occurrence of this would be: |
---|
| 181 | |
---|
| 182 | % launch -n . |
---|
| 183 | launch: can't open items: unable to connect to system service. |
---|
| 184 | Are you logged in? (-600) |
---|
| 185 | |
---|
| 186 | In order to perform certain operations, launch needs to talk to |
---|
| 187 | various system services owned by the currently logged-on user. If you |
---|
| 188 | aren't using 'launch' from a terminal currently logged into the Mac OS |
---|
[166] | 189 | X GUI, certain operations may not work. Try opening Terminal, creating |
---|
| 190 | a new terminal window, and trying again. |
---|
[3] | 191 | |
---|
| 192 | Another possibility is to create your own interprocess messaging. |
---|
| 193 | For example, place this script in a file: |
---|
| 194 | |
---|
| 195 | #!/bin/sh |
---|
| 196 | PIPE=/tmp/.launchpipe |
---|
| 197 | [ -e $PIPE ] || mkfifo $PIPE |
---|
| 198 | while true; do |
---|
| 199 | read opts < $PIPE |
---|
| 200 | eval "/path/to/launch $opts" & # change this to launch's path |
---|
| 201 | done |
---|
| 202 | |
---|
| 203 | Then, define a function or alias. For zsh: |
---|
| 204 | |
---|
| 205 | rlaunch() { echo $@ > /tmp/.launchpipe } |
---|
| 206 | |
---|
| 207 | Or for tcsh: |
---|
| 208 | |
---|
| 209 | alias rlaunch 'echo \!* > /tmp/.launchpipe' |
---|
| 210 | |
---|
| 211 | Start the shell script above from the console, then you can use |
---|
| 212 | 'rlaunch' in place of 'launch' logged in from anywhere else. |
---|
| 213 | |
---|
| 214 | Thanks to robert <robert@allyourbass.org> for this suggestion. |
---|
| 215 | |
---|
| 216 | COMMENTS, SUGGESTIONS, BUG REPORTS, ETC. |
---|
| 217 | ---------------------------------------- |
---|
| 218 | |
---|
| 219 | Please send to the author, Nicholas Riley, at <launchsw@sabi.net>. |
---|
| 220 | |
---|
| 221 | VERSION HISTORY |
---|
| 222 | --------------- |
---|
| 223 | |
---|
[214] | 224 | 1.1 - unreleased |
---|
[265] | 225 | - -L: send "launch" (ascr/noop) event to app, bypasses automatic |
---|
[304] | 226 | opening of untitled document, etc. |
---|
[214] | 227 | - -o: pass command-line arguments (broken, r. 4474993) |
---|
| 228 | - display content type ID (UTI) |
---|
| 229 | - switched to new LSOpen APIs (now requires Mac OS X 10.4 or later) |
---|
[265] | 230 | - switched to new date formatting APIs (the old ones are deprecated) |
---|
[214] | 231 | - for compatibility with open(1), take app path as argument to -a |
---|
[304] | 232 | - Universal Binary, compatible with Intel Macs [Peter Hosey] |
---|
[166] | 233 | 1.0.1 - 3 April 2005 |
---|
| 234 | - prefer files to URLs; added -U for old behavior |
---|
| 235 | - don't display extraneous leading './' on file paths |
---|
| 236 | - display 'zero items', not '0 items', for consistency |
---|
| 237 | - display versions of non-applications |
---|
| 238 | - read Info.plists embedded in unbundled Mach-O applications |
---|
| 239 | - non-ASCII arguments are now handled with the filesystem, rather |
---|
| 240 | than the system encoding [Derrick Bass] |
---|
| 241 | - explicitly use UTF-8 everywhere else to properly interpret and |
---|
| 242 | display non-ASCII filenames and URLs |
---|
| 243 | - reading OSTypes and 'vers' resources, and opening URLs with |
---|
| 244 | Internet Config still uses the system encoding, converting as |
---|
| 245 | necessary for display |
---|
| 246 | - should be buildable on 10.2 again |
---|
[146] | 247 | 1.0 - 23 October 2003 |
---|
[137] | 248 | - work around CFBundle bug to report bundle identifiers and versions |
---|
| 249 | from resource forks of unpackaged Carbon applications and Classic |
---|
| 250 | applications [Lloyd Dupont] |
---|
[146] | 251 | - added descriptions for more error codes and clarified error |
---|
| 252 | reporting |
---|
| 253 | - output all errors to stderr |
---|
| 254 | - provide better errors for -X option |
---|
| 255 | - restored -m: OS X bug is fixed in Panther |
---|
| 256 | - fixed a couple of tiny memory leaks |
---|
| 257 | - added man page [Hisashi T Fujinaka] |
---|
| 258 | - work around bug in LSOpenFromURLSpec opening multiple items in |
---|
| 259 | Mac OS X 10.3 |
---|
[127] | 260 | 1.0b2 - 9 March 2003 |
---|
| 261 | - fixed install instructions to create /usr/local/bin if needed |
---|
| 262 | - show bundle version with text, hex and integer representations |
---|
[52] | 263 | 1.0b1 - 14 December 2002 |
---|
| 264 | - accept "slack" (default http) URLs and email addresses with -l |
---|
| 265 | - accept input from stdin with '-' |
---|
| 266 | - open URLs with arbitrary applications when specified without -l |
---|
| 267 | - builds without compiler warnings |
---|
| 268 | 1.0a9 - 2 April 2002 |
---|
| 269 | - license, comments changes |
---|
| 270 | 1.0a8 - 29 March 2002 |
---|
| 271 | - errors with -l (from ICeCoffEE), added rlaunch script |
---|
| 272 | 1.0a7 - 3 March 2002 |
---|
| 273 | - print dates, sizes, folder valence, locked status for -f |
---|
| 274 | - don't abort on failure to obtain bundle information |
---|
| 275 | 1.0a6 - 30 November 2001 |
---|
| 276 | - fixed incorrect messages, broken -u and crash on -nu |
---|
| 277 | 1.0a5 - 28 November 2001 |
---|
| 278 | - print kind string for -f, still no new installer |
---|
| 279 | 1.0a4 - 20 November 2001 |
---|
| 280 | - [try to] use Installer VISE instead of InstallAnywhere |
---|
| 281 | 1.0a3 - 15 November 2001 |
---|
| 282 | - fixed package identification in -f, updated examples |
---|
| 283 | 1.0a2 - 15 November 2001 |
---|
| 284 | - -f, removed broken -m |
---|
| 285 | 1.0a1 - 14 November 2001 |
---|
| 286 | - renamed from "FindApp", launch by default, -u |
---|
| 287 | 1.0d5 - 7 November 2001 |
---|
| 288 | - option -s for launching as root [nonfunctional] |
---|
| 289 | 1.0d4 - 6 November 2001 |
---|
| 290 | - URL launching and Internet Config support |
---|
| 291 | 1.0d3 - 4 November 2001 |
---|
| 292 | - more robust, support for docs without app |
---|
| 293 | 1.0d2 - 4 November 2001 |
---|
| 294 | - options -opsbmhCX, -cin, documents |
---|
| 295 | 1.0d1 - 26 August 2001 |
---|
| 296 | - returns path of application identified by creator |
---|