Live data from Hacker News

macOS command-line tools you might not know about

saurabhs.org

171–180 of 454 posts

Re: macOS command-line tools you might not know about

#171

Earlier quoted context omitted.

I’ve been looking for a better way to do this than just setting my PC to never sleep. Thanks for this. Now I need to find a Mac alternative as well.

caffeinate is on Mac. caffeinate -d -i -u -s

Thanks very much for this.

Re: macOS command-line tools you might not know about

#172
post #8

`pbcopy` and `pbpaste` are one of my most-loved in the list. Dealing with some minified json, switching to iTerm, doing `pbpaste | json_pp | pbcopy` and having a clean output is _so_ nice.

It's cool to use pbcopy and pbpaste with your phone! Copy some text on the phone, and you can pbpaste it onto the Mac command line. So cool.

Re: macOS command-line tools you might not know about

#173
post #101
post #97

Earlier quoted context omitted.

Those are so useful that I wrote trivial shell functions that do the same under Linux.

Since I'm bouncing between OSX and Linux a lot, I have a shell script with the same name on each that boils down to: if [ `uname` == "Darwin" ]; then pbcopy else xsel --clipboard fi

why not just alias?

Re: macOS command-line tools you might not know about

#175
post #137

Caffeinate is definitely the one I miss most on Windows. Super handy to keep your machine awake whilst some task is ongoing.

I’ve been looking for a better way to do this than just setting my PC to never sleep. Thanks for this. Now I need to find a Mac alternative as well.

keeping you awake wraps this up in a menu bar icon that makes it easy to toggle on or off

https://keepingyouawake.app/

Re: macOS command-line tools you might not know about

#176
post #22

When mentioning `open` they should have noted that `open ` will open the given file with its associated app. It’s indispensable.

I also find myself using open -n -a to open a new separate instance of an application if I want to copy settings from one file to another or work on two files with separate instances of a program

Re: macOS command-line tools you might not know about

#177
post #8

`pbcopy` and `pbpaste` are one of my most-loved in the list. Dealing with some minified json, switching to iTerm, doing `pbpaste | json_pp | pbcopy` and having a clean output is _so_ nice.

Use the Apple shortcuts app and you can just copy some text and hit a keyboard shortcut. The Shortcuts app lets you run arbitrary shell command.

Re: macOS command-line tools you might not know about

#178

Years ago, I wrote a script to find something in a big blob of data and to alert me when it was done, I added a “say ” type phrase upon completion. I forgot about it and went to bed and was jolted awake hours later by what was clearly an “intruder” speaking to his accomplice, in my home office. Quite the relief when I realized what happened.

That's hilarious! Similar vein: there is a Metasploit module to induce the say command on post-exploited mac machines. I haven't seen it used in practice, but I eagerly watch for the eventual twitter thread that reads:

"So, I used the msf module that invokes `say` on a client's laptop"

Re: macOS command-line tools you might not know about

#179
I use:

``` #!/usr/bin/env bash

    set -u

    title=${2:-Shell}
    msg=$1

    osascript -e "display notification \"$1\" with title \"$title\""
```

As `~/bin/,notify` and put it at the end of long-running commands:

``` run_this_program && ,notify "Long program is done!" ```

Re: macOS command-line tools you might not know about

#180

Earlier quoted context omitted.

Especially open . if you need to drag a file somewhere. One thing that kind of breaks my muscle memory here is the opposite, something like firefox file.html doesn't work and you have to fiddle with the arguments to get open to launch a non-default application.

I use `open .` to open up a Finder window of the directory I'm currently in using Terminal so frequently that I've set up an alias for it -- alias op='open .'

It took me a while but I finally got open to open folders in a new Finder tab instead of opening a new window each time.

     function opent () {
        what=${1:-`pwd`}
        what=$(cd "$what"; pwd)
        osascript -e "tell application \"Finder\"
        activate
        set t to target of Finder window 1
        set toolbar visible of window 1 to true
        end tell
        tell application \"System Events\"
        keystroke \"t\" using command down
        end tell
        tell application \"Finder\"
        set target of Finder window 1 to POSIX file \"$what\"
        end tell" > /dev/null
    }

    ## opens current dir
    $ opent .
    ## same
    $ opent
Post reply on HN