Showing posts with label Mac. Show all posts
Showing posts with label Mac. Show all posts

2025-07-29

Disable key repeating when using vi on Warp terminal

SYSTEM WIDE

$ defaults write -g ApplePressAndHoldEnabled -bool false


ONLY FOR WARP

$ defaults write dev.warp.Warp-Stable ApplePressAndHoldEnabled -bool false


 

2021-07-01

Remove password from pdf file using ghostscript

Remove password from pdf file using ghostscript
$ gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sPDFPassword=PASSWORD -sOutputFile=OUTPUT.pdf -f ENCRYPTED.pdf
Install GhostScript on Mac
$ brew install ghostscript

2021-02-01

youtube-dl

List format for a video
$ youtube-dl -F 8Gpa_pdHrPE                        
List format for a playlist
$ youtube-dl -F PLBiQZMT3oSxW1RS1hn2jWBgswh0nlcgQZ\&index\=1
[youtube] 8Gpa_pdHrPE: Downloading webpage
[youtube] 8Gpa_pdHrPE: Downloading MPD manifest
[info] Available formats for 8Gpa_pdHrPE:
format code  extension  resolution note
139          m4a        audio only DASH audio   54k , m4a_dash container, mp4a.40.5@ 48k (22050Hz)
140          m4a        audio only DASH audio  134k , m4a_dash container, mp4a.40.2@128k (44100Hz)
251          webm       audio only DASH audio  136k , webm_dash container, opus @160k (48000Hz)
278          webm       256x144    DASH video   95k , webm_dash container, vp9, 30fps, video only
160          mp4        256x144    DASH video  108k , mp4_dash container, avc1.4d400b, 30fps, video only
242          webm       426x240    DASH video  220k , webm_dash container, vp9, 30fps, video only
133          mp4        426x240    DASH video  242k , mp4_dash container, avc1.4d400c, 30fps, video only
134          mp4        640x360    DASH video  274k , mp4_dash container, avc1.4d401e, 30fps, video only
243          webm       640x360    DASH video  405k , webm_dash container, vp9, 30fps, video only
244          webm       854x480    DASH video  752k , webm_dash container, vp9, 30fps, video only
135          mp4        854x480    DASH video 1155k , mp4_dash container, avc1.4d4014, 30fps, video only
247          webm       1280x720   DASH video 1505k , webm_dash container, vp9, 30fps, video only
137          mp4        1920x1080  DASH video 1831k , mp4_dash container, avc1.640028, 30fps, video only
136          mp4        1280x720   DASH video 2310k , mp4_dash container, avc1.4d4016, 30fps, video only
248          webm       1920x1080  DASH video 2646k , webm_dash container, vp9, 30fps, video only
18           mp4        640x360    360p  216k , avc1.42001E, 30fps, mp4a.40.2@ 96k (44100Hz), 123.62MiB
22           mp4        1280x720   720p  511k , avc1.64001F, 30fps, mp4a.40.2@192k (44100Hz) (best)
.bashrc or .zshrc
alias ytdl="youtube-dl --merge-output-format mp4 -f \"bestvideo+bestaudio[ext=m4a]/best\" -o \”%(title)s.%(ext)s\” --embed-thumbnail --add-metadata"
usage
$ ytdl 8Gpa_pdHrPE
$ ytdl PLBiQZMT3oSxW1RS1hn2jWBgswh0nlcgQZ\&index\=1

2020-09-28

Unicode normalization

NFD to NFC with convmv
 $ brew install convmv

 # Convert all files in a directory from NFD to NFC:
 $ convmv -f utf-8 -t utf-8 --nfc --notest .

 # Convert all files in a directory from NFC to NFD:
 $ convmv -f utf-8 -t utf-8 --nfd --notest .
NFD to NFC with iconv
 $ iconv -f UTF-8 -t UTF-8-MAC
NFD to NFC with rsync
 $ rsync --iconv=utf-8,utf-8-mac

2020-08-27

SSH with multiple private keys

Add privat keys
 $ ssh-add ~/.ssh/id_rsa_SERVER
Verify keys
 $ ssh-add -l
Test keys
 $ ssh -v URL_TO_HOST
Connect to server
 $ ssh HOSTNAME_OR_ALIAS

2020-04-23

ISO to USB on Mac Mojave

  1. List devices
    $ diskutil list
    /dev/disk0 (internal, physical):
       #:                       TYPE NAME                    SIZE       IDENTIFIER
       0:      GUID_partition_scheme                        *251.0 GB   disk0
       1:                        EFI EFI                     314.6 MB   disk0s1
       2:                 Apple_APFS Container disk1         250.7 GB   disk0s2
    
    /dev/disk1 (synthesized):
       #:                       TYPE NAME                    SIZE       IDENTIFIER
       0:      APFS Container Scheme -                      +250.7 GB   disk1
                                     Physical Store disk0s2
       1:                APFS Volume Macintosh HD - Data     77.5 GB    disk1s1
       2:                APFS Volume Preboot                 82.0 MB    disk1s2
       3:                APFS Volume Recovery                528.1 MB   disk1s3
       4:                APFS Volume VM                      1.1 GB     disk1s4
       5:                APFS Volume Macintosh HD            11.1 GB    disk1s5
    
    /dev/disk2 (external, physical):
       #:                       TYPE NAME                    SIZE       IDENTIFIER
       0:     FDisk_partition_scheme                        *124.2 GB   disk2
       1:             Windows_FAT_32 CCCOMA_X64F             124.2 GB   disk2s1
    
  2. Unmount USB stick
    $ diskutil unmountDisk /dev/disk2
    Unmount of all volumes on disk2 was successful
    
  3. $ sudo dd if=kali-linux-2020.1b-installer-amd64.iso of=/dev/disk2 bs=1m
    Password:
    2075+1 records in
    2075+1 records out
    2176778240 bytes transferred in 656.146374 secs (3317519 bytes/sec)
    

2020-04-17

2019-10-04

GCC 32bit compile on Mac

  • The i386 architecture is deprecated for macOS
    $ gcc -m32 fib.c
    ld: warning: The i386 architecture is deprecated for macOS (remove from the Xcode build setting: ARCHS)
    ld: warning: ignoring file /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/lib/libSystem.tbd, missing required architecture i386 in file /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/lib/libSystem.tbd
    Undefined symbols for architecture i386:
      "_printf", referenced from:
          _main in fib-68f6b9.o
    ld: symbol(s) not found for architecture i386
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    
  • Install i386 support
    $ sudo rm -rf /Library/Developer/CommandLineTools
    $ xcode-select --install
    $ open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg
    
  • Compile
    $ gcc -m32 fib.c
    ld: warning: The i386 architecture is deprecated for macOS (remove from the Xcode build setting: ARCHS)
    
    $ make CFLAGS="-m32" fib
    cc -m32    fib.c   -o fib
    ld: warning: The i386 architecture is deprecated for macOS (remove from the Xcode build setting: ARCHS)
    

2019-07-20

Broken attachment filename with Apple mail

With Apple mail, Korean attachment filename is broken.
Attachment filename is encoded to UTF-8
Run the following command within Terminal, then restart Apple mail.
$ defaults write com.apple.mail NSPreferredMailCharset "UTF-8"

2017-11-10

How to use different gateways by IP address on Linux and Mac

on Linux
$ sudo route add -net 192.168.0.0 netmask 255.255.0.0 gw 192.168.0.1
$ sudo route add -net 192.168.1.0 netmask 255.255.0.0 gw 192.168.0.254
$ sudo route add -net 192.168.0.0 netmask 255.255.0.0 dev eth0
$ sudo route add -net 192.168.1.0 netmask 255.255.0.0 dev eth1
$ sudo route add -net 192.168.0.0/16 gw 192.168.0.1
$ sudo route add -net 192.168.1.0/16 gw 192.168.0.254
$ sudo route add -net 192.168.0.0/16 dev eth0
$ sudo route add -net 192.168.1.0/16 dev eth1
on Mac
$ sudo route -n add -net 192.168.0.0 -netmask 255.255.0.0 192.168.0.1
$ sudo route -n add -net 192.168.1.0 -netmask 255.255.0.0 192.168.0.254
$ sudo route -n add -net 192.168.0.0/16 192.168.0.1
$ sudo route -n add -net 192.168.1.0/16 192.168.0.254

2017-11-09

[MAC] convert png to icns with terminal

Use sips to convert png to icns
$ sips
sips 10.4.4 - scriptable image processing system.

This tool is used to query or modify raster image files and ColorSync ICC profiles.
Its functionality can also be used through the "Image Events" AppleScript suite.
Try 'sips --help' or 'sips --helpProperties' for help using this tool

Command
$ sips -s format icns input.png --out output.icns

[MAC] SOMETHING ON DEVICES can't be opened because the original item can't be found

"Cloud" can't be opened because the original item can't be found. Cloud is not an external device.



Follow 3 steps to resolve.
1. Relaunch Finder

  • Option+Right click -> Select Relaunch
  • or open terminal then run "killall Finder"


2. Force quit Finder

  • Apple menu -> Force Quit Finder -> Select Finder -> Click Relaunch
  • or Option+Command+Escape -> Select Finder -> Click Relaunch

3. Logout then Login again. Now no more Cloud.

2017-02-12

Hide files and folders with an Encrypted disk image on Mac

1. Create an Encrypted disk image file
$ hdiutil create -size 100g -layout GPTSPUD -fs "Journaled HFS+" -volname "Secured Repository" -type SPARSEBUNDLE -encryption AES-128 EncDiskImg

Enter a new password to secure "EncryptedDisk.sparsebundle": **********
Re-enter new password: **********

created: /Users/dee/Cloud/EncDiskImg.sparsebundle
* For more options
 $ hdiutil create -help
or use Disk Utility


2. Mount
Double click the image on Finder then answer password you enter the above.
or
$ hdiutil mount EncDiskImg.sparsebundle

Enter password to access "EncDiskImg.sparsebundle": **********

/dev/disk2           GUID_partition_scheme
/dev/disk2s1        EFI
/dev/disk2s2        Apple_HFS /Volumes/Secured Repository

3. Also you can hide the file not to show on Finder. Note that the "ls" command on Terminal can list the file.
$ setfile -a V EncDiskImg.sparsebundle
* Use applescript to mount a hidden file.
do shell script "hdiutil mount /PATH/TO/EndDiskImg.sparsebundle"
It will show you a prompt to get password.

2017-01-31

How to set DYLD_LIBRARY_PATH in Xcode

Open Product > Scheme > Edit Scheme > Run > Arguments
Add DYLD_LIBRARY_PATH under Environment Variables