I had no idea that all Windows applications understood command line arguments.
Whether or not that's the case, it is not the case on Mac OS. When you are using the Terminal application, you are interfacing with a BSD subsystem that follows all the patterns you would expect from a UNIX or Linux operating system.
There are plentiful resources out there to get familiar with the bash shell and *NIX command line. To get you started, the
man command will get you the manpage for whatever command you pass in. Generally all space-separated "words" you type after a command are treated as arguments for that command, at least until you hit some kind of output redirection or control character like
So in your example, you were calling
open and passing in
-page=5 as arguments. As you've observed,
open doesn't know what to do with most of these.
Anyway, let's dig deeper. Most applications (like Preview.app in this case) have an executable file somewhere in their application bundle. You can actually execute this (
/Applications/Preview.app/Contents/MacOS/Preview) to start Preview directly without going through
open, but only certain purpose-built executables will understand command-line arguments.
Preview is not one of them.
man command only works for commands that have had manpages installed, and these will typically only be commands in your shell's
$PATH variable. For other executables, (and usually for standard ones as well), you can try calling the executable with a
--help argument to get usage information whether or not it is in your path. This won't work for everything, but it's a common pattern.
So there may be a PDF reader out there whose executable understands command-line arguments, but if we're still working with Preview, we need to shift into a different paradigm--AppleScript. You can read all about it on Wikipedia, but the basics of it is that it's a natural language scripting language that allows you to programmatically send Apple Events to applications. Some applications implement extensive AppleScript libraries to allow for greater automation.
The good news here is that you can process AppleScript on the command line with
osascript. Even more good news is that people have already solved your AppleScript problem of getting Preview to flip to a page in a PDF here: https://discussions.apple.com/thread/3215851
So what your approach should be here to solve your problem is:
- Devise a terminal command to open your PDF in Preview
open file.pdf should work fine.
- Test an AppleScript to change the page of that PDF to the one you specify (use Script Editor.app).
- Learn enough about the command line to devise a statement that will execute both steps in one go.