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 ..
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
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.
networkQuality is something I really wish I knew about sooner.
/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>
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/p...
# 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'
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
I also alias pbcopy / pbpaste on Linux too, so useful!
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.I use pbcopy and pbpaste probably all day long and always miss it in Linux environments.
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.
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.
hidutil property --set '{"UserKeyMapping":[{"HIDKeyboardModifierMappingSrc":0x700000064,"HIDKeyboardModifierMappingDst":0x700000035}]}'
Remaps top left key on Euro-style keyboards from useless "paragraph" to useful "backtick". /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.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.
On [2] you might find the aliases to pbutil for X11-based Linuxes.
[0]: If not, why not run apt-get command to install one of them, like xclip?
[1]: https://git.zx2c4.com/password-store/tree/src/password-store...
[2]: https://ostechnix.com/how-to-use-pbcopy-and-pbpaste-commands...
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
say "process failure" -v trinoids
you can find all the available voices with say -v '?'
or from Accessibility>Spoken-Content>System-voice>Manage-voiceshttps://osxdaily.com/2014/06/11/use-ditto-copy-files-directo...
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.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.
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 alias pbcopy="xclip -selection clipboard"
alias pbpaste="xclip -selection clipboard -o"
Thanks for sharing.
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.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.
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
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.
alias firefox="open -a Firefox"
This will work < foo.json jq | pbcopy
alias open="xdg-open"
Instead, they open a file descriptor and pass that.
Tiny difference but there you go.
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
}
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!
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 , ' ')
[1]: https://developer.apple.com/documentation/xcode/installing-a...
(There's BetterDisplay - formerly BetterDummy - but it introduces noticeable input lag for me.)
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)
Am I the only one who finds macOS so annoying?
I mean the apps for scroll wheel, alt-tab and what not...
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.
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.
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.
> 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.
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...
macOS 13 Ventura ships with a customized `iperf3` called `iperf3-darwin` adding features like QUIC/L4S/MPTCP.
#!/usr/bin/env python3
import sys
import json
print(json.load(sys.stdin))
alias op='open .'
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>
"So, I used the msf module that invokes `say` on a client's laptop"
``` #!/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!" ```
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
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.
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
And ... ?
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.
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.
In short, I straight up don't care.
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.
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...).
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.
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?
https://opensource.apple.com/source/cups/cups-450/cups/doc/h...
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?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.
lot's of times we sort of know what we are working with, but don't remember the particulars especially
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.
https://developer.apple.com/documentation/uikit/uipasteboard...
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.
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).
If you type `say os x`, it'll actually speak "oh es ten".
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
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.
> 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?
I still uselessly use cat though, it's such a nice way to build a pipeline.
May be a version thing, may be some extended stuff that more common parsers do not support, not sure.
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.
# 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
}
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...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.
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"
}
}
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.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.
-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.
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.)
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/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/
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.
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.
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.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.
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
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 screenshotsBig 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
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.
alias clip='pbcopy <'
Are you sure? https://unix.stackexchange.com/questions/208615/is-cat-a-she... disagrees and neither https://manpages.ubuntu.com/manpages/jammy/man7/bash-builtin... nor https://zsh.sourceforge.io/Doc/Release/Shell-Builtin-Command... mention it
~ um prevent my mac from sleeping for 30m
caffeinate -u -t 1800
don't see what you're looking for? try providing more context
https://github.com/davatorium/rofi
Looks like this:
https://i.imgur.com/Hm9TGeV.jpg
In a vscode terminal I just use the alias "o" and it opens that at the correct location, then I can navigate and pick a file to open in the editor.
> 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)
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. $ fd 's(merge|ubl)$' /Applications/Sublime*
/Applications/Sublime Merge.app/Contents/SharedSupport/bin/smerge
/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl
I wouldn't do that. I treat ChatGPT as public.
But it's a good list nevertheless
I download and save it as 'ytdl' for convenience, but I use it all the time on twitter too.
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=36492487Even the Wikipedia page on cat has a section about that, titled eponymously.
I use this to convert an mp3 to a variable rate m4b for Books:
afconvert -v -s 3 -f m4bf meditation1.mp3
copy_file_range allows a user land program to copy data between two files without doing any user space work. Instead of reading data into a buffer and writing it back out to the destination, the kernel will somehow manage to move the data for you.
I think this will prevent any extra copies from occurring in situations where it can be used.
https://man.archlinux.org/man/copy_file_range.2
https://git.savannah.gnu.org/cgit/coreutils.git/tree/src/cat...
https://georgegarside.com/blog/macos/fix-apple-watch-auto-un...
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.
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.
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 reasonHere 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.
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.
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.
> “…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/
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)
`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
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.
Many of these utilities have been rewritten in Rust and have more modern features and are faster.
For example, instead of ls, I use exa [1]. Or ripgrep [2] instead of grep. sd [3] instead of sed.
[1]: https://github.com/ogham/exa
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.
#!/bin/bash
afplay -v 3 /System/Library/Sounds/Glass.aiff
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.
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
You can use dnctl and pfctl on macOS to do similar things and more.
But thank you for the share, it is interesting!
[1]: https://github.com/roy2220/osc52pty/blob/master/oscexecutor....
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.
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.
:w !pbcopy
or visual selection, and then :w !pbcopy
# 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";}