macOS Open Sesame: what changed
Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.
Title: macOS Open Sesame
| Old | New | Line | |
|---|---|---|---|
| 1 | + | *(macOS only)* | |
| 2 | + | ||
| 3 | + | ## Overview | |
| 4 | + | ||
| 5 | + | The macOS `/usr/bin/open` command line utility is a veritable Aladdin's cave of utility. The command opens a file (or a directory or URL), just as if you had double-clicked the file's icon. If no application name is specified, the default application as determined via LaunchServices is used to open the specified file. If the file is in the form of a URL, the file will be opened as a URL. See [[Executing External Programs]] to run the command from within your application. | |
| 6 | + | ||
| 7 | + | ## Opening files | |
| 8 | + | ||
| 9 | + | Want to open a test.c file? | |
| 10 | + | ||
| 11 | + | ``` bash | |
| 12 | + | open test.c | |
| 13 | + | ``` | |
| 14 | + | ||
| 15 | + | Want to open your test.c file with TextEdit and not with Xcode? | |
| 16 | + | ||
| 17 | + | ``` bash | |
| 18 | + | open -a TextEdit test.c | |
| 19 | + | ``` | |
| 20 | + | ||
| 21 | + | or | |
| 22 | + | ||
| 23 | + | ``` bash | |
| 24 | + | open -e test.c | |
| 25 | + | ``` | |
| 26 | + | ||
| 27 | + | ## Opening directories | |
| 28 | + | ||
| 29 | + | Want to open Finder at a particular directory, say the user's Documents directory? | |
| 30 | + | ||
| 31 | + | ``` bash | |
| 32 | + | open ~/Documents | |
| 33 | + | ``` | |
| 34 | + | ||
| 35 | + | ## Opening URLS | |
| 36 | + | ||
| 37 | + | Open our favourite website: | |
| 38 | + | ||
| 39 | + | ``` bash | |
| 40 | + | open https://wiki.freepascal.org | |
| 41 | + | ``` | |
| 42 | + | ||
| 43 | + | Safari not your favourite? Use FireFox maybe: | |
| 44 | + | ||
| 45 | + | ``` bash | |
| 46 | + | open -a FireFox https://wiki.freepascal.org | |
| 47 | + | ``` | |
| 48 | + | ||
| 49 | + | ## Opening applications | |
| 50 | + | ||
| 51 | + | Want to open another copy of a running application? Normally macOS would simply bring the already-running application to the foreground, but: | |
| 52 | + | ||
| 53 | + | ``` bash | |
| 54 | + | open -n -a TextEdit | |
| 55 | + | ``` | |
| 56 | + | ||
| 57 | + | Want the `open` command to wait until the application opened has exited? | |
| 58 | + | ||
| 59 | + | ``` bash | |
| 60 | + | open -W -n -a TextEdit | |
| 61 | + | ``` | |
| 62 | + | ||
| 63 | + | ## Opening Preference Panes | |
| 64 | + | ||
| 65 | + | Want to open the Security Preferences Pane? | |
| 66 | + | ||
| 67 | + | ``` bash | |
| 68 | + | open "x-apple.systempreferences:com.apple.preference.security" | |
| 69 | + | ``` | |
| 70 | + | ||
| 71 | + | How about the Firewall tab of the Security Preferences pane? | |
| 72 | + | ||
| 73 | + | ``` bash | |
| 74 | + | open "x-apple.systempreferences:com.apple.preference.security?Firewall" | |
| 75 | + | ``` | |
| 76 | + | ||
| 77 | + | Note that this scheme was new in Yosemite (macOS 10.10) and that Apple subsequently restricted use of the URL scheme in El Capitan (macOS 10.11). | |
| 78 | + | ||
| 79 | + | ## More options | |
| 80 | + | ||
| 81 | + | For the full gamut of open command options, open a Terminal and call up the Unix man page: | |
| 82 | + | ||
| 83 | + | ``` bash | |
| 84 | + | man open | |
| 85 | + | ``` | |
| 86 | + | ||
| 87 | + | ## See also (cross-platform) | |
| 88 | + | ||
| 89 | + | - [[opendocument|OpenDocument]] | |
| 90 | + | - [[OpenURL]] | |
| 91 | + | ||
| 92 | + | --- | |
| 93 | + | *From the Free Pascal wiki, page "macOS Open Sesame", as it stood on 2023-03-31 after a change by Trev, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).* | |
| 94 | + | Category: Lazarus | |
| 95 | + | Category: macOS |
