Search Explore
  • gregoriol · 3 years ago

    `tmutil` could be added to this list, it's a management cli for Time Machine

    • hoherd · 3 years ago

      I don't even use Time Machine for my off-machine backups, but I use tmutil to create local snapshots so I can easily back out of changes by using the Time Machine GUI to restore files from the snapshot.

    • Etheryte · 3 years ago

      Neat, I was not aware of `networkQuality`. A good replacement for opening up Speedtest or whatnot when you just want to figure out if the network is slow or something else is up.

      • gargs · 3 years ago

        It seems to grossly underestimate my upload bandwidth!

        • audessuscest · 3 years ago

          same

          • samstave · 3 years ago

            What are you, a station wagon full of thumb drives?

            • varenc · 3 years ago

              It tests your bandwidth while fully saturating your upload AND your download. If maxing out your upload has a huge impact on your download (like, a 70% drop), then that’s probably a sign you could tweak your network for better flow control.

              That’s sort of the idea of `networkQuality`. It’s a new idea for how to measure that’s different from the standard speed test.

              Through if you run it with the `-s` flag it’ll test them sequentially.

              • gargs · 3 years ago

                In my case, it appears that maximizing my download has a huge impact on my upload as well, which makes sense from a TCP/IP point of view. In this case, do you mean the ISP's flow control?

                • varenc · 3 years ago

                  I'm sure others know waaay more about this, but I think it's a thing you can improve locally. Though usually I think of it as the other way around, where maxing out upload severely impacts download. My understanding is that this causes bufferbloat[0], making packets queue up for a long time on your gateway, ultimately limiting you to way less bandwidth then you should be able to get.

                  My one experience with this is on Ubiquiti hardware where there's a feature called "Smart Queues" you can enable. Really it's FQ_CODEL[1] under the hood. If you tell it your real maximum up/down bandwidth, minus ~5%, it'll enforce those limits in a way that prevents buffer bloat and lets you use nearly your full download bandwidth even when your upload bandwidth is maxed out. On Ubiquiti gear this has a CPU impact since it has move some traffic handling from dedicated hardware to the CPU. But it was a huge night and day difference for me. After enabling this, having a couple people on Zoom calls (highish upload) no longer tanked everyone else's download speed.

                  Also I think this stuff matters more when you have a large multi-user network. For normal home life, definitely not worth it. (In my case it was wifi for ~20 people).

                  [0] https://en.wikipedia.org/wiki/Bufferbloat [1] https://en.wikipedia.org/wiki/CoDel

            • zgluck · 3 years ago

              I can't find any (official) documentation on how it measures the speed. Against which target?

              Edit: Found https://www.macinstruct.com/tutorials/how-to-check-your-macs... which says:

              "The networkquality tool uses Apple’s CDN (https://mensura.cdn-apple.com/api/v1/gm/config) as a target"

              The contents of this file (for me):

                { "version": 1,
                  "test_endpoint": "sesto4-edge-bx-021.aaplimg.com",
                  "urls": {
                      "small_https_download_url": "https://mensura.cdn-apple.com/api/v1/gm/small",
                      "large_https_download_url": "https://mensura.cdn-apple.com/api/v1/gm/large",
                      "https_upload_url": "https://mensura.cdn-apple.com/api/v1/gm/slurp",
                      "small_download_url": "https://mensura.cdn-apple.com/api/v1/gm/small",
                      "large_download_url": "https://mensura.cdn-apple.com/api/v1/gm/large",
                      "upload_url": "https://mensura.cdn-apple.com/api/v1/gm/slurp"
                   }
                }
              • Etheryte · 3 years ago

                I find solace in the fact that even at large companies, there's still enough whimsy to name your upload endpoint slurp.

                • varenc · 3 years ago

                  It’s a new proposed standard that’s gaining support. People are building alternative party implementations for it: https://github.com/network-quality/goresponsiveness

                  Try running it with `-s` to see if you get speed tests that resemble what you expect. The idea is that maxing out both links at once is a better measure of network quality than sequence speed tests. Also it’s new RTT metric is key.

                • iNic · 3 years ago

                  `mdfind` and `networkQuality` seem very useful!

                  • hk1337 · 3 years ago

                    I was aware of about half of these but textutil, networkUtility, and sips I didn’t not and look really interesting

                    • oneeyedpigeon · 3 years ago

                      Yeah, sips has a lot of potential. The article doesn't mention it, but it can crop as well which could be a real game-changer!

                      • jfb · 3 years ago

                        We heavily used `sips` when I was at Apple, because it was quicker than writing code against QuickTime or the other rendering subsystems.

                      • boffinAudio · 3 years ago

                        Wut? No fs_usage? Easily one of the most useful of them all ..

                        https://www.manpagez.com/man/1/fs_usage/

                        I can't count the number of times a bit of fs_usage foo has helped me dig out of a seriously messy pile of network, file and page fault issues ..

                        • photonerd · 3 years ago

                          Useful, but definitely more niche & less generally applicable than the others.

                        • rockbruno · 3 years ago

                          Xcode uses `mdfind` to provide symbols in crash reports and for Instruments, and is the reason why it seems to have a life of its own and work only when it wants to. Spotlight indexing is extremely flaky for reasons I'm not aware of.

                          • klausa · 3 years ago

                            `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.

                            • eddieroger · 3 years ago

                              I don't remember when I learned about these, but they've been game changers, and everyone I've shared them with feels the same way. I use your use case often as well, though through `jq` because I'm more familiar with it, and sometimes wish to do transforms.

                              • nerdponx · 3 years ago

                                You can use `python -m json.tool` for just JSON formatting, which is convenient now that Python is available by default in most Linux distros. Jq is really excellent though.

                              • kps · 3 years ago

                                On Linux I have these wrap xsel or xclip, and likewise open to xdg-open.

                                Now, for your Mac example — if that's a specific pipeline you often use, you can write a Service menu entry to do it in place, without switching to a terminal.

                                • andelink · 3 years ago

                                  +1 to the service menu actions. They are so handy, but often forgotten/overlooked. I think maybe a discoverability issue.

                                • pmarreck · 3 years ago

                                  I have linux/macos-agnostic bash functions in my dotfiles that unify this to “clip” and “paste” (since “copy” is too close semantically to “cp”)

                                  • svieira · 3 years ago

                                    And I have one that unifies _both_ to `clip` so you can put the same command in both sides of the pipe, e. g. to turn a line-delimited blob on your clipboard to a space-separated one:

                                        clip | tr '\n' ' ' | clip
                                    
                                    https://github.com/svieira/dotfiles/blob/a3654d6a194e3689978...

                                        # Use clipboard in shell pipelines
                                        # clip | xargs echo           # uses pbpaste
                                        # ps -A | grep search | clip  # uses pbcopy
                                        clip() {
                                          [ -t 0 ] && pbpaste || pbcopy
                                        }
                                    • pmarreck · 3 years ago

                                      Holy crap. Of course! You win! Amazing!

                                      Simple is genius

                                      • pmarreck · 3 years ago

                                        So to check if there's anything sitting on stdin without reading it I've been using

                                        `if read -r -t0; then` # returns true if there is data but times out instantly so it doesn't consume any

                                        Is `[ -t 0 ]` more idiomatic? Apparently it fails on this case: function < file

                                        `read -r -t0` is Bash-only though and not POSIX, but it will work regardless of what type of data is on stdin

                                        • naniwaduni · 3 years ago

                                          [ -t 0 ] instead checks whether stdin (fd 0) is a tty.

                                    • inanutshellus · 3 years ago

                                      I love this flow! Such a powerful and clean way to solve text issues.

                                          # This will remove Windows double-spaced empty lines from your copy/paste buffer
                                          alias winlines="sed '/^$/{$!{N;s/\n//;};}'"
                                          
                                          # pbw = [P]aste [B]uffer to fix [W]indows line endings
                                          alias pbw="pbpaste | winlines | pbcopy"
                                      
                                      Also - if you want `pbpaste` and `pbcopy` on Linux...

                                          # imitate MacOS's paste buffer copy/paste:
                                          alias pbcopy='xsel --clipboard --input'
                                          alias pbpaste='xsel --clipboard --output'
                                      • computerfriend · 3 years ago

                                        Here's the xclip way (almost the same actually).

                                            alias pbcopy="xclip -selection clipboard"
                                            alias pbpaste="xclip -selection clipboard -o"
                                        • lordgrenville · 3 years ago

                                          I use this, and another Mac affordance I copy in Linux is

                                              alias open="xdg-open"
                                      • iuafhiuah · 3 years ago

                                        I find it so annoying that these only work with plain text and RTF. On X11 there is `xclip`[0] and on Wayland there is `wl-clipboard`[1] both of which support binary file formats either through parsing the header or explicitly setting the MIME type.

                                        This means you can do things like copy an image from the terminal and paste it into a graphical program like a browser or chat client and vice-versa. Also can be very useful in shell scripts for desktop automation.

                                        The workaround on MacOS is to use AppleScript via `osascript` to `set the clipboard to...`.

                                          [0] https://github.com/astrand/xclip
                                          [1] https://github.com/bugaevc/wl-clipboard
                                        • ksala_ · 3 years ago

                                          Since you mention both pbcopy and iTerm - I love https://github.com/skaji/remote-pbcopy-iterm2. I do most of the work on a remove Linux server, treating my MacBook as mostly a dumb terminal, and being able to transparently copy from the remove to my local clipboard is so nice.

                                          • whartung · 3 years ago

                                            I’ll have to try that. More than once I’ve been logged in to a remote host and got “pbcopy not found” “What!?… oh, right.“

                                            • tstack · 3 years ago

                                              The tmux integration in iterm is also very nice for remote work if you haven’t tried it out.

                                              • ksala_ · 3 years ago

                                                I have tried it, but for whatever reason I just don't like it. I prefer just running tmux in iTerm with no integration.

                                                On the topic, you can also integrate tmux with the native clipboard - I have set copy-pipe to the remote pbcopy, so any selection done in tmux get copied to my local clipboard. I also just found out that tmux also support it natively (https://github.com/tmux/tmux/wiki/Clipboard#the-set-clipboar...).

                                            • omginternets · 3 years ago

                                              If I had a nickel for each `cat foo.json | jq | pbcopy`, I'd be a rich man :)

                                              • maleldil · 3 years ago

                                                That's a useless use of cat. You can use `jq . foo.json | pbcopy` or `jq < foo.json | pbcopy`.

                                                • jdbartee · 3 years ago

                                                  Speaking for myself, the first form is more natural- even if it’s a useless cat, because I’m always cat-ing files to see their structure. Then progressively tacking on different transforms. And then finally putting it in whatever I want as output.

                                                  It’s so ingrained, I’m more likely than not to just write it out that way even when I know exactly what I’m doing from the onset.

                                                  • paulddraper · 3 years ago

                                                    You could consider

                                                        < foo.json jq | pbcopy
                                                    • jonnycomputer · 3 years ago

                                                      Yes, this iterative procedure is often why "useless" cats get put into it. It's a very effective way of processing regular text information.

                                                      e.g.

                                                      I need to grab some info from textfile.txt to use as arguments to a function.

                                                      cat textfile.txt

                                                      looks like its comma delimited.

                                                      cat textfile.txt | cut -d, -f 2-5

                                                      ah, its the third and fourth column i need

                                                      cat textfile.txt | cut -d, -f 3-4 | grep '123456'

                                                      perfect

                                                      cat textfile.txt | cut -d, -f 3-4 | grep 123456 | tr , ' '

                                                      myfunc $(cat textfile.txt | cut -d, -f 3-4 | grep 123456 | tr , ' ')

                                                      • gumby · 3 years ago

                                                        > cat textfile.txt

                                                        > looks like its comma delimited.

                                                        Interesting; why wouldn't you use `head`? Who knows how big textfile.txt is?

                                                        • rovr138 · 3 years ago

                                                          `file` will tell you too

                                                          • jonnycomputer · 3 years ago

                                                            Won't tell you the delimiter.

                                                          • yrro · 3 years ago

                                                            Don't forget to pipe head into 'cat -v'... that text file could contain _anything_!

                                                            • gunapologist99 · 3 years ago

                                                              Thank you for pointing this out! This is much safer.

                                                              • lelandbatey · 3 years ago

                                                                I really recommend folks use "less" over cat, especially keyboard oriented folks. Different terminal emulators don't always have the scroll behavior I want, not do they always allow me to search the file I'm looking at. "less" does all those things, in nearly every environment no matter the terminal emulator, and has other wonderful options to boot (chop long lines so they don't wrap can be nice for logs, line numbers can be VITAL, etc).

                                                                I still uselessly use cat though, it's such a nice way to build a pipeline.

                                                                • jmhammond · 3 years ago

                                                                  My useless cat is that I always use `cat file | less` when I could just `less file`.

                                                                  I've been typing cat for over 25 years. Old habits die hard.

                                                                  • rconti · 3 years ago

                                                                    I hate that when I use `less`, then quit, the output goes away.

                                                                    • LgWoodenBadger · 3 years ago

                                                                      You can run "less -X" for that, but it may have other problems depending on how you use less (e.g. scrolling up, etc.)

                                                                • jonnycomputer · 3 years ago

                                                                  generally, speaking, if you don't have an idea of how big the file is, or it would take up too much real-estate on your terminal window, sure. 100%. It was just an example.

                                                                  lot's of times we sort of know what we are working with, but don't remember the particulars especially

                                                              • jamespullar · 3 years ago

                                                                I've been using bat as a cat replacement for a while now. It includes paging, syntax highlighting, line numbers, and is generally very performant.

                                                                https://github.com/sharkdp/bat

                                                                • patrec · 3 years ago

                                                                  If you're using zsh, you can just replace any instance of

                                                                      $ cat somefile ...
                                                                  
                                                                  with

                                                                      $ <somefile ...
                                                                  
                                                                  For bash, this only works if you have at least one `|`.
                                                                  • ddingus · 3 years ago

                                                                    I did this last time I saw it come up and was surprised! Doing it makes perfect sense in hindsight. Neato!

                                                                  • fastaguy88 · 3 years ago

                                                                    As a scientist who cares about reproducibility, the big difference between the "useless cat" and providing the input file name on the command line is that, in the latter case, the program can capture that file name and reproduce it. That is harder when using stdin.

                                                                    Many of my programs and scripts start output with the line: # cmd arg1 arg2 arg3 ...

                                                                    and simply echo back lines that start with '#'. That way, I have an internal record of the program that was run and the data file that was read (as well as previous parts of the analysis chain).

                                                                    And, 'R' ignores lines starting with '#', so the record is there, but does not affect later analyses.

                                                                  • nicky0 · 3 years ago

                                                                    In what way do you see those alternatives as superior?

                                                                    • paulddraper · 3 years ago

                                                                      They avoid an unnecessary invocation of the cat executable.

                                                                      Instead, they open a file descriptor and pass that.

                                                                      Tiny difference but there you go.

                                                                      • latexr · 3 years ago

                                                                        To add, searching for “useless use of cat” will yield several results for those interested in learning more. Other examples include “useless use of echo” and “useless use of ls *”.

                                                                      • adrianmonk · 3 years ago

                                                                        Not just that, but also all the bytes have to go through an extra pipe. Presumably they're copied an extra time because of this.

                                                                        When you run "cmd < file", the command reads from stdin, which pulls directly from the file. When you do "cat file | cmd", "cat" opens the file, reads from there, and writes to a pipe. Then "cmd" reads from its stdin, which is a pipe.

                                                                      • omginternets · 3 years ago

                                                                        >They avoid an unnecessary invocation of the cat executable.

                                                                        And ... ?

                                                                        • wpm · 3 years ago

                                                                          I teach shell scripting. Cat invocations are cheap and help learners understand and keep clear where input is coming from, and where it is going. There are no awards or benefits to reducing the number of lines, commands invoked, or finding the shortest possible way to perform a task in a script. There are plenty of detriments to reading and understanding though when we try to obfuscate this to save 1ms of execution time on a script that is going to execute near instantaneously anyways.

                                                                          In short, I straight up don't care.

                                                                          • revscat · 3 years ago

                                                                            I 100% agree with you. My only defense of OP is that `<` is something tends to be forgotten. Like everyone else in this thread I go to `cat` first for things like this. But sometimes I forget that even `<` exists, and the callout is a nice reminder.

                                                                        • derefr · 3 years ago

                                                                          If the command is meant to stream through something really fast by using a large buffer size, then prepending a cat(1) will limit the incoming buffer size to ~4k.

                                                                          • vram22 · 3 years ago

                                                                            Interesting.

                                                                            Maybe use dd with one of its blocksize options, then?

                                                                            Not at a terminal, can't check.

                                                                          • gdavisson · 3 years ago

                                                                            It usually doesn't matter much, but there are some situations where it can matter a lot. For one thing, you can't use seek() on a pipe, so e.g. `cat bigfile | tail` has to read through the entire file to find the end, but `tail bigfile` will read the file backward from the end, completely skipping the irrelevant beginning and middle. With `pv bigfile | whatever`, pv (which is basically a pipeline progress indicator) can tell how big file is and tell you how for through you are as a percentage; with `cat bigfile | pv | whatever`, it has no idea (unless you add a flag to tell it). Also, `cat bigfile | head` will end up killing cat with a SIGPIPE signal after head exits; if you're using something like "Unofficial bash strict mode" [1], this will cause your script to exit prematurely.

                                                                            Another sometimes-important difference is that if there are multiple input files, `somecommand file1 file2 file3` can tell what data is coming from which file; with `cat file1 file2 file3 | somecommand` they're all mashed together, and the program has no idea what's coming from where.

                                                                            In general, though, I think it's mostly a matter of people's expertise level in using the shell. If you're a beginner, it makes sense to learn one very general way to do things (`cat |`), and use it everywhere. But as you gain expertise, you learn other ways of doing it, and will choose the best method for each specific situation. While `cat |` is usually an ok method to read from a file, it's almost never the best method, so expert shell users will almost never use it.

                                                                            [1] http://redsymbol.net/articles/unofficial-bash-strict-mode/

                                                                          • nojs · 3 years ago

                                                                            The “useless cat” meme needs to die. Everyone is aware that most commands accept a file argument, but looking up the arguments and their ordering is annoying and using cat for things like this is just fine.

                                                                            • omginternets · 3 years ago

                                                                              This. "Useless cat" is more useful than "useless file-arg".

                                                                              • epcoa · 3 years ago

                                                                                The redirect always works though - that is not a program argument, that is handled by the shell. Apparently not everyone is aware of that.

                                                                                • hdb2 · 3 years ago

                                                                                  granted, it is a little snarky and maybe the snark isn't appropriate in today's tech environment. but no, things like "useless use of cat" do not need to go away, because they make me better at what I do in little ways. those little ways add up over time.

                                                                                  > but looking up the arguments and their ordering is annoying

                                                                                  you seem to be arguing for complacency. taking your idea to an extreme, why learn to do _anything_ well?

                                                                                  • burnished · 3 years ago

                                                                                    Everyone is not aware, new people are joining all the time.

                                                                                  • Someone · 3 years ago

                                                                                    Is there any shell that has cat as a built-in?

                                                                                    Such a shell could remove some of the more common cases.

                                                                                    • hnlmorg · 3 years ago

                                                                                      All of them do. Including bash. It’s just not the same syntax (ie ‘< filename’).

                                                                                      But I honestly think people who try to optimise away ‘cat’ are optimising the wrong thing. If one extra fork() is that detrimental then don’t use a shell scripting language.

                                                                                      For a lot of people, “useless” ‘cat’ enables them to write a pipeline in the order that their brain farts out the requirements for the pipeline. So they’ve optimised for human productivity. And given the human brain is slower than a few extra fork()s, I think optimising for one’s brain makes more sense here.

                                                                                        • hnlmorg · 3 years ago

                                                                                          Literally the next sentence after the one you quoted explains my point:

                                                                                          > It’s just not the same syntax (ie ‘< filename’).

                                                                                          Reading from a file isn’t a hard problem. Having a good UX for doing that is where most shells fall apart. And that’s basically what ‘cat’ offers here: an improved UX.

                                                                                          Having ‘cat’ as a shell builtin wouldn’t really solve the complaints raised by “useless use of” anyway because you’d still be piping (and in some cases, fork()ing too). You couldnt really use ‘cat’ as syntactic sugar for ‘<‘ because things start to get really weird if you want to pass flags to ‘cat’ or even redirect the output to something other than a pipe. And given ‘cat’ is POSIX (https://en.m.wikipedia.org/wiki/List_of_Unix_commands#/media...) the current behaviour of shells is, in my opinion, correct. This is why my own shell has a differently named builtin that approximately serves the purpose of ‘cat’ but for instances when you need the command built into the shell and it can’t just be passing a file handle to the next command (in my case, because i wanted to pass metadata out-of-band as well as the file contents)

                                                                                    • agmm · 3 years ago

                                                                                      I like to use `pbcopy` when exporting public keys to external services like GitHub.

                                                                                      `cat ~/.ssh/mykey.pub | pbcopy`

                                                                                      • _rend · 3 years ago

                                                                                        You can even simplify this further by feeding `pbcopy` the key directly using file redirection instead of a pipe:

                                                                                        `pbcopy < ~/.ssh/mykey.pub`

                                                                                        (I use this all the time myself!)

                                                                                        • wincy · 3 years ago

                                                                                          I love this tool too!

                                                                                          except one time I quickly typed

                                                                                          `cat ~/.ssh/mykey | pbcopy`

                                                                                          And sent it straight away to my coworker on Slack.

                                                                                          I then spent the rest of the day making a new private key and adding my new pubkey to all of the 1000+ servers I had root access to. I mean we had tools to help but it still wasn’t fun.

                                                                                          With great power/convenience comes the potential to do dumb things at lightning speeds!

                                                                                          • oxygen_crisis · 3 years ago

                                                                                            I might start naming my private key files ~/.ssh/keyname.PRIVATE after hearing that story...

                                                                                            • plorkyeran · 3 years ago

                                                                                              That's not a bad idea. I've never actually made the same mistake, but I have caught it at the last moment and having tab complete not pick the private one first would help.

                                                                                              • wincy · 3 years ago

                                                                                                It would have avoided it! I was using tab and forgot to select .pub as you correctly surmised. I was a junior dev at the time and all the seniors got a good laugh out of it, and I use it as a cautionary tale about trying to be TOO overeager and efficient.

                                                                                              • gunapologist99 · 3 years ago

                                                                                                Userify would have made that pretty painless (all it really seems to do is update the authorized_keys across all of your servers every minute or so)

                                                                                                • superq · 3 years ago

                                                                                                  also userify allows you to set up sudo access on some of the servers and not others, so that'd take care of the other root-access issue you have. (sudo also provides auditing/logging controls that are useful in a multi-user environment)

                                                                                                • vinay_ys · 3 years ago

                                                                                                  If you literally have ssh root access to 1000+ servers, using certificates will be more secure and convenient than directly using public key.

                                                                                                • itslennysfault · 3 years ago

                                                                                                  Where are you pasting the pretty json to view it?

                                                                                                  I do this a lot as well, but just paste the minified json directly into VS Code and then OPT+SHIFT+F to format it.

                                                                                                  • nicky0 · 3 years ago

                                                                                                    `jq` acts as a pretty json viewer (among other things)

                                                                                                  • nine_k · 3 years ago

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

                                                                                                    • timf · 3 years ago

                                                                                                      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
                                                                                                      • cerved · 3 years ago

                                                                                                        why not just alias?

                                                                                                        • timf · 3 years ago

                                                                                                          Could be an alias, I have a limited set of aliases for each type of system. But I keep a repository of hundreds of personal shell scripts and it fit better there.

                                                                                                    • jonnycomputer · 3 years ago

                                                                                                      Yes. I use it a great deal, but I haven't gotten used to using the linux equivalents. I guess that would be either xsel or xclip. Maybe I should create a "pbcopy" that runs one of those. I like to minimize the cognitive load when I switch between mac and linux command line environments.

                                                                                                      • lloeki · 3 years ago

                                                                                                        Another frequent use I have, applying random diffs with git:

                                                                                                            git diff | pbcopy
                                                                                                            pbpaste | git apply
                                                                                                        • js2 · 3 years ago

                                                                                                          You can also use `git format-patch` and `git am` if you want to apply the same commit to multiple repos, a use-case I sometimes I have.

                                                                                                          • verst · 3 years ago

                                                                                                            I should use `git format-patch` instead of creating a mock draft PR (which I end up deleting) and modifying the URL to add `.patch` and then downloading the patch file haha. `git format-patch` would probably be faster :)

                                                                                                        • cancerhacker · 3 years ago

                                                                                                          alias pbg='pbpaste | fgrep --color -i "`pbpaste -pboard find`"'

                                                                                                          select all in a terminal window with pages of log data and cmd-c copy; find the one phrase you want to find in that data and cmd-e to put it in the find pasteboard; cmd-n new window, type pbg to isolate the log lines.

                                                                                                          • philsnow · 3 years ago

                                                                                                            TIL about named pasteboards https://developer.apple.com/documentation/appkit/nspasteboar...

                                                                                                            I recognize that your pbg alias works for pretty much any text you could copy, but I wanted to mention, in case you're looking at log files with plain old less, there's the & limiter, which limits the current view to only lines matching a regular expression (or, if you type ^R during a & prompt, for a text match).

                                                                                                            If you type ^N or ! during a & prompt it will limit the view to those lines that do not match the expression.

                                                                                                            These view limits stack, so you can "&WARN<enter>" to see all lines that have WARN in them, and then maybe you want to see just a certain PID so "&12345<enter>" and you'll only see lines with both WARN and 12345, but then that one module is printing out a bunch of messages you think are safe to ignore so you do "&!modulename<enter>" and it filters out log lines that match modulename. Very handy and less is everywhere.

                                                                                                          • lkbm · 3 years ago

                                                                                                            Oh man. I recently threw together a "j2p" script to make converting between json and python dicts simpler, and combining it with pbcopy/pbpaste will make it so much better:

                                                                                                              #!/usr/bin/env python3
                                                                                                              import sys
                                                                                                              import json
                                                                                                              
                                                                                                              print(json.load(sys.stdin))
                                                                                                            • atoav · 3 years ago

                                                                                                              Or directly from the commandline:

                                                                                                                  pbcopy | python -c 'import sys; import json; print(json.load(sys.stdin))' | pbpaste
                                                                                                              • tomviner · 3 years ago

                                                                                                                The Python json library is callable as a module:

                                                                                                                    pbcopy | python -m json.tool | pbpaste
                                                                                                                
                                                                                                                It has a load options:

                                                                                                                    $ python -m json.tool --help
                                                                                                                    usage: python -m json.tool [-h] [--sort-keys] [--no-ensure-ascii] [--json-lines] [--indent INDENT | --tab | --no-indent | --compact] [infile] [outfile]
                                                                                                                
                                                                                                                    A simple command line interface for json module to validate and pretty-print JSON objects.
                                                                                                                
                                                                                                                    positional arguments:
                                                                                                                      infile             a JSON file to be validated or pretty-printed
                                                                                                                      outfile            write the output of infile to outfile
                                                                                                                
                                                                                                                    options:
                                                                                                                      -h, --help         show this help message and exit
                                                                                                                      --sort-keys        sort the output of dictionaries alphabetically by key
                                                                                                                      --no-ensure-ascii  disable escaping of non-ASCII characters
                                                                                                                      --json-lines       parse input using the JSON Lines format. Use with --no-indent or --compact to produce valid JSON Lines output.
                                                                                                                      --indent INDENT    separate items with newlines and use this number of spaces for indentation
                                                                                                                      --tab              separate items with newlines and use tabs for indentation
                                                                                                                      --no-indent        separate items with spaces rather than newlines
                                                                                                                      --compact          suppress all whitespace separation (most compact)
                                                                                                            • mig39 · 3 years ago

                                                                                                              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.

                                                                                                              • nojs · 3 years ago

                                                                                                                It creeps me out when the clipboard is unexpectedly shared between my phone and computer. And since the feature seems to turn on randomly but not reliably when I want it to, I’d rather it just didn’t exist.

                                                                                                                • emmjay_ · 3 years ago

                                                                                                                  Disabling Handoff is currently the only way to disable Universal Clipboard.

                                                                                                                  * Mac: Go to System Preferences > General > uncheck Allow Handoff.

                                                                                                                  * iPhone: Go to Settings > General > Handoff > uncheck Handoff.

                                                                                                                  • pjot · 3 years ago

                                                                                                                    Make sure both your phone and computer have Wi-Fi and Bluetooth turned on.

                                                                                                                    • MikeTheGreat · 3 years ago

                                                                                                                      I'm curious why the Bluetooth is required?

                                                                                                                      Requiring WiFi makes (so the phone/computer is on a network and can communicate with the other devices), but what's the benefit of Bluetooth? Does it only work when the phone and computer are near each other?

                                                                                                                      • hanche · 3 years ago

                                                                                                                        Bluetooth is used to discover peers and to initiate communication. Thus handoff works even on a wifi network that blocks broadcasts. It even works when no wifi network is present, by setting up an ad hoc network for the connection. (Disclaimer: This is all I know. The details seem rather murky, as handoff is a proprietary Apple protocol.)

                                                                                                                        • lathiat · 3 years ago

                                                                                                                          The requirements are here: https://support.apple.com/en-au/HT209455

                                                                                                                          Turning off Bluetooth or wifi may be one of the more common reasons it doesn’t work. Some people never do that, but others do.

                                                                                                                        • borski · 3 years ago

                                                                                                                          Yes.

                                                                                                                      • andrei_says_ · 3 years ago

                                                                                                                        For me it’s one of the top benefits of the Apple ecosystem.

                                                                                                                        The only drawback is that yes it only works most of the time. And when it doesn’t I get infuriated.

                                                                                                                        Glitches happen without any change to settings or network on my side - it works now, and 5 min later doesn’t.

                                                                                                                        • comprev · 3 years ago

                                                                                                                          Integration is the primary reason I enjoy using Apple ecosystem. My phone, laptop, tablet and watch all work seamlessly together.

                                                                                                                          I use most of Apple's "built in" applications like Mail, Notes, Photos, etc. with Firefox (instead of Safari) probably the only exception to that.

                                                                                                                          • devilbunny · 3 years ago

                                                                                                                            It’s wonderful when it works. For reasons beyond my comprehension, the Watch unlock for my Mac only works ~10% of the time.

                                                                                                                              • devilbunny · 3 years ago

                                                                                                                                I tried this yesterday. It... helped. But what I've now found is that if I escape out of the password prompt (which will turn the screen off again) and then try to unlock it a second time, the watch unlock will be triggered. I wonder if it's something about waking from sleep. (I also wonder if it would have worked before to do the same thing, but it never occurred to me to try.)

                                                                                                                            • andrei_says_ · 3 years ago

                                                                                                                              Yes it’s 1Password. I use the very old, iOS only non subscription version 7.something. But I think sometimes it works (copy from iOS paste on MacOS).

                                                                                                                              • Ukudala · 3 years ago

                                                                                                                                Wonder how many of us are out there!? Long live this app and workflow, iCloud sync ftw.

                                                                                                                                • andrei_says_ · 3 years ago

                                                                                                                                  Yes, I use this app multiple times a day, each time with the added satisfaction of knowing I own the app and not a subscription. Even if my credit card expires I will still have access to my passwords.

                                                                                                                                • e28eta · 3 years ago

                                                                                                                                  I’m on the same version of 1password, probably for similar reasons.

                                                                                                                                  In their iOS app, there’s an entry in Settings -> Security -> Allow Universal Clipboard which lets you opt-in to passwords through the clipboard. I suspect there’s something similar on macOS.

                                                                                                                            • jacurtis · 3 years ago

                                                                                                                              I have a clipboard manager application called "Paste" (creative i know). Its an awesome app for a million reasons. But one thing I like is that it allows me to see and hear when my iphone copy worked.

                                                                                                                              So I have it enabled so there is a sound when something goes into the clipboard. Even on my mac, I have come to rely on that audio feedback. But it has the added benefit that when I am using my phone in front of my computer and I copy something on my phone, I immediate (and it is impressively fast... maybe a 200ms delay), I hear the chime that something was added to my clipboard on my mac. So it gives you that good feedback that a copy "worked".

                                                                                                                              You can also shift+cmd+V to see the clipboard history, which is another complimentary tool with universal clipboard because if a paste isn't working as expected you can see if the universal copy never "took" (as you mentioned it is semi-unreliable), or if it just got overridden. You can then use the navigator to paste the older item.

                                                                                                                              • zackmorris · 3 years ago

                                                                                                                                I wonder if it's this one: https://apps.apple.com/us/app/paste-clipboard-manager/id9678...

                                                                                                                                I've noticed that more and more apps on both macOS and iOS sniff the clipboard contents and randomly clobber it. I usually notice it in apps like Sourcetree, where I'll click something or do a certain action and suddenly I can't paste anymore. I even get a feel for it, like my mind detects the pattern that empties the clipboard so I sense when I can no longer paste, but I can't figure out concrete repeatable steps to make it happen. On iOS it's more random, and I feel like it's probably Facebook doing it, or maybe websites in Safari. I just assume that everything is spying on my clipboard contents now, hoping to log secrets/passwords and PII to sell to scammers.

                                                                                                                                I have to say, this is one of the more disappointing developments from Apple, that they certainly must know by now about these clipboard shenanigans, but have done nothing to stop them. They need to implement permissions that deny all apps the ability to get/set the clipboard by default, and have an option to ask the user whether so-and-so app can access the clipboard (outside of normal copy/paste), every time with the option to allow always. And all clipboard access attempts should probably get logged somewhere.

                                                                                                                                • jamwil · 3 years ago

                                                                                                                                  I think iOS now has per-app permissions/notifications around clipboard reads.

                                                                                                                                  • nativeit · 3 years ago

                                                                                                                                    I would think requiring opt-in for clipboard functionality would be the more radical option that would leave most users (myself included, I would imagine) scratching their heads when they can’t copy/paste as a matter of course. Maybe you meant something more specifically related to 3rd-party sniffing/modifying clipboard contents, but I haven’t really encountered that outside of apps such as CopyQ and Paste, and they are pretty explicit and intentional about their functions.

                                                                                                                                    I have found a lot of utility with cross-device copy/paste. I know it requires the somewhat mysterious phantom Bluetooth/Wi-Fi connectivity that AirPlay/Airdrop use, so if I have disabled Bluetooth on my device, for example, it will no longer work. I could see where it might not be fully reliable enough to count on, I have experienced inexplicable failures, not often but enough to understand that it might not be some folks’ default preference. As part of the “handoff” function, it can be disabled in Settings at least.

                                                                                                                                • nomel · 3 years ago

                                                                                                                                  > is unexpectedly shared between my phone and computer

                                                                                                                                  There was a prompt asking if I wanted to enable it, when I set up my phone/Mac. Same setup screen that asks if you want to enable location, Siri, etc.

                                                                                                                              • renewiltord · 3 years ago

                                                                                                                                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.

                                                                                                                                • philsnow · 3 years ago

                                                                                                                                  This is interesting, thank you. I've been automating various things with Hammerspoon but (I think) it's limited to what you can reach with either a11y or osascript / the NS dictionary for the app you want to manipulate, but Shortcuts seems to have some actions that aren't in the NS dictionary.

                                                                                                                                  For instance, in Shortcuts, I see that there's a "Pin Notes" action for Notes.app, but I don't see anything for pinning notes when I open Notes.app with "File -> Open Dictionary..." in Script Editor.

                                                                                                                                  (In this case it's likely that Notes.app has the a11y bits necessary to run that action from Hammerspoon, but it would probably be easier to go through Shortcuts.)

                                                                                                                                • burnished · 3 years ago

                                                                                                                                  Json pretty printing in the terminal? Bless, didn't know about that and it is perfect

                                                                                                                                  • adolph · 3 years ago

                                                                                                                                    pb[paste|copy] are a life improver. Here is a one-liner to edit the pasteboard contents in vim.

                                                                                                                                      pbpaste > tmp; vim tmp; cat tmp | pbcopy; rm tmp;
                                                                                                                                    
                                                                                                                                    I also use pbpaste to append various notes to files, but since pbpaste doesnt have a newline at the end I wind up using:

                                                                                                                                      echo "$(pbpaste)" >> notes.txt
                                                                                                                                  • flaminHotSpeedo · 3 years ago

                                                                                                                                    Also a fun one to combine with `open` if you have a bunch of web URLs to open

                                                                                                                                    • m463 · 3 years ago

                                                                                                                                      I have a script always running that polls for youtube URLs using pbpaste and runs yt-dl

                                                                                                                                      then just highlight any youtube link and COPY

                                                                                                                                      later when I have time, I can use quicklook to browse directory of youtube videos.

                                                                                                                                      • ErneX · 3 years ago

                                                                                                                                        That’s a great hack thanks for the tip.

                                                                                                                                        • RoyGBivCap · 3 years ago

                                                                                                                                          FYI: yt-dlp is more up to date and faster, AFIK: https://github.com/yt-dlp/yt-dlp

                                                                                                                                          I download and save it as 'ytdl' for convenience, but I use it all the time on twitter too.

                                                                                                                                          • m463 · 3 years ago

                                                                                                                                            sorry mistyped, that's what I use

                                                                                                                                        • n8henrie · 3 years ago

                                                                                                                                          So much of my Linux use is over ssh from a MacOS client that I've made a `pbcopy` executable that just pipes stdin over ssh to my MacBook to its pbcopy (with a dedicated ssh key that runs this as a forced command). Makes it super nice to be on an SSH session and `pbcopy` some content to my MacOS clipboard!

                                                                                                                                          • danielagos · 3 years ago

                                                                                                                                            That sounds amazing, I always wanted to do that! Do you have a guide or some script to help with it? Otherwise, I will try to do it on my own.

                                                                                                                                            • n8henrie · 3 years ago

                                                                                                                                              Happy to share, but I'm away from my MacBook for the next 2-3 weeks. I'll ping you when I have access to the code again.

                                                                                                                                              • desro · 3 years ago

                                                                                                                                                I'm also super interested in this! I've had many amusing moments of instinctively typing either `pbcopy` or `pbpaste` on remote boxes followed by a brief moment of confusion when my local clipboard isn't updated :)

                                                                                                                                            • SushiHippie · 3 years ago

                                                                                                                                              You might want to have a look at osc52

                                                                                                                                              • n8henrie · 3 years ago

                                                                                                                                                I have! Unfortunately not supported in MacOS Terminal.app, which I'm otherwise very satisfied with (have tried iTerm2, use Alacritty on Linux, just like Terminal.app).

                                                                                                                                                  • n8henrie · 3 years ago

                                                                                                                                                    I don't think wrapping my entire shell session in a moderately complex third party tool (that maybe just uses pbcopy under the hood[1]) counts as "simply" when compared to my existing solution which just pipes over ssh and a couple bash scripts.

                                                                                                                                                    But thank you for the share, it is interesting!

                                                                                                                                                    [1]: https://github.com/roy2220/osc52pty/blob/master/oscexecutor....

                                                                                                                                                    • athrun · 3 years ago

                                                                                                                                                      This tool isn’t doing anything particularly complex. It sets up a new pty, attaches the child process to it, listens for OSC52 control codes, and calls pbcopy when appropriate.

                                                                                                                                                      You can wrap your ssh session with it and you’re done.

                                                                                                                                                      It’s very elegant and multiple orders of magnitude less complex than something like tmux.

                                                                                                                                            • escot · 3 years ago

                                                                                                                                              I use the following to edit contents of my clipboard:

                                                                                                                                                  pbpaste | vipe | pbcopy
                                                                                                                                              
                                                                                                                                              
                                                                                                                                              Where vipe is a util for inserting your editor (vim) in the middle of a pipe. From: https://joeyh.name/code/moreutils/
                                                                                                                                              • rasen58 · 3 years ago

                                                                                                                                                This is great utility I didn't know about! Thanks!

                                                                                                                                                But do you know why it doesn't seem to work with the `pbfilter` function?

                                                                                                                                                If I do directly `pbpaste | vipe | pbcopy`, then it opens vim and the clipboard text is pasted there. But if I run `pbfilter | vipe`, then vim opens with a blank buffer.

                                                                                                                                                   function pbfilter() {
                                                                                                                                                      if [ $# -gt 0 ]; then
                                                                                                                                                          pbpaste | "$@" | pbcopy
                                                                                                                                                      else
                                                                                                                                                          pbpaste | pbcopy
                                                                                                                                                      fi
                                                                                                                                                   }      
                                                                                                                                                
                                                                                                                                                
                                                                                                                                                It seems that the number of args is 0 for some reason
                                                                                                                                                • nneonneo · 3 years ago

                                                                                                                                                  I think you have to use `pbfilter vipe`, as the argument to pbfilter is inserted into the middle of the pipe.

                                                                                                                                              • gdavisson · 3 years ago

                                                                                                                                                I find that the `pbpaste | something | pbcopy` idiom is common enough that it's worth having a shell function for it:

                                                                                                                                                  pbfilter() {
                                                                                                                                                      if [ $# -gt 0 ]; then
                                                                                                                                                          pbpaste | "$@" | pbcopy
                                                                                                                                                      else
                                                                                                                                                          pbpaste | pbcopy
                                                                                                                                                      fi
                                                                                                                                                  }       
                                                                                                                                                
                                                                                                                                                
                                                                                                                                                Then you can use something like `pbfilter json_pp` or `pbfilter base64 -d` or `pbfilter sed 's/this/that/'` or whatever.

                                                                                                                                                This version also can also act as a plain-text-only filter. If you just use `pbfilter` with no argument, it'll remove any formatting from the text in the pasteboard, leaving just straight plain text.

                                                                                                                                                It does have a some limitations, though: you can't use it with an alias, or pipeline, or anything complex like that. The filter command must be a single regular command (or function) and its arguments.

                                                                                                                                                • dredmorbius · 3 years ago

                                                                                                                                                  I've aliased that (and its equivalents on Linux and Android/Termux) to 'xc' and 'xp' (for X11 Copy and X11 Paste, as I'd originated this on Linux).

                                                                                                                                                  Being able to populate or read from the system clipboard (or secondary clipboard!), or to feed it, including by reading from or writing to pipes is wonderful.

                                                                                                                                                  • duffyjp · 3 years ago

                                                                                                                                                    I have an alias that while trivally simple is quicker to type and remember. It copies whatever file you give it to the clipboard which is super handy. I use it with the "Compare with Clipboard" to diff a file in Rubymine for example.

                                                                                                                                                    alias clip='pbcopy <'

                                                                                                                                                    • systems_glitch · 3 years ago

                                                                                                                                                      Best way to get ssh keys into the paste buffer too.

                                                                                                                                                      • user00012-ab · 3 years ago

                                                                                                                                                        my favorite vim command:

                                                                                                                                                        :w !pbcopy

                                                                                                                                                        or visual selection, and then :w !pbcopy

                                                                                                                                                      • gemstones · 3 years ago

                                                                                                                                                        qlmanage is super useful for converting SVG to PNG easily, too! I use it like this:

                                                                                                                                                        qlmanage -t -s 1000x1000 -o ~/Pictures/foo.png ~/Pictures/foo.svg

                                                                                                                                                        To turn an square SVG into a PNG without installing anything extra or using an online image tool

                                                                                                                                                        • juujian · 3 years ago

                                                                                                                                                          Is ```textutil -convert``` using pandoc under the hood?

                                                                                                                                                          • kainjow · 3 years ago

                                                                                                                                                            IIRC it’s using the Cocoa class NSAttributedStrimg. These conversions have been in the OS for a long time.

                                                                                                                                                            • secretsatan · 3 years ago

                                                                                                                                                              I thought pandoc used to be installed on MacOS, I def remember using it for something useful a couple of years ago but I check now and it's not there.

                                                                                                                                                            • bovermyer · 3 years ago

                                                                                                                                                              I just freaked out my cat using `say`. I'm going to enjoy this too much.

                                                                                                                                                              • tmearnest · 3 years ago

                                                                                                                                                                I used to work at a 24 hr end user tech support call center. They didn’t use Macs, but we had a machine for the techs to use to understand what the customer is looking at. I wrote a script to sleep until late at night then start saying weird/creepy stuff to mess with the overnight crew.

                                                                                                                                                                • bendecoste · 3 years ago

                                                                                                                                                                  Combined with the `yes` command is very good fun ;)

                                                                                                                                                                  • ubermonkey · 3 years ago

                                                                                                                                                                    YEARS ago, when my nephew was young, he was playing with my mother's Macbook Air at Thanksgiving.

                                                                                                                                                                    I administer that machine for her (to the extent that such a thing is needed), and so I knew (a) her login and (b) that SSH was open.

                                                                                                                                                                    Me combining remote access with "say" made for a very memorable morning for that kid.

                                                                                                                                                                    • gen_greyface · 3 years ago

                                                                                                                                                                      try it out with different voices, for starters try

                                                                                                                                                                        say "process failure" -v trinoids
                                                                                                                                                                      
                                                                                                                                                                      you can find all the available voices with

                                                                                                                                                                        say -v '?' 
                                                                                                                                                                      
                                                                                                                                                                      or from Accessibility>Spoken-Content>System-voice>Manage-voices
                                                                                                                                                                      • mesarvagya · 3 years ago

                                                                                                                                                                        I liked the option of using `-v organ`

                                                                                                                                                                        • memco · 3 years ago

                                                                                                                                                                          A nice feature I discovered recently is -a: you can give it a specific audio device, which falls back to the default if not present. I use it to report when builds finish through my monitor speakers in case I'm not wearing headphones. If I'm on the go and don't have the monitor connected it plays through the speakers.

                                                                                                                                                                          • robertoandred · 3 years ago

                                                                                                                                                                            We must rejoice in this morbid voice.

                                                                                                                                                                        • nanovision · 3 years ago

                                                                                                                                                                          Not a big fan of command lines. but my most used shortkey is ALT+M with Maccy installed.

                                                                                                                                                                          • mattl · 3 years ago

                                                                                                                                                                            What does that do?

                                                                                                                                                                            • nanovision · 3 years ago

                                                                                                                                                                              Maccy ( https://maccy.app/ ) is a clipboard manager for Mac and by Clicking ALT+M , it shows all the recent copied texts in a popup.

                                                                                                                                                                              • mattl · 3 years ago

                                                                                                                                                                                Is that Option-M?

                                                                                                                                                                                • nanovision · 3 years ago

                                                                                                                                                                                  I use external logitech keyboard, where it's Alt+M but yes, it's actually Command+M on Macbook

                                                                                                                                                                                  • mattl · 3 years ago

                                                                                                                                                                                    Aha! They make Logitech keyboards with Macintosh keys now btw.

                                                                                                                                                                          • ExoticPearTree · 3 years ago

                                                                                                                                                                            pbcopy/pbpaste are a lifesaver when doing stuff on the command line that has a lot of output and piping is not something you can do.

                                                                                                                                                                            networkQuality is something I really wish I knew about sooner.

                                                                                                                                                                            • hereonout2 · 3 years ago

                                                                                                                                                                              Also for things like sharing public ssh keys. Instead of "can you send me your public key" and getting something with random line breaks depending on the users text editor I just have to ask them to "cat ~/.ssh/id_rsa.pub | pbcopy".

                                                                                                                                                                              I also alias pbcopy / pbpaste on Linux too, so useful!

                                                                                                                                                                              • superq · 3 years ago

                                                                                                                                                                                The random linebreaks are ok - SSH can handle them. (that's how Userify does it I think, too. it replicates whatever the user provides.. no judgment :)

                                                                                                                                                                                • hereonout2 · 3 years ago

                                                                                                                                                                                  Ah, it's more for ~/.ssh/authorized_keys which is one key per line.

                                                                                                                                                                                  • superq · 3 years ago

                                                                                                                                                                                    right (authorized_keys ignores blank lines and comments)

                                                                                                                                                                                • jcotton42 · 3 years ago

                                                                                                                                                                                  Fwiw, `clip` on Windows does the same as `pbcopy` (there's no analog to pbpaste built in though)

                                                                                                                                                                              • lapcat · 3 years ago

                                                                                                                                                                                Manage the Launch Services database:

                                                                                                                                                                                  /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister
                                                                                                                                                                                
                                                                                                                                                                                Manage file extended attributes (such as quarantine):

                                                                                                                                                                                  xattr
                                                                                                                                                                                
                                                                                                                                                                                Execute a script (AppleScript or JavaScript):

                                                                                                                                                                                  osascript -e <statement>
                                                                                                                                                                                • spookthesunset · 3 years ago

                                                                                                                                                                                  It’s weird how macs don’t come with a GUI for managing system services. Windows does.. that being said the number of times I’ve had to mess with system services on mac can probably be counted with a few fingers…

                                                                                                                                                                                  • cyberge99 · 3 years ago

                                                                                                                                                                                    You can also prepend #!/usr/bin/osascript to a script and then make it executable with chmod oag+x. You can then invoke it normally in bash: ./filename.sh (or whatever)

                                                                                                                                                                                  • callumprentice · 3 years ago

                                                                                                                                                                                    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 <some glib Rambo or Schwarzenegger>” 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.

                                                                                                                                                                                    • no-dr-onboard · 3 years ago

                                                                                                                                                                                      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"

                                                                                                                                                                                      • joshstrange · 3 years ago

                                                                                                                                                                                        I use Pushover for a few alerts so years ago I wrote a little bash script called `push` that you pass a title and optionally a body. Was very nice to to `./longRunningCommand && push "Task Done" "Here is a body"`. I'd sometimes combine this with my `beep` script that just makes a noise for when I know I'll still be at my computer but want to know when something finishes.

                                                                                                                                                                                        • desro · 3 years ago

                                                                                                                                                                                          What's the beep script like? Do you use the terminal bell or does it synthesize a tone?

                                                                                                                                                                                          • joshstrange · 3 years ago

                                                                                                                                                                                            Here is my beep script, it's almost embarrassingly basic. You can pick a different sound, I wanted one that wasn't too offensive/harsh and I've used this for 3-4+ years.

                                                                                                                                                                                            #!/bin/bash

                                                                                                                                                                                            afplay -v 3 /System/Library/Sounds/Glass.aiff

                                                                                                                                                                                        • jeremy_wiebe · 3 years ago

                                                                                                                                                                                          I often have multiple terminal tabs open. Sometimes I’ll run a command that ends up taking a while and switch away and forget about it.

                                                                                                                                                                                          So I added a fish command completion script that plays a beep with afplay if the task took longer than 5 seconds. It helps me get back on task for those “just long enough” tasks that I run.

                                                                                                                                                                                          • alanbernstein · 3 years ago

                                                                                                                                                                                            I like to use the "research complete" sample from StarCraft for this.

                                                                                                                                                                                            • IggleSniggle · 3 years ago

                                                                                                                                                                                              It's comments like this that remind me that HN is my tribe.

                                                                                                                                                                                            • datavirtue · 3 years ago

                                                                                                                                                                                              I would pay a lot of money to switch the voice to Arnold.

                                                                                                                                                                                            • donatj · 3 years ago

                                                                                                                                                                                              When mentioning `open` they should have noted that `open <file>` will open the given file with its associated app.

                                                                                                                                                                                              It’s indispensable.

                                                                                                                                                                                              • computerfriend · 3 years ago

                                                                                                                                                                                                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.
                                                                                                                                                                                                • alanpearce · 3 years ago

                                                                                                                                                                                                  If you set

                                                                                                                                                                                                      alias firefox="open -a Firefox"
                                                                                                                                                                                                  
                                                                                                                                                                                                  This will work
                                                                                                                                                                                                  • zora_goron · 3 years ago

                                                                                                                                                                                                    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 .'
                                                                                                                                                                                                    • ojosilva · 3 years ago

                                                                                                                                                                                                      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
                                                                                                                                                                                                  • lloeki · 3 years ago

                                                                                                                                                                                                    More than that, it sends a message to launchd/the app instead of forking on the spot.

                                                                                                                                                                                                    Sadly the app does get the shell's environment and it can't be disabled:

                                                                                                                                                                                                         Opened applications inherit environment variables just as if you had
                                                                                                                                                                                                         launched the application directly through its full path.  This behavior
                                                                                                                                                                                                         was also present in Tiger.
                                                                                                                                                                                                    
                                                                                                                                                                                                    Why this matters, e.g with vscode:

                                                                                                                                                                                                        - ensure vscode is fully closed
                                                                                                                                                                                                        - enter project directory, something sets vars in your shell (you manually or automatically via direnv)
                                                                                                                                                                                                        - code .
                                                                                                                                                                                                        - vscode process now has the env from the shell it was started
                                                                                                                                                                                                        - open another directory from the UI
                                                                                                                                                                                                        - vscode forks and inherits from its parent process, thus the other project window has the original shell's env
                                                                                                                                                                                                        - go to another directory
                                                                                                                                                                                                        - code .
                                                                                                                                                                                                        - vscode finds out it's already running, forks and opens another window. this window has the original shell env
                                                                                                                                                                                                        - fully quit vscode and reopen it, but via the app in /Applications
                                                                                                                                                                                                        - vscode opens, now has a blank environment for its main process, and forks form there to restore previous windows, which now lack the environment they had
                                                                                                                                                                                                    
                                                                                                                                                                                                    It's a) completely inconsistent and b) dangerous: imagine the original shell had a setting or secret in an env var that was shared to the second project (e.g virtualenv, deploy target, deployment key...)

                                                                                                                                                                                                    The same issue can happen with other apps but also tmux (the tmux daemon is spawned from the first tmux command, and then subsequent sessions from tmux-server; doing it another way is possible but nontrivial)

                                                                                                                                                                                                    https://github.com/microsoft/vscode/issues/15452

                                                                                                                                                                                                    https://github.com/microsoft/vscode/issues/108804#issuecomme...

                                                                                                                                                                                                    • lattalayta · 3 years ago

                                                                                                                                                                                                      I also find myself using open -n -a <application> 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

                                                                                                                                                                                                    • karmakaze · 3 years ago

                                                                                                                                                                                                      Another good one is 'hidutil' which can remap any keys without additional software. It's handy for things like remapping CapsLock to anything, etc. For actual full keyboard layouts though I'd use Ukelele[0].

                                                                                                                                                                                                      [0] https://software.sil.org/ukelele

                                                                                                                                                                                                      • ris58h · 3 years ago

                                                                                                                                                                                                        There is a helper tool for hidutil https://hidutil-generator.netlify.app/

                                                                                                                                                                                                        > It's handy for things like remapping CapsLock to anything

                                                                                                                                                                                                        It's a built-in MacOS feature that you can find in the keyboard settings.

                                                                                                                                                                                                        • varenc · 3 years ago

                                                                                                                                                                                                          to anything” is the key difference. MacOS only lets you remap it to other control keys.

                                                                                                                                                                                                          • ris58h · 3 years ago

                                                                                                                                                                                                            Yeah, I've missed that part.

                                                                                                                                                                                                      • maxfurman · 3 years ago

                                                                                                                                                                                                        I remember Caffeine used to be a third-party program that would prevent your Mac from sleeping, same behavior as the `caffeinate` here. Were they acquired and incorporated into the OS?

                                                                                                                                                                                                        • LanceH · 3 years ago

                                                                                                                                                                                                          Anyone know of a Ubuntu on WSL equivalent?

                                                                                                                                                                                                            • LanceH · 3 years ago

                                                                                                                                                                                                              Hoping for something in WSL land.

                                                                                                                                                                                                              • redacted · 3 years ago

                                                                                                                                                                                                                `vmIdleTimeout` in .wslconfig might be an option? Win 11 only though

                                                                                                                                                                                                            • input_sh · 3 years ago

                                                                                                                                                                                                              apt install caffeine

                                                                                                                                                                                                            • alexdbird · 3 years ago

                                                                                                                                                                                                              I believe that Caffeine was a fairly simple GUI wrapper for the existing caffeinate command

                                                                                                                                                                                                              • emodendroket · 3 years ago

                                                                                                                                                                                                                Yes. There is a similar product called Amphetamine now.

                                                                                                                                                                                                                • krackers · 3 years ago

                                                                                                                                                                                                                  From what I recall, caffeine app predated the caffeinate command (which was only introduced in lion). Caffeine.app also disables sleep via a completely different method than caffeinate. The latter uses a IOPMAssertion which is the recommended way to do it because it is visible in `pmset -g assertions` whereas the former doesn't use that approach (I forgot how exactly it did it, there's like 4 different methods on osx to prevent sleep).

                                                                                                                                                                                                                • meepmorp · 3 years ago

                                                                                                                                                                                                                  It's been cli util on macos for 10+ years. I remember a gui util called caffeinated, though.

                                                                                                                                                                                                                  • coldtea · 3 years ago

                                                                                                                                                                                                                    Caffeine was a front-end by a third party company. Used it back in the day, the command existed already though.

                                                                                                                                                                                                                    Since then I've moved to Amphetamine (same purpose menu-bar app, even stronger chemicals, has timed keep-awake etc).

                                                                                                                                                                                                                  • apozem · 3 years ago

                                                                                                                                                                                                                    I love pbcopy and miss it every time I ssh into my Raspberry Pi. Should be included in every shell environment as standard.

                                                                                                                                                                                                                    • dredmorbius · 3 years ago

                                                                                                                                                                                                                      A strong second to this, it was going to be my own comment ;-)

                                                                                                                                                                                                                    • BruceEel · 3 years ago

                                                                                                                                                                                                                      Nice list.

                                                                                                                                                                                                                      Also, hidutil (https://developer.apple.com/library/archive/technotes/tn2450...).

                                                                                                                                                                                                                      Example:

                                                                                                                                                                                                                           hidutil property --set '{"UserKeyMapping":[{"HIDKeyboardModifierMappingSrc":0x700000049,"HIDKeyboardModifierMappingDst":0x700000065}]}'
                                                                                                                                                                                                                      
                                                                                                                                                                                                                      For my PC keyboard, remaps "Ins" (normally useless under macOS) to something ("PC Execute") I can trap and remap with Keyboard Maestro.
                                                                                                                                                                                                                      • maratc · 3 years ago

                                                                                                                                                                                                                            hidutil property --set '{"UserKeyMapping":[{"HIDKeyboardModifierMappingSrc":0x700000064,"HIDKeyboardModifierMappingDst":0x700000035}]}'
                                                                                                                                                                                                                        
                                                                                                                                                                                                                        Remaps top left key on Euro-style keyboards from useless "paragraph" to useful "backtick".
                                                                                                                                                                                                                        • kevans91 · 3 years ago

                                                                                                                                                                                                                          Yes, this is great... I was given a Macbook with a Norweigan keyboard for testing a port of FreeBSD on it, and I quickly discovered that the keyboard layout remapping stuff available via the UI won't remap at least this one key to what I'd find on my US keyboard.

                                                                                                                                                                                                                        • hoherd · 3 years ago

                                                                                                                                                                                                                          not to be confused with hdiutil:

                                                                                                                                                                                                                              hdiutil detach /Volumes/some-usb-drive
                                                                                                                                                                                                                          
                                                                                                                                                                                                                              hdiutil makehybrid -joliet -o foo.iso ./srcfolder/
                                                                                                                                                                                                                            • xiaomai · 3 years ago

                                                                                                                                                                                                                              Oh wow, this is amazing. I had been unable to _swap_ esc and caps lock on the mac until now.

                                                                                                                                                                                                                          • whalesalad · 3 years ago

                                                                                                                                                                                                                            `pbcopy | jq | pbpaste` is a very frequent command that I run to quickly format json in the clipboard.

                                                                                                                                                                                                                            I use pbcopy and pbpaste probably all day long and always miss it in Linux environments.

                                                                                                                                                                                                                            • photonerd · 3 years ago

                                                                                                                                                                                                                              You should Alias xsel if you’re in an x environment

                                                                                                                                                                                                                              • hoherd · 3 years ago

                                                                                                                                                                                                                                Also `alias pbsort='pbpaste | sort | pbcopy'`

                                                                                                                                                                                                                                • ngai_aku · 3 years ago

                                                                                                                                                                                                                                  Slick! I need to figure out how to get something like this for SQL

                                                                                                                                                                                                                                • Version467 · 3 years ago

                                                                                                                                                                                                                                  Great list. Didn't know about pbcopy/pbpaste, very useful.

                                                                                                                                                                                                                                  I use open regularly. Often to open a directory in finder and preview a file. Looks like I can just use qlmanage from now on.

                                                                                                                                                                                                                                  Not sure I'd use screencapture manually, but I'm sure there are some automations that could benefit from this.

                                                                                                                                                                                                                                • birdyrooster · 3 years ago

                                                                                                                                                                                                                                  I never knew sips was a thing, cool!

                                                                                                                                                                                                                                  • detourdog · 3 years ago

                                                                                                                                                                                                                                    Most people would rather criticize than actually look for goodness.

                                                                                                                                                                                                                                  • brazzledazzle · 3 years ago

                                                                                                                                                                                                                                    Probably want to check your policies if using a business-owned mac. Caffeinate probably violates your security policies if it’s a decent sized company.

                                                                                                                                                                                                                                    • pantulis · 3 years ago

                                                                                                                                                                                                                                      Why?

                                                                                                                                                                                                                                      • salzig · 3 years ago

                                                                                                                                                                                                                                        with sleep comes "unlock screen" ;)

                                                                                                                                                                                                                                        • pantulis · 3 years ago

                                                                                                                                                                                                                                          Ouch! Thanks!

                                                                                                                                                                                                                                          • Groxx · 3 years ago

                                                                                                                                                                                                                                            Caffeinate with -u and then lock your screen. (Apple menu -> lock screen)

                                                                                                                                                                                                                                            It'll stay connected/running/screen-on/etc but it's still locked.

                                                                                                                                                                                                                                        • computerfriend · 3 years ago

                                                                                                                                                                                                                                          You can lock the screen while caffeinated though.

                                                                                                                                                                                                                                          • brazzledazzle · 3 years ago

                                                                                                                                                                                                                                            Automatic screensaver enable after a period of inactivity is considered a fail safe control.

                                                                                                                                                                                                                                            • wpm · 3 years ago

                                                                                                                                                                                                                                              `caffeinate` can set assertions, the same assertions that Zoom or PowerPoint or Keynote do to stop the screen going to sleep during a meeting or presentation, the same assertions that the browsers can set during streaming video, so you absolutely can bypass whatever your admins set using `caffeinate -dmisu` which sets every assertion available.

                                                                                                                                                                                                                                              • brazzledazzle · 3 years ago

                                                                                                                                                                                                                                                It’s not about capabilities, it’s about policy. Willfully violating security policies is generally going to go over poorly.

                                                                                                                                                                                                                                          • Macha · 3 years ago

                                                                                                                                                                                                                                            I thought that was its primary use case these days

                                                                                                                                                                                                                                          • semanticist · 3 years ago

                                                                                                                                                                                                                                              /System/Library/PrivateFrameworks/Apple80211.framework/Versions/A/Resources/airport
                                                                                                                                                                                                                                            
                                                                                                                                                                                                                                            I set an alias in my shell so this is just 'airport', lets you interact with the wifi settings - I particularly like 'airport -s' for doing a scan of the local wifi networks, since it shows signal strength and channel information right there, which is helpful when troubleshooting.
                                                                                                                                                                                                                                            • lloeki · 3 years ago

                                                                                                                                                                                                                                              It also separates 2.4GHz and 5.0GHz bands and shows security details (which matters sometimes e.g band steering or automatic same-SSID signal-strength-based AP selection doesn't work)

                                                                                                                                                                                                                                            • prvc · 3 years ago

                                                                                                                                                                                                                                              What it really needs is a way to prevent sleeping when the lid is closed (only) during a system update.

                                                                                                                                                                                                                                              • pseufaux · 3 years ago

                                                                                                                                                                                                                                                Not a bad list of basic macOS specific cli tools. For a more in depth list, I usually reference https://ss64.com/osx/.

                                                                                                                                                                                                                                                • latexr · 3 years ago

                                                                                                                                                                                                                                                  A tad outdated. At a glance I see it’s missing `networkQuality` (introduced in Monterey) and `realpath` (added in Ventura).

                                                                                                                                                                                                                                                  • drewmol · 3 years ago

                                                                                                                                                                                                                                                    Yes it is, but the forum is current and the creator replies very actively. I’ll ask if he plans update.

                                                                                                                                                                                                                                                • reaperducer · 3 years ago

                                                                                                                                                                                                                                                  One I use a lot: mdls.

                                                                                                                                                                                                                                                  It's ls for metadata. Very helpful for getting quick and scripted access to the date/time when and the latitude/longitude where a photograph was taken.

                                                                                                                                                                                                                                                  Also, the say command is a lot more versatile than it seems.

                                                                                                                                                                                                                                                  Combined with the ability to save the speech to an audio file, my wife uses it as the disc jockey for her little hobby AM radio station. It introduces the song and does little station IDs and such.

                                                                                                                                                                                                                                                  You can customize it with dozens of dozens of voices, some in very high quality.

                                                                                                                                                                                                                                                  When a song from her Japanese playlists comes on, it switches to one of the Japanese voices. I don't speak Japanese, so I don't know if it actually translates the DJ words into Japanese, but it sounds pretty close to my untrained ears.

                                                                                                                                                                                                                                                  • pantulis · 3 years ago

                                                                                                                                                                                                                                                    powermetrics gives a lot of energy usage info per CPU core and apps.

                                                                                                                                                                                                                                                    • coding123 · 3 years ago

                                                                                                                                                                                                                                                      Caffienate will save my ass going forward. I don't know how many times I end up being the person that runs some batch job on my system...

                                                                                                                                                                                                                                                    • wkat4242 · 3 years ago

                                                                                                                                                                                                                                                      Not a command-line tool but the network link conditioner is also really great. Never seen such a tool on another OS

                                                                                                                                                                                                                                                      You can simulate a really bad network. Latency, bandwidth, packet loss etc. Great for testing but also if people insist on cameras being on. Just screw up the connection so bad that everyone gets annoyed with your blocky image and robot voice and suggest you turn off video and then you make it 'magically' ok - lol

                                                                                                                                                                                                                                                      • elpakal · 3 years ago

                                                                                                                                                                                                                                                        You can do similar magic with Charles Proxy fyi

                                                                                                                                                                                                                                                        • obituary_latte · 3 years ago

                                                                                                                                                                                                                                                          Never had heard of this before. Some other cool tools in the "additional tools for X-Code" package which I had also never heard of. https://developer.apple.com/download/all/

                                                                                                                                                                                                                                                          Thanks for sharing.

                                                                                                                                                                                                                                                          • llimllib · 3 years ago

                                                                                                                                                                                                                                                            I've used AU Lab to pipe my microphone input through my headphones, which is apparently how professionals like to record audio (a "monitor" so you can hear how you sound), but I couldn't get used to it

                                                                                                                                                                                                                                                            • desro · 3 years ago

                                                                                                                                                                                                                                                              How was the latency when you last tried it? Most outboard audio interfaces (even inexpensive ones like the Focusrite Scarletts with ≤ 2 inputs) have a "direct monitor" feature that is as close to zero-latency as you can reasonably get.

                                                                                                                                                                                                                                                              • llimllib · 3 years ago

                                                                                                                                                                                                                                                                I don’t remember, or have context for how it feels when it’s instant, so I’m a bad tester.

                                                                                                                                                                                                                                                                Maybe that’s why I didn’t like it, a tiny bit of latency seems like a killer in that scenario

                                                                                                                                                                                                                                                          • nine_k · 3 years ago

                                                                                                                                                                                                                                                            Toxiproxy is such a tool for everywhere else, and it did help me test and improve networking code for poor conditions: timeouts, retries, packet loss, etc.

                                                                                                                                                                                                                                                              • pwenzel · 3 years ago

                                                                                                                                                                                                                                                                Network Link Conditioner rules. I pair it with `mitmproxy` for debugging native apps.

                                                                                                                                                                                                                                                                • macshome · 3 years ago

                                                                                                                                                                                                                                                                  You can also use `rvictl` to connect to a development iOS device’s network device for grab a tcp dump.

                                                                                                                                                                                                                                                                  Also Instruments has a really nice network capture tool now.

                                                                                                                                                                                                                                                                  • wkat4242 · 3 years ago

                                                                                                                                                                                                                                                                    Thanks! I'm on BSD so this is great to hear!

                                                                                                                                                                                                                                                                  • ipozgaj · 3 years ago

                                                                                                                                                                                                                                                                    You can do that with standard Linux tooling available on every distribution, see https://man7.org/linux/man-pages/man8/tc.8.html. What you're specifically looking for is `qdisc netem`, it can inject packet loss, reordered packets, duplicate packets, delay and more.

                                                                                                                                                                                                                                                                    • xenadu02 · 3 years ago

                                                                                                                                                                                                                                                                      Note that NLC is a GUI interface to control dummynet and PF (packet filter). It sets up rules to inject packet relay and drop a certain percentage of packets based on the profile.

                                                                                                                                                                                                                                                                      You can use dnctl and pfctl on macOS to do similar things and more.

                                                                                                                                                                                                                                                                      • cpach · 3 years ago

                                                                                                                                                                                                                                                                        Ditto can also be useful for backup and restore since, AFAICT, it preserves file meta data. (Unlike rsync for example.)

                                                                                                                                                                                                                                                                        • desro · 3 years ago

                                                                                                                                                                                                                                                                          `ditto` will also preserve resource forks, which is occasionally necessary for not breaking apps or installer pkgs. I've had to use it when doing a semi-automated deployment of some zipped-up software to a hundred or so Macs via bash over ARD. `ditto -xkv`

                                                                                                                                                                                                                                                                      • api · 3 years ago

                                                                                                                                                                                                                                                                        Here are my favorites:

                                                                                                                                                                                                                                                                            alias sleepoff="sudo pmset -a disablesleep 1"
                                                                                                                                                                                                                                                                        
                                                                                                                                                                                                                                                                            alias sleepon="sudo pmset -a disablesleep 0"
                                                                                                                                                                                                                                                                        
                                                                                                                                                                                                                                                                        This fully disables sleep, period. Just make sure you don't leave it unplugged too long, but on Apple Silicon it lasts for quite a long time.
                                                                                                                                                                                                                                                                        • kec · 3 years ago

                                                                                                                                                                                                                                                                          this is just a worse version of caffeinate which is more likely to leave you with a dead battery.

                                                                                                                                                                                                                                                                        • reacharavindh · 3 years ago

                                                                                                                                                                                                                                                                          Is there any easy shortcut to resizing an image by percentage or fitting to a specific size?

                                                                                                                                                                                                                                                                          Many a times, a website says "file needs to be no bigger than 2 MB", and I need to scramble with Preview app to resize teh app until it falls below that limit. A cli tool for that action would be very handy.

                                                                                                                                                                                                                                                                          • itake · 3 years ago

                                                                                                                                                                                                                                                                            I typically use https://www.digitalocean.com/community/tutorials/workflow-re...

                                                                                                                                                                                                                                                                            You can even do bulk cmds with cli on images:

                                                                                                                                                                                                                                                                              for x in ls *.webp; do  ffmpeg -i $x ${x%.webp}.png; done
                                                                                                                                                                                                                                                                            
                                                                                                                                                                                                                                                                            reformats images from webp to png in a directory.

                                                                                                                                                                                                                                                                              magick mogrify -monitor -format jpg *.png -compress 70
                                                                                                                                                                                                                                                                            
                                                                                                                                                                                                                                                                            reformats and compresses pngs to be jpg in a directory
                                                                                                                                                                                                                                                                            • frankjr · 3 years ago

                                                                                                                                                                                                                                                                              You can use ImageMagick's `convert`.

                                                                                                                                                                                                                                                                                convert original.jpg -define jpeg:extent=2MB output.jpg
                                                                                                                                                                                                                                                                              
                                                                                                                                                                                                                                                                              The result will be around 2MB in size (in both directions).
                                                                                                                                                                                                                                                                            • hgurmen · 3 years ago

                                                                                                                                                                                                                                                                              It was nice to find out that macOS has a tool similar to Valgrind called `leaks` that helps you find memory leaks!

                                                                                                                                                                                                                                                                              • elpakal · 3 years ago

                                                                                                                                                                                                                                                                                `xed .` Is probably my most underrated macOS command. It will open Xcode using either your project or workspace file.

                                                                                                                                                                                                                                                                                  • janandonly · 3 years ago

                                                                                                                                                                                                                                                                                    Does this tool also allow me to change my iPad screen on Sidecar from landscape/horizontal into vertical?

                                                                                                                                                                                                                                                                                  • greenshackle2 · 3 years ago

                                                                                                                                                                                                                                                                                    I was hoping this would let me set 125% scaling on my 3440x1440 display but no, I guess it's a hard OS limitation. It's my biggest gripe with MacOS.

                                                                                                                                                                                                                                                                                    (There's BetterDisplay - formerly BetterDummy - but it introduces noticeable input lag for me.)

                                                                                                                                                                                                                                                                                    • joshstrange · 3 years ago

                                                                                                                                                                                                                                                                                      This tool is invaluable, I love it so much. I have 2 workspaces and I love just running the command (via Alfred) when I plug into my dock at either place that fixes all my monitors. I could script it so that as soon as my computer recognizes a monitor UUID it fires off the correct displayplacer command but I don't switch often enough to care (the 2 desks are 3.5+ hours apart).

                                                                                                                                                                                                                                                                                      When I was commuting daily displayplacer was even more indispensable but even for just unplugging my mac and using the internal screen vs my monitors I get a ton of value out of this tool.

                                                                                                                                                                                                                                                                                    • shortrounddev2 · 3 years ago

                                                                                                                                                                                                                                                                                      While you're at it, `brew install coreutils`. The coreutils that ship with macOS lack a lot of features available on Linux. If you use bash, I recommend upgrading it, too, since Apple ships a 16 year old build (iirc due to legal issues associated with GPLv3) `brew install bash`

                                                                                                                                                                                                                                                                                      • Finnucane · 3 years ago

                                                                                                                                                                                                                                                                                        They're shipping zsh now.

                                                                                                                                                                                                                                                                                        • jonnycomputer · 3 years ago

                                                                                                                                                                                                                                                                                          I've found the transition to zsh surprisingly painless. But then, I do most of my command line scripting on linux and not my own machine. But still.

                                                                                                                                                                                                                                                                                          • latexr · 3 years ago

                                                                                                                                                                                                                                                                                            macOS has shipped Zsh for a long time. The difference is that now (since Catalina), it’s the default shell.

                                                                                                                                                                                                                                                                                            • shortrounddev2 · 3 years ago

                                                                                                                                                                                                                                                                                              That's why I said "if you use bash"

                                                                                                                                                                                                                                                                                            • lloeki · 3 years ago

                                                                                                                                                                                                                                                                                              They come from BSD (and, nitpick, are not called coreutils). These BSD tools lack features mostly only if you're used to GNU coreutils.

                                                                                                                                                                                                                                                                                              The expanse of GNU coreutils features is questionable too: some are nice, some you can do without easily and rarely to never miss, and some are downright annoying (yes I'm looking at you, ls with colors+quotes)

                                                                                                                                                                                                                                                                                              • shortrounddev2 · 3 years ago

                                                                                                                                                                                                                                                                                                Obviously everything is preference, but I prefer things like expanded regex in gnu grep to the underpowered macOS utils

                                                                                                                                                                                                                                                                                                • alwaysbeconsing · 3 years ago

                                                                                                                                                                                                                                                                                                  GNU and BSD grep both default to "basic" regular expressions and both have the `-E` switch to use "extended" expressions.

                                                                                                                                                                                                                                                                                                  • shortrounddev2 · 3 years ago

                                                                                                                                                                                                                                                                                                    Last time I used macOS (which was 6 years ago) there was no extended expressions, or the regex syntax was limited. I forget (again, haven't used an apple product in years)

                                                                                                                                                                                                                                                                                                    • alwillis · 3 years ago

                                                                                                                                                                                                                                                                                                      It's not necessary to install a suite of commands if you want updated grep.

                                                                                                                                                                                                                                                                                                      Just use Homebrew and you can install different versions of grep, including GNU's:

                                                                                                                                                                                                                                                                                                          brew install grep
                                                                                                                                                                                                                                                                                                      • shortrounddev2 · 3 years ago

                                                                                                                                                                                                                                                                                                        Sure but with this you get all the other improved core utils like sed, etc. GNU utils just blow BSD/macOS out of the water. Personally, macOS seems to me like a half baked development platform in general

                                                                                                                                                                                                                                                                                          • nomilk · 3 years ago

                                                                                                                                                                                                                                                                                            Surprised pngpaste isn't mentioned (in the article nor the comments).

                                                                                                                                                                                                                                                                                            If you take a screen shot (command + shift + 4) or partial screen shot (command + shift + control + 4) you can save it directly to an image file with:

                                                                                                                                                                                                                                                                                            pngpaste filename.png

                                                                                                                                                                                                                                                                                            • pier25 · 3 years ago

                                                                                                                                                                                                                                                                                              Both commands you listed take a partial screenshot. The first one saves it to the desktop and the second one (with control) to the clipboard.

                                                                                                                                                                                                                                                                                              • nomilk · 3 years ago

                                                                                                                                                                                                                                                                                                Oops, you're right. I meant command + shift + control + 3 (full screen to clipboard) and command + shift + control + 4 (partial screen to clipboard).

                                                                                                                                                                                                                                                                                              • agos · 3 years ago

                                                                                                                                                                                                                                                                                                command shift 4 already saves a file, maybe you were thinking about command + shift + control + 3?

                                                                                                                                                                                                                                                                                                • filoleg · 3 years ago

                                                                                                                                                                                                                                                                                                  IIRC Cmd+shift+4 by default stores to a file, but it is easily changeable in settings. Mine has been set to store to clipboard since a long time ago (since i mostly ever take them to send to someone in chat or to insert into my own notes, for which clipboard is exactly what i need).

                                                                                                                                                                                                                                                                                                  To change it: open Screenshot app (either cmd+shift+5 or from the app launcher), click Options in the center bar, and set "Save to" to "clipboard". Now, all screenshots in the future will be going by default to clipboard. You can also pick many other destinations for saving, including any arbitrary directory or many other apps (e.g., mail, preview, etc.).

                                                                                                                                                                                                                                                                                                  After some googling TIL, apparently if you use Ctrl key modifier with any screenshot shortcuts (cmd+shift+3/4), it will store to clipboard regardless of your setting. Kinda nifty for those who switch between storing to file/clipboard all the time.

                                                                                                                                                                                                                                                                                                  • eppsilon · 3 years ago

                                                                                                                                                                                                                                                                                                    You can also right-click the screenshot thumbnail to save to clipboard or some other location on a one-off basis.

                                                                                                                                                                                                                                                                                                    • doctor_eval · 3 years ago

                                                                                                                                                                                                                                                                                                      You can also use shift-cmd-5 to frame the page and then cmd-c to copy the screenshot - regardless of the screenshot app settings.

                                                                                                                                                                                                                                                                                                  • latexr · 3 years ago

                                                                                                                                                                                                                                                                                                    `pngpaste` doesn’t ship with macOS. All the tools in the article do.

                                                                                                                                                                                                                                                                                                    • penjelly · 3 years ago

                                                                                                                                                                                                                                                                                                      wait caffeinate exists natively? ive been using a third party caffeine tool for the longest time..

                                                                                                                                                                                                                                                                                                      • drooopy · 3 years ago

                                                                                                                                                                                                                                                                                                        That's surprising to me as well. I had no idea that caffeinate existed as a native tool on my mac. I've been relying on "Jolt of Caffeine" for the past 3 years.

                                                                                                                                                                                                                                                                                                        • hoosieree · 3 years ago

                                                                                                                                                                                                                                                                                                          Now if only I could remember how to spell caffeinate.

                                                                                                                                                                                                                                                                                                          • plorkyeran · 3 years ago

                                                                                                                                                                                                                                                                                                            I've only ever tab-completed it from caff.

                                                                                                                                                                                                                                                                                                            • samstave · 3 years ago

                                                                                                                                                                                                                                                                                                              Just make an alias to its other, easier to spell name `Methyltheobromine`. Simple.

                                                                                                                                                                                                                                                                                                              • desro · 3 years ago

                                                                                                                                                                                                                                                                                                                I'm a 'trimethylxanthine' guy myself.

                                                                                                                                                                                                                                                                                                            • sandyarmstrong · 3 years ago

                                                                                                                                                                                                                                                                                                              Yeah, I was thrilled when I discovered this for myself a few months ago! It's so useful in long-running scripts.

                                                                                                                                                                                                                                                                                                              • jkubicek · 3 years ago

                                                                                                                                                                                                                                                                                                                For a long time I used an app for this as well, but the app was just a thin wrapper around the CLI tool

                                                                                                                                                                                                                                                                                                                • penjelly · 3 years ago

                                                                                                                                                                                                                                                                                                                  after seeing the post i realized this is probably the case for most of us

                                                                                                                                                                                                                                                                                                                • roycebranning · 3 years ago

                                                                                                                                                                                                                                                                                                                  i'm most surprised that they got this one by HN community

                                                                                                                                                                                                                                                                                                                • louzell · 3 years ago

                                                                                                                                                                                                                                                                                                                  opensnoop is also a good one that usually stays under the radar

                                                                                                                                                                                                                                                                                                                  • Xen9 · 3 years ago

                                                                                                                                                                                                                                                                                                                    It's rare to see a "you might not know about" instead of "you never thought about" etc.

                                                                                                                                                                                                                                                                                                                    • 29athrowaway · 3 years ago

                                                                                                                                                                                                                                                                                                                      pandoc is the definitive document converter.

                                                                                                                                                                                                                                                                                                                      • lasermike026 · 3 years ago

                                                                                                                                                                                                                                                                                                                        Wow! So cool! Thanks!

                                                                                                                                                                                                                                                                                                                          • bpye · 3 years ago

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

                                                                                                                                                                                                                                                                                                                            • perfect-blue · 3 years ago

                                                                                                                                                                                                                                                                                                                              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.

                                                                                                                                                                                                                                                                                                                              • philbarr · 3 years ago

                                                                                                                                                                                                                                                                                                                                caffeinate is on Mac.

                                                                                                                                                                                                                                                                                                                                  caffeinate -d -i -u -s
                                                                                                                                                                                                                                                                                                                                • perfect-blue · 3 years ago

                                                                                                                                                                                                                                                                                                                                  Thanks very much for this.

                                                                                                                                                                                                                                                                                                                                • lattalayta · 3 years ago

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

                                                                                                                                                                                                                                                                                                                                  https://keepingyouawake.app/

                                                                                                                                                                                                                                                                                                                                  • Alifatisk · 3 years ago

                                                                                                                                                                                                                                                                                                                                    I believe you can still get it, if not, there are similar like Amphetamine

                                                                                                                                                                                                                                                                                                                                    • jimt1234 · 3 years ago

                                                                                                                                                                                                                                                                                                                                      Amphetamine has been my go-to app for keeping my Mac alive, especially since Apple tried to remove it from the App Store because, according to [someone?], the name violated App Store rules.

                                                                                                                                                                                                                                                                                                                                      https://apps.apple.com/us/app/amphetamine/id937984704

                                                                                                                                                                                                                                                                                                                                      • bigtunacan · 3 years ago

                                                                                                                                                                                                                                                                                                                                        I switched to Amphetamine a few years back because caffeinate doesn't work consistently.

                                                                                                                                                                                                                                                                                                                                      • varispeed · 3 years ago

                                                                                                                                                                                                                                                                                                                                        Interesting so many useful commands, but they didn't have time to fix basics like scroll wheel, so you have to install 3rd party apps to set it independently from the touch pad and then it still manages to swap it around at random times.

                                                                                                                                                                                                                                                                                                                                        Am I the only one who finds macOS so annoying?

                                                                                                                                                                                                                                                                                                                                        I mean the apps for scroll wheel, alt-tab and what not...

                                                                                                                                                                                                                                                                                                                                        • KyleBerezin · 3 years ago

                                                                                                                                                                                                                                                                                                                                          The issues I have are touch-dragging with the touchpad, and no window docking. Docking I fixed by buying 'Magnet', touch dragging is still annoying. They have a setting that is supposed to enable 'double tap drag' like windows, but when you let go, it keeps dragging for some random amount of time, making it unusable.

                                                                                                                                                                                                                                                                                                                                          • sbuk · 3 years ago

                                                                                                                                                                                                                                                                                                                                            Settings > Accessibility > Pointer Control > Trackpad Options...

                                                                                                                                                                                                                                                                                                                                            Three-Finger Drag works really well and is surprisingly easy to get used to doing.

                                                                                                                                                                                                                                                                                                                                        • Hamuko · 3 years ago

                                                                                                                                                                                                                                                                                                                                          You can use `say` to recreate your own Serial Experiments Lain intros.

                                                                                                                                                                                                                                                                                                                                            say -v Whisper "Weird: Layer zero one"
                                                                                                                                                                                                                                                                                                                                          • blacksmith_tb · 3 years ago

                                                                                                                                                                                                                                                                                                                                            You may have to install extra voices somehow, looking at the manpage for say, it seems like 'say -v ?' would list the voices installed, but I don't seem to have any (like Whisper), though plain old 'say "hello world"' does do a robotic voice which must be the default.

                                                                                                                                                                                                                                                                                                                                            • Hamuko · 3 years ago

                                                                                                                                                                                                                                                                                                                                              You can install additional voices in System Settings → Accessibility → Spoken Content → System voice → Manage voices (in Ventura).

                                                                                                                                                                                                                                                                                                                                              "Whisper" is listed under "English (US) - Novelty".

                                                                                                                                                                                                                                                                                                                                              • blacksmith_tb · 3 years ago

                                                                                                                                                                                                                                                                                                                                                Thanks, I found those with some digging, I see that even just adding Whisper it's a 3.8GB dl, mostly to upgrade the default voice apparently - I guess that's why it isn't all included by default I guess!

                                                                                                                                                                                                                                                                                                                                              • frankjr · 3 years ago

                                                                                                                                                                                                                                                                                                                                                Not sure if you can install additional voices using the command line, but the way you do it in the UI is Preferences -> Accessibility -> Spoken Content, then select customize in the voice selector and finally select the voice you want to add.

                                                                                                                                                                                                                                                                                                                                            • riobard · 3 years ago

                                                                                                                                                                                                                                                                                                                                              For audio there're also `afinfo` to probe metadata and `afconvert` to convert between different codec/container formats. I use them for podcast post-processing and archiving workflow.

                                                                                                                                                                                                                                                                                                                                              macOS 13 Ventura ships with a customized `iperf3` called `iperf3-darwin` adding features like QUIC/L4S/MPTCP.

                                                                                                                                                                                                                                                                                                                                              • Alifatisk · 3 years ago

                                                                                                                                                                                                                                                                                                                                                QUIC already? Cool

                                                                                                                                                                                                                                                                                                                                              • rogual · 3 years ago

                                                                                                                                                                                                                                                                                                                                                A fun one I use surprisingly often is

                                                                                                                                                                                                                                                                                                                                                    open -h AppKit.h
                                                                                                                                                                                                                                                                                                                                                
                                                                                                                                                                                                                                                                                                                                                to open any system header file (or I guess any header in the standard include path? It finds stuff from Homebrew too.)
                                                                                                                                                                                                                                                                                                                                                • daneel_w · 3 years ago

                                                                                                                                                                                                                                                                                                                                                  afconvert(1) lets you convert between various audio formats - most noteworthy is that it gives you access to Core Audio's superior AAC encoder without having to use iTunes/Music:

                                                                                                                                                                                                                                                                                                                                                    afconvert music.wav -o music_160kbps_aac.m4a -b 160000 -q 127 -s 2 -f m4af -d 'aac '
                                                                                                                                                                                                                                                                                                                                                  
                                                                                                                                                                                                                                                                                                                                                  lipo(1) lets you operate (replace/extract/thin/etc) on executables and libraries to tailor their supported architectures:

                                                                                                                                                                                                                                                                                                                                                    lipo <universal exe/dylib> -thin arm64e -output <new apple silicon-only exe/dylib>
                                                                                                                                                                                                                                                                                                                                                  • daneel_w · 3 years ago

                                                                                                                                                                                                                                                                                                                                                    Also, using hdiutil(1) and diskutil(8) to create a RAM-disk:

                                                                                                                                                                                                                                                                                                                                                      # 500 megabytes disk image
                                                                                                                                                                                                                                                                                                                                                      mb=$((500*2048))
                                                                                                                                                                                                                                                                                                                                                      diskutil eraseVolume ExFAT my_ramdisk `hdiutil attach -nomount ram://$mb`
                                                                                                                                                                                                                                                                                                                                                  • efitz · 3 years ago

                                                                                                                                                                                                                                                                                                                                                    Someone should turn this HN discussion into a gist.

                                                                                                                                                                                                                                                                                                                                                  • renewiltord · 3 years ago

                                                                                                                                                                                                                                                                                                                                                    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!" ```

                                                                                                                                                                                                                                                                                                                                                    • Svetlitski · 3 years ago

                                                                                                                                                                                                                                                                                                                                                      I can’t help but ask, why “,notify” and not just “notify”?

                                                                                                                                                                                                                                                                                                                                                      • renewiltord · 3 years ago

                                                                                                                                                                                                                                                                                                                                                        I name all my personal programs prefixed by the comma. I learnt it from someone on lobste.rs. No Unix utilities use the prefix in their name and it is a valid filename.

                                                                                                                                                                                                                                                                                                                                                        So I can type , and I am sure it's my program and I'm not running something else and it'll autocomplete among my list of programs.

                                                                                                                                                                                                                                                                                                                                                        • wpm · 3 years ago

                                                                                                                                                                                                                                                                                                                                                          This is a very cool idea, I always hesitate to add a lot of aliases to my zshrc since I never want to step on any toes.

                                                                                                                                                                                                                                                                                                                                                      • inanutshellus · 3 years ago

                                                                                                                                                                                                                                                                                                                                                        an upvote wasn't enough! this is cool, thanks for sharing.

                                                                                                                                                                                                                                                                                                                                                        • codetrotter · 3 years ago

                                                                                                                                                                                                                                                                                                                                                          Shoutout to the `diskutil` command line utility on macOS.

                                                                                                                                                                                                                                                                                                                                                          I had problems with some slices on a disk today, and was not able to fix it with the graphical Disk Utility that comes with macOS. These slices were remnants from experimenting with running Asahi Linux on the machine in the past.

                                                                                                                                                                                                                                                                                                                                                          I knew there had to be a way to fix it with diskutility cli program.

                                                                                                                                                                                                                                                                                                                                                          I found a thread, and the solution for what to do in such situation.

                                                                                                                                                                                                                                                                                                                                                          https://apple.stackexchange.com/questions/411544/cant-reclai...

                                                                                                                                                                                                                                                                                                                                                          Now the disk can be fully utilised by macOS again.

                                                                                                                                                                                                                                                                                                                                                          • wpm · 3 years ago

                                                                                                                                                                                                                                                                                                                                                            `diskutil` is great but it's a travesty what they did to Disk Utility.app. It never really got any love after the APFS transition and there are things it straight up fails to do the `diskutil` command doesn't. Before they re-designed the interface, it was such a rock-solid tool that even if it failed during some task, would typically tell you why. Now it's a baby LEGO Duplo interface meant for nothing more than reformatting a flash drive.

                                                                                                                                                                                                                                                                                                                                                            • IggleSniggle · 3 years ago

                                                                                                                                                                                                                                                                                                                                                              I still open it sometimes thinking it's going to be a great experience, forgetting about this.

                                                                                                                                                                                                                                                                                                                                                          • sovietswag · 3 years ago

                                                                                                                                                                                                                                                                                                                                                            Needs to mention afplay for playing audio! You can easily use this to make a command-line MP3 player.

                                                                                                                                                                                                                                                                                                                                                            Others have mentioned the “say” utility for speech synthesis. There is a lot you can do with it, it supports the TUNE format, which allows you to "shape the overall melody and timing of an utterance... for example ... to make an utterance sound as if it is spoken with emotion".

                                                                                                                                                                                                                                                                                                                                                            See: Apple's Speech Synthesis Programming Guide, https://josh8.com/blog/img/speech-synthesis.pdf

                                                                                                                                                                                                                                                                                                                                                            I also wrote more about this here: https://josh8.com/blog/commandline-audio-mac.html

                                                                                                                                                                                                                                                                                                                                                            • microtherion · 3 years ago

                                                                                                                                                                                                                                                                                                                                                              Unfortunately, the TUNE format turned out to be a bit of an evolutionary dead end; the last generation of Speech Synthesis that supports it is the Alex voice which shipped in 2007, and it's highly unlikely in my opinion that we'll ever see it again — pinpoint control of synthesis and naturalness are inherently in tension, and the latter is a lot more valuable.

                                                                                                                                                                                                                                                                                                                                                              • IggleSniggle · 3 years ago

                                                                                                                                                                                                                                                                                                                                                                It is unfortunate. But Alex does sound pretty good! Not up to 2023 standards maybe but still pretty good.

                                                                                                                                                                                                                                                                                                                                                              • manifoldgeo · 3 years ago

                                                                                                                                                                                                                                                                                                                                                                Thanks for posting! I'm always glad when I discover good blogs like yours.

                                                                                                                                                                                                                                                                                                                                                                • kaycey2022 · 3 years ago

                                                                                                                                                                                                                                                                                                                                                                  Thank you for the article :) One small correction, the command to list the voices is `say -v '?'`

                                                                                                                                                                                                                                                                                                                                                                • MobiusHorizons · 3 years ago

                                                                                                                                                                                                                                                                                                                                                                  I didn’t know about textutil before, I’ll have to try that. Does that use the same backend as pages for word documents? How good is the conversion?

                                                                                                                                                                                                                                                                                                                                                                  • tngranados · 3 years ago

                                                                                                                                                                                                                                                                                                                                                                    I didn't know about `taskpolicy`, I'll add it to my list. It will be handy now that it's getting hot around here for long running commands that I don't mind waiting for, Apple Silicon Macs run cooler than Intel's but they can still get very hot when maxed out.

                                                                                                                                                                                                                                                                                                                                                                    • knodi123 · 3 years ago

                                                                                                                                                                                                                                                                                                                                                                      > open - open files and applications

                                                                                                                                                                                                                                                                                                                                                                      And urls! I use that one in a lot of my scripts. We have a ticket-based workflow, and I can parse out the ticket number from the current git branch, and open the ticket or create a merge requests without having to do anything complicated.

                                                                                                                                                                                                                                                                                                                                                                        • strogonoff · 3 years ago

                                                                                                                                                                                                                                                                                                                                                                          You can use sips together with iconutil to generate a complete .icns file for your app from a single 1024 by 1024 PNG without any third party software:

                                                                                                                                                                                                                                                                                                                                                                              mkdir MyIcon.iconset
                                                                                                                                                                                                                                                                                                                                                                              cp Icon1024.png MyIcon.iconset/icon_512x512@2x.png
                                                                                                                                                                                                                                                                                                                                                                              sips -z 16 16     Icon1024.png --out MyIcon.iconset/icon_16x16.png
                                                                                                                                                                                                                                                                                                                                                                              sips -z 32 32     Icon1024.png --out MyIcon.iconset/icon_16x16@2x.png
                                                                                                                                                                                                                                                                                                                                                                              sips -z 32 32     Icon1024.png --out MyIcon.iconset/icon_32x32.png
                                                                                                                                                                                                                                                                                                                                                                              sips -z 64 64     Icon1024.png --out MyIcon.iconset/icon_32x32@2x.png
                                                                                                                                                                                                                                                                                                                                                                              sips -z 128 128   Icon1024.png --out MyIcon.iconset/icon_128x128.png
                                                                                                                                                                                                                                                                                                                                                                              sips -z 256 256   Icon1024.png --out MyIcon.iconset/icon_128x128@2x.png
                                                                                                                                                                                                                                                                                                                                                                              sips -z 256 256   Icon1024.png --out MyIcon.iconset/icon_256x256.png
                                                                                                                                                                                                                                                                                                                                                                              sips -z 512 512   Icon1024.png --out MyIcon.iconset/icon_256x256@2x.png
                                                                                                                                                                                                                                                                                                                                                                              sips -z 512 512   Icon1024.png --out MyIcon.iconset/icon_512x512.png
                                                                                                                                                                                                                                                                                                                                                                              iconutil -c icns MyIcon.iconset
                                                                                                                                                                                                                                                                                                                                                                          
                                                                                                                                                                                                                                                                                                                                                                          As a bonus, generate .ico with ffmpeg:

                                                                                                                                                                                                                                                                                                                                                                              ffmpeg -i MyIcon.iconset/icon_256x256.png icon.ico
                                                                                                                                                                                                                                                                                                                                                                          
                                                                                                                                                                                                                                                                                                                                                                          Incidentally, does anyone know enough about the way sips scales PNGs to confirm that it makes sense to create the 16px version straight from 1024px, as opposed to basing it off 32px (and all the way up)? I.e., is it better to downscale in fewer steps (as currently) or in smaller steps?
                                                                                                                                                                                                                                                                                                                                                                          • photonerd · 3 years ago

                                                                                                                                                                                                                                                                                                                                                                            additional bonus, you can input an SVG at the start if you use qlmanage first instead of the cp command:

                                                                                                                                                                                                                                                                                                                                                                            qlmanage -t -s 1024x1024 -o MyIcon.iconset/Icon1024.png icon.svg

                                                                                                                                                                                                                                                                                                                                                                            • strogonoff · 3 years ago

                                                                                                                                                                                                                                                                                                                                                                              Note of caution: if qlmanage uses QuickLook SVG rendering, YMMV. I recently had to deal with SVGs that render broken in Finder but correctly in, say, Affinity or Adobe tools.

                                                                                                                                                                                                                                                                                                                                                                              Rasterization feels sufficiently finicky that I personally would consider it part of designer’s workflow rather than automated conversion pipeline; but then some would say the same about raster versions at different sizes, so in the end it depends on what you can and want spend resources at.

                                                                                                                                                                                                                                                                                                                                                                              If it does work for you, though, you could generate every size from SVG directly and skip sips altogether (but you should check both methods to see which gives you a better quality icon, at small sizes single pixels can matter and so it would depend on how qlmanage handles rasterization to different sizes).

                                                                                                                                                                                                                                                                                                                                                                              • photonerd · 3 years ago

                                                                                                                                                                                                                                                                                                                                                                                That’s fair. I will say, I’ve found that svgs that only rendered “right” in Adobe/Affinity to be broken most other places too.

                                                                                                                                                                                                                                                                                                                                                                                May be a version thing, may be some extended stuff that more common parsers do not support, not sure.

                                                                                                                                                                                                                                                                                                                                                                            • nielsbot · 3 years ago

                                                                                                                                                                                                                                                                                                                                                                              If you really want nice looking smaller icons (16x16, 32x32) you'll have to hand edit them after scaling down to get something that looks crisp.

                                                                                                                                                                                                                                                                                                                                                                              That said I just checked some macOS system icons (get info on app, select icon, copy, create new document in Preview.app) and they don't seem to be hand adjusted any more.

                                                                                                                                                                                                                                                                                                                                                                              • strogonoff · 3 years ago

                                                                                                                                                                                                                                                                                                                                                                                I’d say hand-crafting pixel-perfect icons with different versions for extreme sizes is worthwhile (and I don’t believe in simple rasterization from vector for the same reason), but not every developer would have resources to spare for that.

                                                                                                                                                                                                                                                                                                                                                                                • vintagedave · 3 years ago

                                                                                                                                                                                                                                                                                                                                                                                  I was lucky enough to oversee a project replacing seven hundred icons back in 2017, and we hand-adjusted the low resolution versions of 16x16 and 24x24.

                                                                                                                                                                                                                                                                                                                                                                                  > “…notice that the icons are not simply the same image scaled up or down. TTrackBar is a good example of this: at each size, the small indicator marks are different. An icon designed for 16×16 or 32×32 won’t resize and scale to look good at 24×24, because the pixel grid is different. Even if we support antialiasing, a 1-pixel-wide line looks much cleaner when it takes up one pixel in the image, rather than being approximated through antialiasing over several pixels, which makes it look blurry. Similarly, shape edges should be snapped to the pixel grid for each size. We’ve gone through and tweaked the icons for each different pixel grid.”

                                                                                                                                                                                                                                                                                                                                                                                  This meant that not only did we tweak the icons at the small sizes (in the example above for a track bar control, we don’t use the large size 128x one scaled down to 16x even though they are both built on a 16x grid) but that we used a different base grid for the 24x and 48x versions compared to all other sizes.

                                                                                                                                                                                                                                                                                                                                                                                  It took time. And not everyone has those resources. But if you can, it is the right thing to do.

                                                                                                                                                                                                                                                                                                                                                                                  https://blogs.embarcadero.com/new-in-10-2-2-component-icons/

                                                                                                                                                                                                                                                                                                                                                                                  • strogonoff · 3 years ago

                                                                                                                                                                                                                                                                                                                                                                                    Thanks for the insight. My script targets a solo dev such as myself, but crafting icons is always superior.

                                                                                                                                                                                                                                                                                                                                                                                    As a designer, the way I recommend to do it is not by tweaking icons but by having a specific process separating design from deliverables. Define branding language, come up with your symbols and marks and mascots and their use guidelines, and then prepare deliverables based on that. Icons intended to be used at extremely different sizes (16px vs. 512px) and in different contexts are different deliverables.

                                                                                                                                                                                                                                                                                                                                                                              • gpspake · 3 years ago

                                                                                                                                                                                                                                                                                                                                                                                Perfect timing. I need to generate an.icns today and I'm going to try this. Thanks :)

                                                                                                                                                                                                                                                                                                                                                                              • tommica · 3 years ago

                                                                                                                                                                                                                                                                                                                                                                                Oh, the `say` command is really damn useful to know about!

                                                                                                                                                                                                                                                                                                                                                                                • simscitizen · 3 years ago

                                                                                                                                                                                                                                                                                                                                                                                  dtrace and the DTrace Toolkit scripts are also quite useful for understanding and debugging things, e.g. `opensnoop -a` to print the result of all open syscalls on the system.

                                                                                                                                                                                                                                                                                                                                                                                  • lastangryman · 3 years ago

                                                                                                                                                                                                                                                                                                                                                                                    I find it extremely upsetting that `networkQuality` is the only command that is not entirely lowercase. How did this get through PR??

                                                                                                                                                                                                                                                                                                                                                                                    • 1f60c · 3 years ago

                                                                                                                                                                                                                                                                                                                                                                                      APFS isn't case-sensitive, so you can type networkquality if it makes you happy. :-)

                                                                                                                                                                                                                                                                                                                                                                                      • andelink · 3 years ago

                                                                                                                                                                                                                                                                                                                                                                                        Wow, truly a pro tip, thank you!

                                                                                                                                                                                                                                                                                                                                                                                        • saagarjha · 3 years ago

                                                                                                                                                                                                                                                                                                                                                                                          It can be, it’s just not by default.

                                                                                                                                                                                                                                                                                                                                                                                      • RandallBrown · 3 years ago

                                                                                                                                                                                                                                                                                                                                                                                        The say command has one of my favorite pieces of that famous Apple polish.

                                                                                                                                                                                                                                                                                                                                                                                        If you type `say os x`, it'll actually speak "oh es ten".

                                                                                                                                                                                                                                                                                                                                                                                        • unsupp0rted · 3 years ago

                                                                                                                                                                                                                                                                                                                                                                                          It says "oh es ex" for all variations I've tried

                                                                                                                                                                                                                                                                                                                                                                                          • _diyar · 3 years ago

                                                                                                                                                                                                                                                                                                                                                                                            Capitalizing the phrase made it work for me

                                                                                                                                                                                                                                                                                                                                                                                            > say OS X

                                                                                                                                                                                                                                                                                                                                                                                            Edit: Late 2016 MBP on 12.6.6 Monterey

                                                                                                                                                                                                                                                                                                                                                                                            • rootusrootus · 3 years ago

                                                                                                                                                                                                                                                                                                                                                                                              Interesting. Says 'OS 10" on my Ventura 13.4 macbook.

                                                                                                                                                                                                                                                                                                                                                                                          • fredoralive · 3 years ago

                                                                                                                                                                                                                                                                                                                                                                                            I'll go for the somewhat obsolete `drutil eject` as Mac OS can be sometimes rather reluctant to eject cycle optical drives if it doesn't actually think a disc in in them. Although nowadays you'll probably be using a 3rd party tray load drive with an eject button instead of a no-button slot loading Apple one.

                                                                                                                                                                                                                                                                                                                                                                                            • reaperducer · 3 years ago

                                                                                                                                                                                                                                                                                                                                                                                              My LG Blu-Ray drive ignores its eject button if it's connected to a Mac, unless the drive is empty, so I use this, too.

                                                                                                                                                                                                                                                                                                                                                                                            • js2 · 3 years ago

                                                                                                                                                                                                                                                                                                                                                                                              Some that were missed:

                                                                                                                                                                                                                                                                                                                                                                                              diskutil: modify, verify and repair local disk

                                                                                                                                                                                                                                                                                                                                                                                              hdiutil: manipulate disk images (attach, verify, create, etc)

                                                                                                                                                                                                                                                                                                                                                                                              dscl: Directory Service command line utility (manage users and groups)

                                                                                                                                                                                                                                                                                                                                                                                              scutil: Manage system configuration parameters (useful for checking current DNS configuration and checking reachability to a host).

                                                                                                                                                                                                                                                                                                                                                                                              sysadminctl: It's a secret! No man page. Run without options to get a usage message, but even the usage is apparently incomplete. It's a grab-bag of functionality. I use for adding/removing a temporary build user as part of a CI/CD setup.

                                                                                                                                                                                                                                                                                                                                                                                              • verst · 3 years ago

                                                                                                                                                                                                                                                                                                                                                                                                I like to hide all icons or folders on my Desktop when I need to be more productive or when I'm presenting. This can be done with:

                                                                                                                                                                                                                                                                                                                                                                                                  # hide desktop icons and folders
                                                                                                                                                                                                                                                                                                                                                                                                  defaults write com.apple.finder CreateDesktop 0
                                                                                                                                                                                                                                                                                                                                                                                                  killall Finder # restarting Finder is required
                                                                                                                                                                                                                                                                                                                                                                                                
                                                                                                                                                                                                                                                                                                                                                                                                  # unhide desktop icons and folders
                                                                                                                                                                                                                                                                                                                                                                                                  defaults write com.apple.finder CreateDesktop 1
                                                                                                                                                                                                                                                                                                                                                                                                  killall Finder # restarting Finder is required
                                                                                                                                                                                                                                                                                                                                                                                                
                                                                                                                                                                                                                                                                                                                                                                                                
                                                                                                                                                                                                                                                                                                                                                                                                
                                                                                                                                                                                                                                                                                                                                                                                                I made myself a convenient bash alias for this which lets me simply toggle the desktop on and off Here is a gist: https://gist.github.com/berndverst/6f58c0d6aedddb6c06c23e57d...

                                                                                                                                                                                                                                                                                                                                                                                                  toggledesktop () {
                                                                                                                                                                                                                                                                                                                                                                                                    if [[ $(defaults read com.apple.finder CreateDesktop) -eq "0" ]]
                                                                                                                                                                                                                                                                                                                                                                                                    then
                                                                                                                                                                                                                                                                                                                                                                                                        export SHOWDESKTOP=1;
                                                                                                                                                                                                                                                                                                                                                                                                        echo "Unhiding Desktop icons"
                                                                                                                                                                                                                                                                                                                                                                                                    else
                                                                                                                                                                                                                                                                                                                                                                                                        export SHOWDESKTOP=0;
                                                                                                                                                                                                                                                                                                                                                                                                        echo "Hiding Desktop icons"
                                                                                                                                                                                                                                                                                                                                                                                                    fi
                                                                                                                                                                                                                                                                                                                                                                                                    defaults write com.apple.finder CreateDesktop $SHOWDESKTOP
                                                                                                                                                                                                                                                                                                                                                                                                    killall Finder
                                                                                                                                                                                                                                                                                                                                                                                                  }
                                                                                                                                                                                                                                                                                                                                                                                                • IggleSniggle · 3 years ago

                                                                                                                                                                                                                                                                                                                                                                                                  I've used this one for over a decade now. When I was a teacher, I even assigned it to a key-combo. Consider pairing with a few other things you might want in a presentation setting

                                                                                                                                                                                                                                                                                                                                                                                                  • verst · 3 years ago

                                                                                                                                                                                                                                                                                                                                                                                                    What do you use for assigning it to a key combination? Can it be done without a third party tool?

                                                                                                                                                                                                                                                                                                                                                                                                    • niels_bom · 3 years ago

                                                                                                                                                                                                                                                                                                                                                                                                      Automator should be able to do that.

                                                                                                                                                                                                                                                                                                                                                                                                  • desro · 3 years ago

                                                                                                                                                                                                                                                                                                                                                                                                    Turning off the desktop is one of the first things I do when setting up a new Mac. I still use ~/Desktop often enough that it's one of two folders I keep in the Dock (the other being ~/Downloads).

                                                                                                                                                                                                                                                                                                                                                                                                    Although: the introduction of Stacks to the macOS desktop was a great thing — I always show that feature to anyone whose Desktop is helplessly cluttered with files.

                                                                                                                                                                                                                                                                                                                                                                                                  • balls187 · 3 years ago

                                                                                                                                                                                                                                                                                                                                                                                                    “say” with my laptop connected to my home bluetooth speakers is a lot of fun with my kids.

                                                                                                                                                                                                                                                                                                                                                                                                    • verst · 3 years ago

                                                                                                                                                                                                                                                                                                                                                                                                      A lot of macOS behavior can be toggled by modifying the system component defaults.

                                                                                                                                                                                                                                                                                                                                                                                                      For example, turn off autohiding of the Dock from commandline:

                                                                                                                                                                                                                                                                                                                                                                                                        defaults write com.apple.dock "autohide" -bool "false" && killall Dock
                                                                                                                                                                                                                                                                                                                                                                                                      
                                                                                                                                                                                                                                                                                                                                                                                                      Include the date in screenshots you take:

                                                                                                                                                                                                                                                                                                                                                                                                        defaults write com.apple.screencapture "include-date" -bool "true"
                                                                                                                                                                                                                                                                                                                                                                                                      
                                                                                                                                                                                                                                                                                                                                                                                                      Here is handy website which documents many of the defaults and their purpose: https://macos-defaults.com/#%F0%9F%99%8B-what-s-a-defaults-c...
                                                                                                                                                                                                                                                                                                                                                                                                      • llimllib · 3 years ago

                                                                                                                                                                                                                                                                                                                                                                                                        https://github.com/zcutlip/prefsniff can be handy for figuring this stuff out, you start it up, change a setting, and it reports the plist differences to you

                                                                                                                                                                                                                                                                                                                                                                                                        • andelink · 3 years ago

                                                                                                                                                                                                                                                                                                                                                                                                          Pretty cool tool it looks like. Gonna try using this. Also has good resources in the README.

                                                                                                                                                                                                                                                                                                                                                                                                      • joshSzep · 3 years ago

                                                                                                                                                                                                                                                                                                                                                                                                        `caffeinate` is a game changer. Now I can keep my Slack status green without sitting in an empty zoom room. #WFHLife ;)

                                                                                                                                                                                                                                                                                                                                                                                                        • lkuty · 3 years ago

                                                                                                                                                                                                                                                                                                                                                                                                          I use `caffeinate -dsim` permanently. In short I ask the computer to avoid any kind of sleep.

                                                                                                                                                                                                                                                                                                                                                                                                            -d Create an assertion to prevent the display from sleeping.
                                                                                                                                                                                                                                                                                                                                                                                                            -i Create an assertion to prevent the system from idle sleeping.
                                                                                                                                                                                                                                                                                                                                                                                                            -m Create an assertion to prevent the disk from idle sleeping.
                                                                                                                                                                                                                                                                                                                                                                                                            -s Create an assertion to prevent the system from sleeping. This
                                                                                                                                                                                                                                                                                                                                                                                                               assertion is valid only when system is running on AC power.
                                                                                                                                                                                                                                                                                                                                                                                                            • datavirtue · 3 years ago

                                                                                                                                                                                                                                                                                                                                                                                                              Or a full screen YouTube Mozart video that lasts for six hours

                                                                                                                                                                                                                                                                                                                                                                                                          • massysett · 3 years ago

                                                                                                                                                                                                                                                                                                                                                                                                            Is there a place Apple documents these things? Do people find these things with something like “ls /usr/bin” and wondering “what is this?” or does Apple have an administrator’s guide somewhere? Or has someone written a good book with this stuff?

                                                                                                                                                                                                                                                                                                                                                                                                            • saurabhsharan · 3 years ago

                                                                                                                                                                                                                                                                                                                                                                                                              Hi, author here. There isn't any official canonical documentation that I know of, outside of the individual man pages. This was a list of commands I've been maintaining for myself over the years and thought it would be useful to share.

                                                                                                                                                                                                                                                                                                                                                                                                              If you want more like this, I also have another page full of lesser well-known macOS tips and tricks: https://saurabhs.org/macos-tips

                                                                                                                                                                                                                                                                                                                                                                                                              • tlh · 3 years ago

                                                                                                                                                                                                                                                                                                                                                                                                                Oh my, and a bucket load of iOS tips too!

                                                                                                                                                                                                                                                                                                                                                                                                                TIL you can tap and drag with 2 fingers to multi-select list items in mail and notes, etc

                                                                                                                                                                                                                                                                                                                                                                                                                Bless you for finding and collating

                                                                                                                                                                                                                                                                                                                                                                                                              • andelink · 3 years ago

                                                                                                                                                                                                                                                                                                                                                                                                                I'd love some official Apple documentation. In lieu of that, you can search man pages with `man -f`, `whatis`, or `apropos`. I also keep the following aliases in my ~/.zshrc:

                                                                                                                                                                                                                                                                                                                                                                                                                  alias list-functions='functions -x4'
                                                                                                                                                                                                                                                                                                                                                                                                                  alias list-function-names='functions +'
                                                                                                                                                                                                                                                                                                                                                                                                                  alias list-aliases='alias'
                                                                                                                                                                                                                                                                                                                                                                                                                  alias list-alias-names='alias +'
                                                                                                                                                                                                                                                                                                                                                                                                                  alias list-commands='print -raC2 ${(kv)commands} | sort'
                                                                                                                                                                                                                                                                                                                                                                                                                  alias list-command-names='print -roC1 ${(k)commands}'
                                                                                                                                                                                                                                                                                                                                                                                                                  alias list-builtins='print -raC2 ${(kv)builtins} | sort'
                                                                                                                                                                                                                                                                                                                                                                                                                  alias list-builtin-names='print -roC1 ${(k)builtins}'
                                                                                                                                                                                                                                                                                                                                                                                                                  alias list-everything='whence -cm "[^_]*"'
                                                                                                                                                                                                                                                                                                                                                                                                                  alias list-everything-names='whence -wm "[^_]*"'
                                                                                                                                                                                                                                                                                                                                                                                                                
                                                                                                                                                                                                                                                                                                                                                                                                                Edit: another commenter posted what looks to be comprehensive docs/lists here: https://news.ycombinator.com/item?id=36492487
                                                                                                                                                                                                                                                                                                                                                                                                              • kevwil · 3 years ago

                                                                                                                                                                                                                                                                                                                                                                                                                The `security` tool is handy too. I like the ability to store passwords in the `login` Keychain and automate using them in the terminal using `security find-generic-password`.

                                                                                                                                                                                                                                                                                                                                                                                                                    security find-generic-password -gw -l "${keychain_id}"
                                                                                                                                                                                                                                                                                                                                                                                                                
                                                                                                                                                                                                                                                                                                                                                                                                                Super helpful for VPN automation scripts, easy logins to things like Vault, etc. The security tool has tons of other handy functions as well.
                                                                                                                                                                                                                                                                                                                                                                                                                • asveikau · 3 years ago

                                                                                                                                                                                                                                                                                                                                                                                                                  Not on the list, but I think `fs_usage` is an interesting one. Like a firehose of disk activity.

                                                                                                                                                                                                                                                                                                                                                                                                                  • thadk · 3 years ago

                                                                                                                                                                                                                                                                                                                                                                                                                    Having ChatGPT or equivalent create a basic Makefile for these commands (and other commands) is a quick way to preserve your process for later. You can show it your file structure first too.

                                                                                                                                                                                                                                                                                                                                                                                                                    • apocalyptic0n3 · 3 years ago

                                                                                                                                                                                                                                                                                                                                                                                                                      `open` is one I use all the time. I love that simple command.

                                                                                                                                                                                                                                                                                                                                                                                                                          alias tab='open . -a iterm'
                                                                                                                                                                                                                                                                                                                                                                                                                          alias phpstorm='open -a "PhpStorm"'
                                                                                                                                                                                                                                                                                                                                                                                                                          alias smerge='open -a "Sublime Merge"'
                                                                                                                                                                                                                                                                                                                                                                                                                      
                                                                                                                                                                                                                                                                                                                                                                                                                      etc. I use those more than I do the Open/Recents dialogs in the respective apps.
                                                                                                                                                                                                                                                                                                                                                                                                                      • baliex · 3 years ago

                                                                                                                                                                                                                                                                                                                                                                                                                        To open a new finder window in the current directory in a terminal:

                                                                                                                                                                                                                                                                                                                                                                                                                            alias finder='open .'
                                                                                                                                                                                                                                                                                                                                                                                                                        • Kyuuketsuki · 3 years ago

                                                                                                                                                                                                                                                                                                                                                                                                                          One flag also not mentioned is -n, which allows you to run the same application in more than one instance. Historically the single most used utility for me, though the number of applications that have had design problems bad enough to warrant it has gone down.

                                                                                                                                                                                                                                                                                                                                                                                                                            • movedx · 3 years ago

                                                                                                                                                                                                                                                                                                                                                                                                                              > alias tab='open . -a iterm'

                                                                                                                                                                                                                                                                                                                                                                                                                              But if you just open a new tab, you'll be in the same $CWD in the new tab? Am I missing some trick here?

                                                                                                                                                                                                                                                                                                                                                                                                                              • andelink · 3 years ago

                                                                                                                                                                                                                                                                                                                                                                                                                                In your iterm profile settings, you can configure new tabs to go to either $HOME, $CWD, or a fixed specific directory. I've configured new windows and tabs to $HOME, but new split panes $CWD.

                                                                                                                                                                                                                                                                                                                                                                                                                                • apocalyptic0n3 · 3 years ago

                                                                                                                                                                                                                                                                                                                                                                                                                                  I forget that's an option. I really dislike that and prefer for new tabs to open in my home directory. So having my `tab` alias that I use a couple times a week and opening the other 100 tabs in my home directory fits my workflow.

                                                                                                                                                                                                                                                                                                                                                                                                                                • jonpalmisc · 3 years ago

                                                                                                                                                                                                                                                                                                                                                                                                                                  Sublime Text and Sublime Merge actually ship with these CLI utilities by default, which have some additional features:

                                                                                                                                                                                                                                                                                                                                                                                                                                      $ fd 's(merge|ubl)$' /Applications/Sublime*                                          
                                                                                                                                                                                                                                                                                                                                                                                                                                      /Applications/Sublime Merge.app/Contents/SharedSupport/bin/smerge
                                                                                                                                                                                                                                                                                                                                                                                                                                      /Applications/Sublime Text.app/Contents/SharedSupport/bin/subl
                                                                                                                                                                                                                                                                                                                                                                                                                                  • apocalyptic0n3 · 3 years ago

                                                                                                                                                                                                                                                                                                                                                                                                                                    I knew of (and use) `subl` but was unaware they provided their own `smerge`. I'll delete my own alias in favor of that. Thanks!

                                                                                                                                                                                                                                                                                                                                                                                                                                  • varenc · 3 years ago

                                                                                                                                                                                                                                                                                                                                                                                                                                    `open -a ...` tab completion has been horribly slow for years because Apple hasn’t updated their completion definition. I replied with a work around on this SO post: https://stackoverflow.com/a/63097652

                                                                                                                                                                                                                                                                                                                                                                                                                                  • babbledabbler · 3 years ago

                                                                                                                                                                                                                                                                                                                                                                                                                                    say --rate=500 "Peter Piper picked a peck of pickled peppers. A peck of pickled peppers Peter Piper picked. If Peter Piper picked a peck of pickled peppers, Where’s the peck of pickled peppers Peter Piper picked?"

                                                                                                                                                                                                                                                                                                                                                                                                                                    • miohtama · 3 years ago

                                                                                                                                                                                                                                                                                                                                                                                                                                      say - text-to-speech engine:

                                                                                                                                                                                                                                                                                                                                                                                                                                      I would have expected that at the era of AI this would sound a bit better than the Commodore 64 speech synthesis from 80s.

                                                                                                                                                                                                                                                                                                                                                                                                                                      • meepmorp · 3 years ago

                                                                                                                                                                                                                                                                                                                                                                                                                                        It's dependent on the voice you pick in system settings. If you choose one of the siri voices for the system voice (not in the siri settings, iirc), it sounds much more natural.

                                                                                                                                                                                                                                                                                                                                                                                                                                      • xenodium · 3 years ago

                                                                                                                                                                                                                                                                                                                                                                                                                                        A couple of built-in I didn't see:

                                                                                                                                                                                                                                                                                                                                                                                                                                        macOS software versions:

                                                                                                                                                                                                                                                                                                                                                                                                                                            sw_vers
                                                                                                                                                                                                                                                                                                                                                                                                                                        
                                                                                                                                                                                                                                                                                                                                                                                                                                        
                                                                                                                                                                                                                                                                                                                                                                                                                                        macOS hardware overview:

                                                                                                                                                                                                                                                                                                                                                                                                                                            system_profiler SPHardwareDataType
                                                                                                                                                                                                                                                                                                                                                                                                                                        
                                                                                                                                                                                                                                                                                                                                                                                                                                        
                                                                                                                                                                                                                                                                                                                                                                                                                                        Convert binary plist to xml

                                                                                                                                                                                                                                                                                                                                                                                                                                            plutil -convert xml1 -o out.xml in.plist
                                                                                                                                                                                                                                                                                                                                                                                                                                        
                                                                                                                                                                                                                                                                                                                                                                                                                                        
                                                                                                                                                                                                                                                                                                                                                                                                                                        A couple of lesser known, but also handy ones to install:

                                                                                                                                                                                                                                                                                                                                                                                                                                            brew install dark-mode
                                                                                                                                                                                                                                                                                                                                                                                                                                        
                                                                                                                                                                                                                                                                                                                                                                                                                                            brew install duti
                                                                                                                                                                                                                                                                                                                                                                                                                                        
                                                                                                                                                                                                                                                                                                                                                                                                                                        > screencapture - take screenshots

                                                                                                                                                                                                                                                                                                                                                                                                                                        Big fan of screencapture. I wanted something similar but for capturing window videos, so I built https://github.com/xenodium/macosrec

                                                                                                                                                                                                                                                                                                                                                                                                                                        I often wrap command line utilites with Emacs functions (don't need to remember invocation flags/structure but also enables batch invocations) https://xenodium.com/recordscreenshot-windows-the-lazy-way

                                                                                                                                                                                                                                                                                                                                                                                                                                        • Crontab · 3 years ago

                                                                                                                                                                                                                                                                                                                                                                                                                                          When a new MacOS release comes out, one of the first things I look for is adds and changes to the command line tools. Sadly they are not the things that most people care about on a new release.

                                                                                                                                                                                                                                                                                                                                                                                                                                          • silly_squidward · 3 years ago

                                                                                                                                                                                                                                                                                                                                                                                                                                            You should check out "um" https://github.com/promptops/cli for when you can't remember the command/parameters.

                                                                                                                                                                                                                                                                                                                                                                                                                                            ~ um prevent my mac from sleeping for 30m

                                                                                                                                                                                                                                                                                                                                                                                                                                               caffeinate -u -t 1800
                                                                                                                                                                                                                                                                                                                                                                                                                                                don't see what you're looking for? try providing more context
                                                                                                                                                                                                                                                                                                                                                                                                                                            • defatigable · 3 years ago

                                                                                                                                                                                                                                                                                                                                                                                                                                              Hey, this looks awesome. Thanks so much for the pointer.

                                                                                                                                                                                                                                                                                                                                                                                                                                            • koinedad · 3 years ago

                                                                                                                                                                                                                                                                                                                                                                                                                                              pbcopy and pbpaste are soooo helpful

                                                                                                                                                                                                                                                                                                                                                                                                                                                • thomasahle · 3 years ago

                                                                                                                                                                                                                                                                                                                                                                                                                                                  I just tried the following: I copied all of my ~/.bash_history into GPT and asked it for some commands that would save me time. It didn't quite work to identify "bad patterns" as I had hoped, but it did suggest the following:

                                                                                                                                                                                                                                                                                                                                                                                                                                                  1. bat: A `cat` clone with syntax highlighting and Git integration.

                                                                                                                                                                                                                                                                                                                                                                                                                                                  2. htop: Interactive process viewer, a better alternative to `top`.

                                                                                                                                                                                                                                                                                                                                                                                                                                                  3. fzf: Command-line fuzzy finder to quickly search files, command history, etc.

                                                                                                                                                                                                                                                                                                                                                                                                                                                  4. tldr: Community-driven man pages with practical examples.

                                                                                                                                                                                                                                                                                                                                                                                                                                                  5. ripgrep (rg): Extremely fast text search tool, recursively searches directories for a regex pattern.

                                                                                                                                                                                                                                                                                                                                                                                                                                                  6. tmux: Terminal multiplexer to run multiple terminal sessions within a single window.

                                                                                                                                                                                                                                                                                                                                                                                                                                                  7. autoenv: Automatically source environment variables based on the current directory.

                                                                                                                                                                                                                                                                                                                                                                                                                                                  8. hub: Extends git with extra features and commands for GitHub.

                                                                                                                                                                                                                                                                                                                                                                                                                                                  9. ncdu: Disk usage analyzer with an ncurses interface.

                                                                                                                                                                                                                                                                                                                                                                                                                                                  10. jq: Lightweight command-line JSON processor.

                                                                                                                                                                                                                                                                                                                                                                                                                                                  11. sshfs: Mount a remote filesystem using SFTP.

                                                                                                                                                                                                                                                                                                                                                                                                                                                  12. watch: Execute a program periodically, showing output fullscreen.

                                                                                                                                                                                                                                                                                                                                                                                                                                                  13. fd: Simpler and faster alternative to `find`.

                                                                                                                                                                                                                                                                                                                                                                                                                                                  14. z: Jump around directories based on frequent use.

                                                                                                                                                                                                                                                                                                                                                                                                                                                  15. lazygit: Simple terminal UI for git commands.

                                                                                                                                                                                                                                                                                                                                                                                                                                                  Most of them I already knew, but z seems like an interesting tool. The docs are here <https://github.com/rupa/z>:

                                                                                                                                                                                                                                                                                                                                                                                                                                                         z foo         cd to most frecent dir matching foo
                                                                                                                                                                                                                                                                                                                                                                                                                                                  
                                                                                                                                                                                                                                                                                                                                                                                                                                                         z foo bar     cd to most frecent dir matching foo, then bar
                                                                                                                                                                                                                                                                                                                                                                                                                                                  
                                                                                                                                                                                                                                                                                                                                                                                                                                                         z -r foo      cd to highest ranked dir matching foo
                                                                                                                                                                                                                                                                                                                                                                                                                                                  
                                                                                                                                                                                                                                                                                                                                                                                                                                                         z -t foo      cd to most recently accessed dir matching foo
                                                                                                                                                                                                                                                                                                                                                                                                                                                  
                                                                                                                                                                                                                                                                                                                                                                                                                                                         z -l foo      list all dirs matching foo (by frecency)
                                                                                                                                                                                                                                                                                                                                                                                                                                                  
                                                                                                                                                                                                                                                                                                                                                                                                                                                  Might start using it, if I'm not too stuck in my habits.
                                                                                                                                                                                                                                                                                                                                                                                                                                                  • tambourine_man · 3 years ago

                                                                                                                                                                                                                                                                                                                                                                                                                                                    >I copied all of my ~/.bash_history into GPT

                                                                                                                                                                                                                                                                                                                                                                                                                                                    I wouldn't do that. I treat ChatGPT as public.

                                                                                                                                                                                                                                                                                                                                                                                                                                                    But it's a good list nevertheless

                                                                                                                                                                                                                                                                                                                                                                                                                                                    • msie · 3 years ago

                                                                                                                                                                                                                                                                                                                                                                                                                                                      json_pp

                                                                                                                                                                                                                                                                                                                                                                                                                                                      • tambourine_man · 3 years ago

                                                                                                                                                                                                                                                                                                                                                                                                                                                        In the best HN tradition, the list in the article is good, but the comments section is where the gold nuggets are.

                                                                                                                                                                                                                                                                                                                                                                                                                                                        • FabHK · 3 years ago

                                                                                                                                                                                                                                                                                                                                                                                                                                                          Another one that comes in handy occasionally is afconvert to convert audio files. I like to add audio files (eg audio books, or guided meditations) to iTunes/Music or Books, and they are a little bit finicky in terms of what they accept and sync (I've had problems with files converted with ffmpeg).

                                                                                                                                                                                                                                                                                                                                                                                                                                                          I use this to convert an mp3 to a variable rate m4b for Books:

                                                                                                                                                                                                                                                                                                                                                                                                                                                              afconvert -v -s 3 -f m4bf meditation1.mp3
                                                                                                                                                                                                                                                                                                                                                                                                                                                          • oregano · 3 years ago

                                                                                                                                                                                                                                                                                                                                                                                                                                                            At the risk of sounding like an idiot, can someone please explain why I cannot use `networkQuality` when zsh is my shell? Is there an alternative for zsh?

                                                                                                                                                                                                                                                                                                                                                                                                                                                            • remi · 3 years ago

                                                                                                                                                                                                                                                                                                                                                                                                                                                              It’s not a shell utility, it should work with any shell.

                                                                                                                                                                                                                                                                                                                                                                                                                                                                $ which networkQuality
                                                                                                                                                                                                                                                                                                                                                                                                                                                                /usr/bin/networkQuality
                                                                                                                                                                                                                                                                                                                                                                                                                                                              • oregano · 3 years ago

                                                                                                                                                                                                                                                                                                                                                                                                                                                                Yes thanks- probably an issue with my $PATH

                                                                                                                                                                                                                                                                                                                                                                                                                                                            • ernst_mulder · 3 years ago

                                                                                                                                                                                                                                                                                                                                                                                                                                                              Many thanks OP for the couple of commands I did not yet know. Especially `pbcopy` and `pbpaste`, those are going to be very useful.

                                                                                                                                                                                                                                                                                                                                                                                                                                                              Here are a couple of commands I use quite a lot.

                                                                                                                                                                                                                                                                                                                                                                                                                                                              lsof -p <PID>

                                                                                                                                                                                                                                                                                                                                                                                                                                                              Lists the open files of the process with process ID <PID>. Very very useful.

                                                                                                                                                                                                                                                                                                                                                                                                                                                              fs_usage -w <PID>

                                                                                                                                                                                                                                                                                                                                                                                                                                                              This one is mentioned by others here as well, but followed by a <PID> it shows all filesystem activity of the given process. Useful if you want to know where specific settings of an application are stored.

                                                                                                                                                                                                                                                                                                                                                                                                                                                              top -u

                                                                                                                                                                                                                                                                                                                                                                                                                                                              Obvious what this does, standard command. Sorted by CPU usage.

                                                                                                                                                                                                                                                                                                                                                                                                                                                              <some command> | open -ft

                                                                                                                                                                                                                                                                                                                                                                                                                                                              Opens the <some command>'s result in your default text editor.

                                                                                                                                                                                                                                                                                                                                                                                                                                                              system_profiler

                                                                                                                                                                                                                                                                                                                                                                                                                                                              Very useful for finding out stuff. E.g. system_profiler SPNVMeDataType SPSerialATADataType | grep 'BSD Name: disk[0-9]$' | sed 's/.\* //' Gives the device name of all your system's SATA and NVMe SSD's.

                                                                                                                                                                                                                                                                                                                                                                                                                                                              sysctl -a

                                                                                                                                                                                                                                                                                                                                                                                                                                                              Another way to find out stuff. E.g. sysctl -a | grep hw.memsize Shows the amount of physical memory in your system.

                                                                                                                                                                                                                                                                                                                                                                                                                                                              tmutil

                                                                                                                                                                                                                                                                                                                                                                                                                                                              Very powerful for managing Time Machine as mentioned by others here. Also useful for other stuff. There is a lot of File I/O on my system due to running at least five VM's all the time. This produces big snapshots. Every now and then my system hung up due to running out of space because of these snapshots. Now I'm running my own "snapshottaper" daemon running every ten minutes keeping only the last 4 snapshots and deleting the rest, using "tmutil listlocalsnapshotdates" and "tmutil deletelocalsnapshots" which eliminates that issue (which is a bug imho).

                                                                                                                                                                                                                                                                                                                                                                                                                                                              And some of my often used (tcsh) aliases:

                                                                                                                                                                                                                                                                                                                                                                                                                                                              proc, aliased to 'ps -axww -o pid,user,command | grep -v "grep -i" | grep -i \!\* | sed "s/^\ *//"'

                                                                                                                                                                                                                                                                                                                                                                                                                                                              Filter the list of running processes for a specific string, e.g. use "proc adobe" to find all running processes by Adobe. I use this a lot.

                                                                                                                                                                                                                                                                                                                                                                                                                                                              spf, aliased to 'dig \!* txt | grep "v=spf"'

                                                                                                                                                                                                                                                                                                                                                                                                                                                              Useful for finding SPF records for a given domain, e.g. 'spf apple.com'.

                                                                                                                                                                                                                                                                                                                                                                                                                                                              mx, aliased to 'dig \!\* mx | grep -v "^;..*" | grep "IN\WMX"'

                                                                                                                                                                                                                                                                                                                                                                                                                                                              Same, but for MX records (I maintain e-mail servers, hence these two).

                                                                                                                                                                                                                                                                                                                                                                                                                                                              est, aliased to 'netstat -n | grep -i proto ; netstat -n | grep ESTABLISHED | grep -v 127.0.0.1'

                                                                                                                                                                                                                                                                                                                                                                                                                                                              List all currently open network connections.

                                                                                                                                                                                                                                                                                                                                                                                                                                                              listen, aliased to 'sudo echo -n; sudo lsof -i4 -n -P | grep "\*:" | sed "s/IPv4.*://" | grep LISTEN | sort -n --key=5 | sed "s/ (LISTEN)//" | awk BEGIN\ \{print\ \"COMMAND\ \ \ \ \ \ \ \ \ \ \ PID\ \ \ \ \ \ \ USER\ \ \ \ \ \ \ PORT\"\}\ \{printf\ \"%-10s\ %10s\ %10s\ %10s\\n\"\,\ \$1\,\ \$2\,\ \$3\,\ \$5\}'

                                                                                                                                                                                                                                                                                                                                                                                                                                                              List all processes currently listening on network ports.

                                                                                                                                                                                                                                                                                                                                                                                                                                                              router, aliased to 'netstat -rn -f inet | grep default | grep -v link | awk \{print\ \$2\} | head -1'

                                                                                                                                                                                                                                                                                                                                                                                                                                                              List the currently used internet router.

                                                                                                                                                                                                                                                                                                                                                                                                                                                              (I hope all escape characters and such survive posting this, please excuse me if they don't, also my default command shell is tcsh for historical reasons, it was my default shell in the early 1990's. Yes my shell scripts are all #!/bin/sh)

                                                                                                                                                                                                                                                                                                                                                                                                                                                              Other than these, I really like using AppleScript and shell scripts together. Using AppleScript I now have my own GUI tools for making disk images using drag-and-drop, compacting sparse images, performing default settings for new installations, switching between virtual machines whilst hiding others, etc.

                                                                                                                                                                                                                                                                                                                                                                                                                                                              • d4rkp4ttern · 3 years ago

                                                                                                                                                                                                                                                                                                                                                                                                                                                                I recently discovered snippet-management tools, which I didn't know I needed. I'm trying Maccy and Paste. Curious which ones others love.

                                                                                                                                                                                                                                                                                                                                                                                                                                                                • revicon · 3 years ago

                                                                                                                                                                                                                                                                                                                                                                                                                                                                  I wrote this a while back to document managing WIFI connections using the command line.

                                                                                                                                                                                                                                                                                                                                                                                                                                                                  https://www.mattcrampton.com/blog/managing_wifi_connections_...

                                                                                                                                                                                                                                                                                                                                                                                                                                                                  I use these commands a lot when I'm in a coffeeshop and I'm trying to fine-grain control which wifi connection my laptop is using and dealing with passwords.

                                                                                                                                                                                                                                                                                                                                                                                                                                                                  IMO OSX's UI for wifi network picking is clunky when you're in an area with >50 wifi networks in range, command line tools are much easier to deal with.

                                                                                                                                                                                                                                                                                                                                                                                                                                                                  • tobiasbischoff · 3 years ago

                                                                                                                                                                                                                                                                                                                                                                                                                                                                    Super cool.

                                                                                                                                                                                                                                                                                                                                                                                                                                                                    • bhal · 3 years ago

                                                                                                                                                                                                                                                                                                                                                                                                                                                                      Great list, working with Mac a long time and found some good things here. This might be useful too:

                                                                                                                                                                                                                                                                                                                                                                                                                                                                      # cd to frontmost open finder folder (in Terminal cd to the current top finder window) cdf() { cd "`osascript -e 'tell app "Finder" to POSIX path of (insertion location as alias)'`"; pwd; }

                                                                                                                                                                                                                                                                                                                                                                                                                                                                      # Copy the frontmost open finder folder Path from Terminal to the Clipboard in MacOS: cpf() { echo "`osascript -e 'tell app "Finder" to POSIX path of (insertion location as alias)'`"|pbcopy; }

                                                                                                                                                                                                                                                                                                                                                                                                                                                                      # open manpage in preview app: pman() { mandoc -T pdf "$(/usr/bin/man -w $@)" | open -fa Preview; }

                                                                                                                                                                                                                                                                                                                                                                                                                                                                      # Function to delete a given line in ssh known_hosts file: xho() { line=$1;tFile="$HOME/.ssh/known_hosts";sed -e "${line}d" -i ".tmp" "$tFile";}