简体   繁体   中英

Is there a way to know the options of a shell/terminal command/application?

What I would like to know is, if there is any way to get the options used by a command or application (having no manual entry. For example:

For the application ScreenSaverEngine , located in:

/System/Library/Frameworks/ScreenSaver.framework/Resources/ScreenSaverEngine.app/Contents/MacOS/

has the option -background which allows me to set the current screensaver as a desktop background.

./ScreenSaverEngine -background

Now I would like to do other stuff with this application, or at least I would like to know if there is a possibility to do other stuff. So I want to know all the other options of ScreenSaverEngine . I thought maybe some options are coded in the app, so I tried something like

strings ScreenSaverEngine | grep "-"

but without results. ScreenSaverEngine doesn't have a manual, so

man ScreenSaverEngine

won't help. I'd be happy for any suggestions :-).

(By the way I'm using MAC OS X).

For any arbitrary application, this is not possible, because the argv parameters passed to the program's main() function (in C) can be stored, parsed, and accessed any way the program wants. It could even write the parameters out to a file, and then read the file when it wants to know what options to use.

However, it looks like the command-line options are already documented. From CocoaDev :

The ScreenSaverEngine supports some special command line flags to aid in debugging:

-background -- All screen saver windows appear behind all other windows (behind Finder icons but in front of the desktop image). The password and gamma fade features are disabled. It will not exit on mouse or keyboard activity.

-debug -- Like -background, except mouse movement over the desktop causes it to exit. Very handy when running the ScreenSaverEngine in GDB. (Trying to get around my computer in this mode without causing it to exit reminds me of playing Don't Touch The Floor as a kid)

-module -- Loads the specified module rather than the module specified by the user defaults. accepts the same values as the moduleName node in ~/Library/Preferences/ByHost/com.apple.screensaver.*.plist For example, Flurry, Abstract, or Spectrum. It doesn't appear to accept full paths or URLs to .saver, .slideSaver, or .qtz files, however, so it's necessary to place the desired module in one of the typical ScreenSaver folders and reference it without the filename extension.

-window -- an additional command runs the screensaver in a window.

this can be combined with -background. example: -window -background

Here's a script I like to put in my path:

#!/bin/bash

usage() {
    echo "usage: $0 [options]"
    echo "  -background  Screen saver windows appear behind all other windows"
    echo "  -debug       Like -background, except mouse movement over the"
    echo "                 desktop causes it to exit"
    echo "  -module      Loads the specified module by name"
}

engine=/System/Library/Frameworks/ScreenSaver.framework/Resources\
/ScreenSaverEngine.app/Contents/MacOS/ScreenSaverEngine

while getopts "hbackgrounddebugmodule" opt; do
    case "${opt}" in
        h)
            usage
            exit 0
            ;;
    esac
done

$engine "$@"

Not sure about the accuracy of the result. But it makes logical sense.

I went ahead and looked to answer this question because apple broke the -background flag with High Sierra. Still an issue as of High Sierra 10.13.4

This was from my mac running Sierra 10.12.16 the executable is the same but it is in a different file location for HighSierra.

So to get this working. The ScreenSaverEngine is an executable file.

Strings is a command that clumps anything that looks like english. I need to cat the file to get a string output because by default it is reads as binary and does not give any result.

cat /System/Library/Frameworks/ScreenSaver.framework/Resources/ScreenSaverEngine.app/Contents/MacOS/ScreenSaverEngine | strings

I manually looked through the files but your could add this to see the files I eventually noticed:

/System/Library/Frameworks/ScreenSaver.framework/Resources/ScreenSaverEngine.app/Contents/MacOS/ScreenSaverEngine | strings | grep /System

Then I noticed that the program was calling this Versions/A/ScreenSaver

cat /System/Library/Frameworks/ScreenSaver.framework/Versions/A/ScreenSaver | strings

I manually looked through and spotted an Arguments section.

payoff: arguments

  • -idleCheck
  • -cornerCheck
  • -debug
  • -window
  • ss-windowed-mode=1
  • -numWindows
  • -background
  • -foreground
  • -loginWindow
  • -mainOnly
  • -module
  • -lockDelay
  • floatValue
  • -black
  • -noEarlyMouseCheck
  • argument '%@' not understood
  • Background mode is disabled because full screen application was detected.

no idea why there is not official documentation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM