Skip to content

Instantly share code, notes, and snippets.

@varenc
varenc / _launchctl
Created May 10, 2023 22:39
macOS launchctl completion for for bash and zsh (autocomplete)
#!/bin/bash
#
# Bash completion support for launchctl
__launchctl_list_sigs ()
{
echo {,SIG}{HUP,INT,QUIT,ILL,TRAP,ABRT,EMT,FPE,KILL,BUS,SEGV,SYS,PIPE,ALRM,TERM,URG,STOP,TSTP,CONT,CHLD,TTIN,TTOU,IO,XCPU,XFSZ,VTALRM,PROF,WINCH,INFO,USR1,USR2} `seq 1 31 | tr '\n' ' '`
}
__launchctl_list_pids ()
@varenc
varenc / _ugrep
Created May 10, 2023 22:36
ugrep zsh completion automatically generated
#compdef ugrep
# zsh completions for 'ugrep'
# automatically generated with http://github.com/RobSis/zsh-completion-generator
local arguments
arguments=(
{-A,--after-context}'[output NUM lines of trailing context after matching lines. Places]'
{-a,--text}'[process a binary file as if it were text. This is equivalent to]'
'--and[PATTERN ... -e PATTERN]'
@varenc
varenc / extract_vcf_image.sh
Created April 24, 2023 20:07
Extract the contact photo from a .vcf contact file. Decodes the base64 encoded contact image/jpeg from a .vcf file.
### Extract the contact image from a .vcf file. This is otherwise impossible with macOS contacts.
### To work, first export a single contact as a .vcf file.
#
# Example Usage:
# $ extract_vcf_image input.vcf > output.jpg
# $ file output.jpg
# output.jpg: JPEG image data, JFIF standard 1.01, aspect ratio, density 72x72, segment length 16, Exif Standard: [TIFF image data, big-endian, direntries=1TIFF image data, big-endian, direntries=1], baseline, precision 8, 148x148, components 3
#
# Notes:
# - 2nd argument is the output path, if not specified, will output to stdout
@varenc
varenc / unblock_keyboard_shortcuts.js
Last active March 11, 2023 01:37
Unblock browser keyboard shortcuts (in Chrome) from bad website javascript (like discussions.apple.com forums)
// Some bad sites, like the discussions.apple.com Apple Forums, block various browser keyboard shortcuts. Very rarely do you want this.
// They even block basic things like refresh, Cmd+R, or go back, Cmd+[
// This snippet just insert a new event handler that stops propagration but doesn't prevent the default.
// This prevents a site/Apple's event handlers from blocking your shortcuts. It also disables all other Keyboard shortcuts.
// ublock origin instructions:
// You can use ublock origin to automatically run this snippet on certain sites using a custom resource: https://github.com/gorhill/uBlock/wiki/Advanced-settings#userresourceslocation
// Steps
// - Create a custom JS resource file (see linked docs above) that includes this snippet. Here is mine for example: https://gist.github.com/varenc/7c0c17eea480a03d7c8844d81e608e1e#file-ublock_custom_scripts-js-L49
// - Once you have this JS available to use as a resource, just create a ublock filter rule to run it on certain sites.
@varenc
varenc / ai_shell_command_warp.sh
Created December 19, 2022 23:11
Use Warp's AI Command generator via curl from outside of Warp (Requires you have a Warp account)
### Manually call Warp's AI Command generator
# It's no where near as smart as something like Copilot, but I find it pretty handy sometimes. Sadly the Warp terminal itself is often lacking but I like this feature.
#
# To use, get your long lasting Warp account refresh token. (managed by Firebase/Google)
# How to do this is left as an excercise to the reader. Hint: MITM traffic or look in the Keychain
export WARP_REFRESH_TOKEN="<set yours here>"
# Now copy/paste or source this file to define the `ai_command` function
@varenc
varenc / siri_recording_save.sh
Last active March 5, 2023 08:28
Siri on macOS: Copy and save all Siri audio recordings as .wav files
#!/bin/zsh
###################
# Save all of your Siri recordings on macOS. The recordings will be saved as .wav files in $SIRI_SAVE_DIR
#
# USAGE:
# $ wget https://gist.githubusercontent.com/varenc/8cae8f19fede79f63b84cc85f602f382/raw/siri_recording_save.sh
# $ chmod +x siri_recording_save.sh
# $ ./siri_recording_save.sh
#
@varenc
varenc / zshexpn-explained.md
Created November 26, 2022 02:01 — forked from roblogic/zshexpn-explained.md
Regular Expressions in Zsh

The following is taken from a brilliant answer on unix.se. Posting it here for personal reference. The question was:

${var//pattern/replacement} is using zsh wildcard patterns for pattern, the same ones as used for filename generation aka globbing which are a superset of the sh wildcard patterns. The syntax is also affected by the kshglob and extendedglob options. The ${var//pattern/replacement} comes from the Korn shell initially.

I'd recommend enabling extendedglob (set -o extendedglob in your ~/.zshrc) which gives you the most features (more so than standard EREs) at the expense of some backward incompatibility in some corner cases.

You'll find it documented at info zsh 'filename generation'.

@varenc
varenc / system_profiler_SPDisplaysDataType.json
Created November 24, 2022 00:27
`system_profiler -json SPDisplaysDataType` output on a MBP 16" 2019
{
"SPDisplaysDataType" : [
{
"_name" : "kHW_IntelUHDGraphics630Item",
"_spdisplays_vram" : "1536 MB",
"spdisplays_automatic_graphics_switching" : "spdisplays_supported",
"spdisplays_device-id" : "0x3e9b",
"spdisplays_gmux-version" : "5.0.0",
"spdisplays_metalfamily" : "spdisplays_mtlgpufamilymac2",
"spdisplays_ndrvs" : [
@varenc
varenc / README.md
Last active April 18, 2023 10:29
Homebrew patch to spoof a particular macOS version to allow you to force install pre-compiled binary bottles anywhere

Force brew to install pre-compiled binary bottles on older versions of macOS (Mojave).

This patch makes a small modification to Homebrew allowing you to "spoof" or override its perceived macOS version. Often compiled bottles will work fine on older unsupported macOS verisons and using a bottle means you don't have to compile a formula from scratch or download and compile its build-only dependencies.

Of course you shouldn't do this unless you're very familiar Homebrew internals and understand the limitations. Things make break in a very confusing way. Most users should just keep macOS up to date, but for those that can't this patch may be helpful.

To use, first download and install the patch:

$ cd "$(brew --repo)"
$ wget "https://gist.githubusercontent.com/varenc/47c4b22e2b8c5afabce556645a90801d/raw/homebrew_override_version.patch" --output-document=/tmp/homebrew_override_version.patch
@varenc
varenc / profile_defaults.md
Created May 6, 2022 01:37 — forked from dlevi309/profile_defaults.md
An extensive list of settings written when installing a debugging profile from developer.apple.com

MediaPlayer logging:

defaults: {
    "com.apple.homesharing" =     {
        HSConsoleLoggingLevel = 7;
        HSLogFileLoggingLevel = 7;
        HSLogging = 1;
    };
    "com.apple.medialibrary" =     {