Executing Keyboard Shortcuts Through Terminal

Discussion in 'macOS' started by Noah212, Nov 30, 2010.

  1. Noah212 macrumors newbie

    Joined:
    Nov 16, 2010
    #1
    I was wondering if it was possible to execute keyboard shortcuts by using terminal. Thanks.
     
  2. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #2
    Need more details. You can hit command+v to paste text into Terminal.
     
  3. Noah212 thread starter macrumors newbie

    Joined:
    Nov 16, 2010
    #3
    Let me clarify... Is it possible to run a keyboard shortcut, not by actually pressing the keys, but by entering a certain command into terminal (which would complete the task that the keyboard shortcut would have completed)?

    For example... Let's say I wanted to be able to shut down my computer via a terminal command. Given that ^⌥⌘ + eject will shut down the computer, would it be possible to somehow enter this command into terminal however, not with the keyboard shortcut, but by typing something (My question is what is this something?)?

    Let me know if you are still having trouble understanding my question. Thanks.
     
  4. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #4
  5. LPZ macrumors 65816

    Joined:
    Jul 11, 2006
    #5
    To shutdown from Terminal, enter

    Code:
    sudo shutdown -h now
    To reboot from Terminal, enter

    Code:
    sudo shutdown -r now
     
  6. Noah212 thread starter macrumors newbie

    Joined:
    Nov 16, 2010
    #6
    Thanks, I'll look into that.

    I appreciate your contribution to the discussion however, I'm looking for a terminal command which doesn't prompt a password.
     
  7. LPZ macrumors 65816

    Joined:
    Jul 11, 2006
    #7
    You can include your password in the command:

    Code:
    echo 'yourpasswordhere' | sudo -S shutdown -r now
     
  8. Mal macrumors 603

    Mal

    Joined:
    Jan 6, 2002
    Location:
    Orlando
    #8
    In general, you should be looking for ways to achieve the same result as hitting a particular keyboard shortcut, not to actually make the computer think you hit that shortcut. You'll be more likely to find the correct solution (like with the shutdown command from a couple posts ago).

    jW
     

Share This Page