helio.loureiro.eng.br
  • Home
  • Unix
  • Linux
  • Blog
  • Python
  • Programação
  • Tudo
  • Suécia
  1. You are here:  
  2. Home
  3. Unix
  4. MacOS/Darwin/BSD

Os artigos mais lidos de 2024

  • linux-br.org num ritmo mais lento
  • Criando um serviço de relay de DNS-over-HTTPS
  • Minha palestra sobre a história do Unix na IX BSD Day
  • Pedal forte de 2023 em dados do Google
  • Linux vs GNU/Linux

Unzip com erro illegal byte sequence no MacOS

Details
Written by: Helio Loureiro
Category: MacOS/Darwin/BSD
Published: May 25, 2023
Hits: 2719

Recentemente eu descobri que minha conta corporativa no Google, que uso pra gerenciar o loureiro.eng.br no geral, custa muito caro pra aumentar o tamanho do storage.  Mas muito.

Então resolvi voltar a usar minha conta genérica do Google/Gmail pra colocar fotos e tudo mais que estava entupindo meu espaço virtual no loureiro.eng.br e afetando o serviço de email entre outras coisas.

Passei então a baixar os albuns que tinha lá, abrir o arquivo em formato zip, extrair os dados e subir na conta genérica que agora tem 200 GB de espaço.

Mas eis que...

$ unzip Sexta-feira\ de\ manhã-001.zip
Archive:  Sexta-feira de manhã-001.zip
checkdir error:  cannot create Sexta-feira de manh+�
                 Illegal byte sequence
                 unable to process Sexta-feira de manh+�/GOPR2787_1553588194745_high.JPG.
checkdir error:  cannot create Sexta-feira de manh+�
                 Illegal byte sequence
                 unable to process Sexta-feira de manh+�/GOPR2815_1553588196860_high.JPG.
checkdir error:  cannot create Sexta-feira de manh+�
                 Illegal byte sequence
                 unable to process Sexta-feira de manh+�/GOPR2733_1553287304138_high.JPG.
checkdir error:  cannot create Sexta-feira de manh+�
                 Illegal byte sequence
                 unable to process Sexta-feira de manh+�/GOPR2765_1553588192848_high.JPG.
checkdir error:  cannot create Sexta-feira de manh+�
                 Illegal byte sequence
                 unable to process Sexta-feira de manh+�/GOPR2805_1553588196125_high.JPG.
checkdir error:  cannot create Sexta-feira de manh+�
                 Illegal byte sequence
                 unable to process Sexta-feira de manh+�/GOPR2766_1553588192990_high.JPG.
checkdir error:  cannot create Sexta-feira de manh+�
                 Illegal byte sequence
                 unable to process Sexta-feira de manh+�/GOPR2804_1553588196053_high.JPG.
checkdir error:  cannot create Sexta-feira de manh+�
                 Illegal byte sequence
                 unable to process Sexta-feira de manh+�/GOPR2737_1553287304362_high.JPG.
checkdir error:  cannot create Sexta-feira de manh+�
                 Illegal byte sequence
                 unable to process Sexta-feira de manh+�/GOPR2816_1553588196891_high.JPG.
checkdir error:  cannot create Sexta-feira de manh+�
                 Illegal byte sequence
                 unable to process Sexta-feira de manh+�/GOPR2772_1553588193399_high.JPG.
checkdir error:  cannot create Sexta-feira de manh+�
                 Illegal byte sequence
                 unable to process Sexta-feira de manh+�/GOPR2789_1553588194826_high.JPG.
checkdir error:  cannot create Sexta-feira de manh+�
                 Illegal byte sequence
                 unable to process Sexta-feira de manh+�/GOPR2792_1553588195166_high.JPG.
checkdir error:  cannot create Sexta-feira de manh+�
                 Illegal byte sequence
                 unable to process Sexta-feira de manh+�/GOPR2802_1553588195831_high.JPG.
checkdir error:  cannot create Sexta-feira de manh+�
                 Illegal byte sequence
                 unable to process Sexta-feira de manh+�/GOPR2769_1553588193183_high.JPG.
checkdir error:  cannot create Sexta-feira de manh+�
                 Illegal byte sequence
                 unable to process Sexta-feira de manh+�/GOPR2735_1553287304243_high.JPG.
checkdir error:  cannot create Sexta-feira de manh+�
                 Illegal byte sequence
                 unable to process Sexta-feira de manh+�/GOPR2764_1553588192788_high.JPG.
checkdir error:  cannot create Sexta-feira de manh+�
                 Illegal byte sequence
                 unable to process Sexta-feira de manh+�/GOPR2809_1553588196428_high.JPG.
checkdir error:  cannot create Sexta-feira de manh+�
                 Illegal byte sequence
                 unable to process Sexta-feira de manh+�/GOPR2793_1553588195213_high.JPG.
checkdir error:  cannot create Sexta-feira de manh+�
                 Illegal byte sequence
                 unable to process Sexta-feira de manh+�/GOPR2781_1553588194244_high.JPG.
checkdir error:  cannot create Sexta-feira de manh+�
                 Illegal byte sequence
                 unable to process Sexta-feira de manh+�/GOPR2814_1553588196818_high.JPG.
checkdir error:  cannot create Sexta-feira de manh+�
                 Illegal byte sequence
                 unable to process Sexta-feira de manh+�/GOPR2785_1553588194565_high.JPG.
checkdir error:  cannot create Sexta-feira de manh+�
                 Illegal byte sequence
                 unable to process Sexta-feira de manh+�/GOPR2784_1553588194484_high.JPG.
checkdir error:  cannot create Sexta-feira de manh+�
                 Illegal byte sequence
                 unable to process Sexta-feira de manh+�/GOPR2812_1553588196668_high.JPG.
checkdir error:  cannot create Sexta-feira de manh+�
                 Illegal byte sequence
                 unable to process Sexta-feira de manh+�/GOPR2779_1553588194000_high.JPG.
checkdir error:  cannot create Sexta-feira de manh+�
                 Illegal byte sequence
                 unable to process Sexta-feira de manh+�/GOPR2813_1553588196753_high.JPG.
checkdir error:  cannot create Sexta-feira de manh+�
                 Illegal byte sequence
                 unable to process Sexta-feira de manh+�/GOPR2771_1553588193350_high.JPG.
checkdir error:  cannot create Sexta-feira de manh+�
                 Illegal byte sequence
                 unable to process Sexta-feira de manh+�/GOPR2770_1553588193282_high.JPG.
checkdir error:  cannot create Sexta-feira de manh+�
                 Illegal byte sequence
                 unable to process Sexta-feira de manh+�/GOPR2734_1553287304192_high.JPG.
checkdir error:  cannot create Sexta-feira de manh+�
                 Illegal byte sequence
                 unable to process Sexta-feira de manh+�/GOPR2776_1553588193839_high.JPG.
checkdir error:  cannot create Sexta-feira de manh+�
                 Illegal byte sequence
                 unable to process Sexta-feira de manh+�/GOPR2811_1553588196578_high.JPG.
checkdir error:  cannot create Sexta-feira de manh+�
                 Illegal byte sequence
                 unable to process Sexta-feira de manh+�/GOPR2782_1553588194320_high.JPG.
checkdir error:  cannot create Sexta-feira de manh+�
                 Illegal byte sequence
                 unable to process Sexta-feira de manh+�/GOPR2732_1553287303926_high.JPG.
checkdir error:  cannot create Sexta-feira de manh+�
                 Illegal byte sequence
                 unable to process Sexta-feira de manh+�/GOPR2810_1553588196503_high.JPG.
checkdir error:  cannot create Sexta-feira de manh+�
                 Illegal byte sequence
                 unable to process Sexta-feira de manh+�/GOPR2774_1553588193500_high.JPG.
checkdir error:  cannot create Sexta-feira de manh+�
                 Illegal byte sequence
                 unable to process Sexta-feira de manh+�/GOPR2780_1553588194048_high.JPG.
checkdir error:  cannot create Sexta-feira de manh+�
                 Illegal byte sequence
                 unable to process Sexta-feira de manh+�/GOPR2795_1553588195371_high.JPG.
checkdir error:  cannot create Sexta-feira de manh+�
                 Illegal byte sequence
                 unable to process Sexta-feira de manh+�/GOPR2736_1553287304300_high.JPG.
checkdir error:  cannot create Sexta-feira de manh+�
                 Illegal byte sequence
                 unable to process Sexta-feira de manh+�/GOPR2808_1553588196356_high.JPG.
checkdir error:  cannot create Sexta-feira de manh+�
                 Illegal byte sequence
                 unable to process Sexta-feira de manh+�/GOPR2767_1553588193040_high.JPG.
checkdir error:  cannot create Sexta-feira de manh+�
                 Illegal byte sequence
                 unable to process Sexta-feira de manh+�/GOPR2817_1553588197051_high.MP4.

Um erro de utf-8 no MacOS.  O nome do álbum é "Sexta-feira de manhã".  É, faltou um pouco de criatividade aqui.  E o unzip no MacOS não consegue de jeito nenhum resolver isso.  Mais provavelmente por limitação do APFS, o filesystem da Apple (que não é lá grande coisa).

Buscando na Internet achei uma referência aqui: https://github.com/adamhathcock/sharpcompress/issues/315

Então basicamente eu usei o "ditto" pra resolver meu problema.

$ mkdir recuperação
$ cd recuperação/
$ ditto -V -x -k --sequesterRsrc --rsrc ../Sexta-feira\ de\ manhã-001.zip .
>>> Copying ../Sexta-feira de manhã-001.zip
copying file Sexta-feira de manhã/GOPR2787_1553588194745_high.JPG ...
467431 bytes for Sexta-feira de manhã/GOPR2787_1553588194745_high.JPG
copying file Sexta-feira de manhã/GOPR2815_1553588196860_high.JPG ...
510835 bytes for Sexta-feira de manhã/GOPR2815_1553588196860_high.JPG
copying file Sexta-feira de manhã/GOPR2733_1553287304138_high.JPG ...
761484 bytes for Sexta-feira de manhã/GOPR2733_1553287304138_high.JPG
copying file Sexta-feira de manhã/GOPR2765_1553588192848_high.JPG ...
468822 bytes for Sexta-feira de manhã/GOPR2765_1553588192848_high.JPG
copying file Sexta-feira de manhã/GOPR2805_1553588196125_high.JPG ...
787425 bytes for Sexta-feira de manhã/GOPR2805_1553588196125_high.JPG
copying file Sexta-feira de manhã/GOPR2766_1553588192990_high.JPG ...
1058611 bytes for Sexta-feira de manhã/GOPR2766_1553588192990_high.JPG
copying file Sexta-feira de manhã/GOPR2804_1553588196053_high.JPG ...
995234 bytes for Sexta-feira de manhã/GOPR2804_1553588196053_high.JPG
copying file Sexta-feira de manhã/GOPR2737_1553287304362_high.JPG ...
1011534 bytes for Sexta-feira de manhã/GOPR2737_1553287304362_high.JPG
copying file Sexta-feira de manhã/GOPR2816_1553588196891_high.JPG ...
511600 bytes for Sexta-feira de manhã/GOPR2816_1553588196891_high.JPG
copying file Sexta-feira de manhã/GOPR2772_1553588193399_high.JPG ...
823201 bytes for Sexta-feira de manhã/GOPR2772_1553588193399_high.JPG
copying file Sexta-feira de manhã/GOPR2789_1553588194826_high.JPG ...
822008 bytes for Sexta-feira de manhã/GOPR2789_1553588194826_high.JPG
copying file Sexta-feira de manhã/GOPR2792_1553588195166_high.JPG ...
1876322 bytes for Sexta-feira de manhã/GOPR2792_1553588195166_high.JPG
copying file Sexta-feira de manhã/GOPR2802_1553588195831_high.JPG ...
914018 bytes for Sexta-feira de manhã/GOPR2802_1553588195831_high.JPG
copying file Sexta-feira de manhã/GOPR2769_1553588193183_high.JPG ...
675609 bytes for Sexta-feira de manhã/GOPR2769_1553588193183_high.JPG
copying file Sexta-feira de manhã/GOPR2735_1553287304243_high.JPG ...
1699626 bytes for Sexta-feira de manhã/GOPR2735_1553287304243_high.JPG
copying file Sexta-feira de manhã/GOPR2764_1553588192788_high.JPG ...
2014672 bytes for Sexta-feira de manhã/GOPR2764_1553588192788_high.JPG
copying file Sexta-feira de manhã/GOPR2809_1553588196428_high.JPG ...
2000556 bytes for Sexta-feira de manhã/GOPR2809_1553588196428_high.JPG
copying file Sexta-feira de manhã/GOPR2793_1553588195213_high.JPG ...
988673 bytes for Sexta-feira de manhã/GOPR2793_1553588195213_high.JPG
copying file Sexta-feira de manhã/GOPR2781_1553588194244_high.JPG ...
2254617 bytes for Sexta-feira de manhã/GOPR2781_1553588194244_high.JPG
copying file Sexta-feira de manhã/GOPR2814_1553588196818_high.JPG ...
1815341 bytes for Sexta-feira de manhã/GOPR2814_1553588196818_high.JPG
copying file Sexta-feira de manhã/GOPR2785_1553588194565_high.JPG ...
2126053 bytes for Sexta-feira de manhã/GOPR2785_1553588194565_high.JPG
copying file Sexta-feira de manhã/GOPR2784_1553588194484_high.JPG ...
1961346 bytes for Sexta-feira de manhã/GOPR2784_1553588194484_high.JPG
copying file Sexta-feira de manhã/GOPR2812_1553588196668_high.JPG ...
1007050 bytes for Sexta-feira de manhã/GOPR2812_1553588196668_high.JPG
copying file Sexta-feira de manhã/GOPR2779_1553588194000_high.JPG ...
1612054 bytes for Sexta-feira de manhã/GOPR2779_1553588194000_high.JPG
copying file Sexta-feira de manhã/GOPR2813_1553588196753_high.JPG ...
2126066 bytes for Sexta-feira de manhã/GOPR2813_1553588196753_high.JPG
copying file Sexta-feira de manhã/GOPR2771_1553588193350_high.JPG ...
378743 bytes for Sexta-feira de manhã/GOPR2771_1553588193350_high.JPG
copying file Sexta-feira de manhã/GOPR2770_1553588193282_high.JPG ...
1995866 bytes for Sexta-feira de manhã/GOPR2770_1553588193282_high.JPG
copying file Sexta-feira de manhã/GOPR2734_1553287304192_high.JPG ...
1689565 bytes for Sexta-feira de manhã/GOPR2734_1553287304192_high.JPG
copying file Sexta-feira de manhã/GOPR2776_1553588193839_high.JPG ...
1793406 bytes for Sexta-feira de manhã/GOPR2776_1553588193839_high.JPG
copying file Sexta-feira de manhã/GOPR2811_1553588196578_high.JPG ...
2326771 bytes for Sexta-feira de manhã/GOPR2811_1553588196578_high.JPG
copying file Sexta-feira de manhã/GOPR2782_1553588194320_high.JPG ...
2258922 bytes for Sexta-feira de manhã/GOPR2782_1553588194320_high.JPG
copying file Sexta-feira de manhã/GOPR2732_1553287303926_high.JPG ...
2001698 bytes for Sexta-feira de manhã/GOPR2732_1553287303926_high.JPG
copying file Sexta-feira de manhã/GOPR2810_1553588196503_high.JPG ...
2709410 bytes for Sexta-feira de manhã/GOPR2810_1553588196503_high.JPG
copying file Sexta-feira de manhã/GOPR2774_1553588193500_high.JPG ...
2058495 bytes for Sexta-feira de manhã/GOPR2774_1553588193500_high.JPG
copying file Sexta-feira de manhã/GOPR2780_1553588194048_high.JPG ...
1882808 bytes for Sexta-feira de manhã/GOPR2780_1553588194048_high.JPG
copying file Sexta-feira de manhã/GOPR2795_1553588195371_high.JPG ...
2403193 bytes for Sexta-feira de manhã/GOPR2795_1553588195371_high.JPG
copying file Sexta-feira de manhã/GOPR2736_1553287304300_high.JPG ...
1576599 bytes for Sexta-feira de manhã/GOPR2736_1553287304300_high.JPG
copying file Sexta-feira de manhã/GOPR2808_1553588196356_high.JPG ...
2032676 bytes for Sexta-feira de manhã/GOPR2808_1553588196356_high.JPG
copying file Sexta-feira de manhã/GOPR2767_1553588193040_high.JPG ...
2080346 bytes for Sexta-feira de manhã/GOPR2767_1553588193040_high.JPG
copying file Sexta-feira de manhã/GOPR2817_1553588197051_high.MP4 ...
351123 bytes for Sexta-feira de manhã/GOPR2817_1553588197051_high.MP4

Nada muito simples, mas funciona e fica aqui registrado pra futura referência.

ditto -V -x -k --sequesterRsrc --rsrc arquivo.zip diretório_destino

Gerando vídeo de images jpeg com ffmpeg usando aceleração de hardware no MacOS

Details
Written by: Helio Loureiro
Category: MacOS/Darwin/BSD
Published: May 15, 2023
Hits: 2261
  • ffmpeg
  • Apple Silicon
  • aceleração de hardware
  • gopro

Eu já escrevi sobre isso em Linux com Intel (Usando a GPU para renderizar vídeo) e depois em Linux com NVIDIA (Renderizando as fotos da GoPro em vídeo mpeg4 com ffmpeg e NVIDIA).  Agora eu testei como fazer isso no MacOS.

E deu muito certo.

O comando e saída foram esses:

$ ffmpeg -r 1 -i G%04d.JPG -c:v h264_videotoolbox -b:v 5M -pix_fmt yuv420p output.mp4
ffmpeg version 6.0 Copyright (c) 2000-2023 the FFmpeg developers
  built with Apple clang version 14.0.3 (clang-1403.0.22.14.1)
  configuration: --prefix=/opt/homebrew/Cellar/ffmpeg/6.0 --enable-shared --enable-pthreads 
--enable-version3 --cc=clang --host-cflags= --host-ldflags= --enable-ffplay --enable-gnutls
--enable-gpl --enable-libaom --enable-libaribb24 --enable-libbluray --enable-libdav1d
--enable-libmp3lame --enable-libopus --enable-librav1e --enable-librist --enable-librubberband
--enable-libsnappy --enable-libsrt --enable-libsvtav1 --enable-libtesseract --enable-libtheora
--enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvpx --enable-libwebp
--enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-lzma
--enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass
--enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libspeex
--enable-libsoxr --enable-libzmq --enable-libzimg --disable-libjack --disable-indev=jack
--enable-videotoolbox --enable-neon libavutil 58. 2.100 / 58. 2.100 libavcodec 60. 3.100 / 60. 3.100 libavformat 60. 3.100 / 60. 3.100 libavdevice 60. 1.100 / 60. 1.100 libavfilter 9. 3.100 / 9. 3.100 libswscale 7. 1.100 / 7. 1.100 libswresample 4. 10.100 / 4. 10.100 libpostproc 57. 1.100 / 57. 1.100 Input #0, image2, from 'G%04d.JPG': Duration: 00:03:05.08, start: 0.000000, bitrate: N/A Stream #0:0: Video: mjpeg (Baseline), yuvj422p(pc, bt470bg/unknown/unknown), 4000x3000, 25 fps, 25 tbr, 25 tbn File 'output.mp4' already exists. Overwrite? [y/N] y Stream mapping: Stream #0:0 -> #0:0 (mjpeg (native) -> h264 (h264_videotoolbox)) Press [q] to stop, [?] for help [swscaler @ 0x130018000] deprecated pixel format used, make sure you did set range correctly [swscaler @ 0x128478000] deprecated pixel format used, make sure you did set range correctly [swscaler @ 0x138008000] deprecated pixel format used, make sure you did set range correctly [swscaler @ 0x108e58000] deprecated pixel format used, make sure you did set range correctly Output #0, mp4, to 'output.mp4': Metadata: encoder : Lavf60.3.100 Stream #0:0: Video: h264 (avc1 / 0x31637661), yuv420p(tv, bt470bg/unknown/unknown, progressive), 4000x3000, q=2-31, 5000 kb/s, 1 fps, 16384 tbn Metadata: encoder : Lavc60.3.100 h264_videotoolbox frame= 4627 fps= 21 q=-0.0 Lsize= 2824030kB time=01:17:06.00 bitrate=5001.0kbits/s speed=21.5x video:2823985kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.001582%

O que fez a mágica aqui foi o parâmetro "h264_videotoolbox".  Juntei 4626 imagens JPEG da última pedalada que fizemos em um vídeo de pouco mais de 1 hora.  E agora vou trabalhar em cima pra fazer o vídeo no formato adequado, trilha sonora e tamanho menor.

pycurl no MacOS

Details
Written by: Helio Loureiro
Category: MacOS/Darwin/BSD
Published: December 16, 2022
Hits: 1587
  • python
  • curl
  • pycurl
  • macos

Tive de trabalhar nessa semana com um caso que me exigiu usar o pycurl no Python.  O problema foi que escrevi um script que rodava baixando artefatos de build no Jenkins usando o módulo requests, e o mesmo não funcionava mais no Gitlab.

Depois de gastar um pouco de tempo no request, e usando o curl do exemplo do site do Gitlab, eu acabei desistindo e indo pra usar o pycurl no script.  De cara descobri que não tinha pycurl instalado.  E no MacOS não foi tão simples como poderia ter sido.  A receita de bolo pra instalar o pycurl foi a seguinte sequência:

helio@MacOS> arch -arm64 brew install openssl curl
helio@MacOS> export PATH=/opt/homebrew/opt/curl/bin:$PATH
helio@MacOS> export LDFLAGS="-L/opt/homebrew/opt/curl/lib":$LDFLAGS
helio@MacOS> export CPPFLAGS="-I/opt/homebrew/opt/curl/include":$CPPFLAGS
helio@MacOS> arch -arm64 pip install --no-cache-dir --compile --ignore-installed --install-option="--with-openssl" --install-option="--openssl-dir=/opt/homebrew/Cellar/openssl@3/3.0.7" pycurl 

Quando algo funciona em curl é fácil escrever o código em python.  Basta rodar com o parâmetro --libcurl foo.c que ele joga o código em funcionou dentro do arquivo.c no formato pra linguagem C, mas é bem próximo do uso em python.

   hnd = curl_easy_init();
  curl_easy_setopt(hnd, CURLOPT_BUFFERSIZE, 102400L);
  curl_easy_setopt(hnd, CURLOPT_URL, "https://gitlab.[redacted]/api/v4/projects/[redacted]/jobs/[redacted]/artifacts");
  curl_easy_setopt(hnd, CURLOPT_NOPROGRESS, 1L);
  curl_easy_setopt(hnd, CURLOPT_HTTPHEADER, slist1);
  curl_easy_setopt(hnd, CURLOPT_USERAGENT, "curl/7.86.0");
  curl_easy_setopt(hnd, CURLOPT_FOLLOWLOCATION, 1L);
  curl_easy_setopt(hnd, CURLOPT_MAXREDIRS, 50L);
  curl_easy_setopt(hnd, CURLOPT_HTTP_VERSION, (long)CURL_HTTP_VERSION_2TLS);
  curl_easy_setopt(hnd, CURLOPT_FTP_SKIP_PASV_IP, 1L);
  curl_easy_setopt(hnd, CURLOPT_TCP_KEEPALIVE, 1L);

Em python:

             url = "https://gitlab.[redacted]/api/v4/projects/[redacted]/jobs/[redacted]/artifacts"
             buffer = BytesIO()
            c = pycurl.Curl()
            c.setopt(c.URL, url)
            c.setopt(c.BUFFERSIZE, 102400)
            c.setopt(c.NOPROGRESS, 1)
            if GITLAB_PRIVATE_TOKEN:
                c.setopt(c.HTTPHEADER, [ "PRIVATE-TOKEN:" + GITLAB_PRIVATE_TOKEN ])
            else:
                c.setopt(c.HTTPHEADER, [ USERNAME + ":" + PASSWORD])
            c.setopt(c.USERAGENT, "curl/7.84.0")
            c.setopt(c.FOLLOWLOCATION, 1)
            c.setopt(c.HTTP_VERSION, c.CURL_HTTP_VERSION_2TLS)
            c.setopt(c.TCP_KEEPALIVE, 1)
            c.setopt(c.WRITEDATA, buffer)
            c.perform()
            c.close()

E assim o código saiu funcionando.

Remapeando a tecla ± do MacBook Pro

Details
Written by: Helio Loureiro
Category: MacOS/Darwin/BSD
Published: November 26, 2022
Hits: 1717

Por algum motivo bizarro, a Apple inclui essa tecla esquisita no teclado de seus notebooks.  Tenho no MacBook Pro que uso, mas já vi que é a mesma coisa em outro modelos como o MacBook Air.  Como eu uso boa parte do tempo em casa, onde tenho um teclado mecânico, quase nunca percebo o problema dessa tecla alienígena instalada.  Mas basta eu trabalhar só no laptop em hackathons e outros eventos pra começarem os problemas.  Principalmente quando vou mexer no shell e passar o "~" pra usar como abreviação do HOME.

Hoje, um dos raros dias que faço isso, resolvi mexer no laptop na sala pra assistir à copa do mundo e acertar algumas coisas no raspberrypi.  Além de escrever pro blog aqui.  Eis que o raio da tecla "~" faz falta.  Mas dessa vez resolvi buscar alguma solução na Internet.  E achei!

https://apple.stackexchange.com/questions/281405/easy-way-to-remap-non-modifier-keys-on-mac

Basicamente é rodar o seguinte comando:

MacOS@helio> hidutil property --set '{"UserKeyMapping":
   [{"HIDKeyboardModifierMappingSrc":0x700000035,
      "HIDKeyboardModifierMappingDst":0x700000064},
     {"HIDKeyboardModifierMappingSrc":0x700000064,
      "HIDKeyboardModifierMappingDst":0x700000035}]
}'

Isso já configura a tecla corretamente. E pra iniciar durante o boot, criar o arquivo ~/Library/LaunchAgents/com.user.loginscript.plist com o seguinte conteúdo:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>com.user.loginscript</string>
    <key>ProgramArguments</key>
    <array>
        <string>/usr/bin/hidutil</string>
        <string>property</string>
        <string>--set</string>
        <string>{"UserKeyMapping":[{"HIDKeyboardModifierMappingSrc":0x700000035, "HIDKeyboardModifierMappingDst":0x700000064}, {"HIDKeyboardModifierMappingSrc":0x700000064, "HIDKeyboardModifierMappingDst":0x700000035}]}</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
</dict>
</plist>

E chamar na inicialização assim:

MacOS@helio> launchctl load ~/Library/LaunchAgents/com.user.loginscript.plist

E pronto! Tecla funcional.  Agradeço de coração quem deu essa resposta maravilhosa no stack exchange.

UPDATE:  Sun Nov 27 19:27:29 CET 2022

Quando fui usar o laptop conectado no teclado externo, tive a triste verificação de que os comandos acima troca uma tecla pela outra, o que é altamente indesejado.  O que eu quero é mesmo sumir com a tecla do "±" que não uso.

Pra isso eu precisei modificar o comando anterior para:

MacOS@helio> hidutil property --set '{"UserKeyMapping":
   [{"HIDKeyboardModifierMappingSrc":0x700000064,
      "HIDKeyboardModifierMappingDst":0x700000035}]
}'

E o mesmo pra ~/Library/LaunchAgents/com.user.loginscript.plist:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>com.user.loginscript</string>
    <key>ProgramArguments</key>
    <array>
        <string>/usr/bin/hidutil</string>
        <string>property</string>
        <string>--set</string>
        <string>{"UserKeyMapping":[{"HIDKeyboardModifierMappingSrc":0x700000064, "HIDKeyboardModifierMappingDst":0x700000035}]}</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
</dict>
</plist>

E agora tenho a tecla "~" em ambos os teclados.  Precisei dar um "reload" no launchctl pro caso do teclado:

MacOS@helio> launchctl unload ~/Library/LaunchAgents/com.user.loginscript.plist
MacOS@helio> launchctl load ~/Library/LaunchAgents/com.user.loginscript.plist

Corrigindo o problema de fontes pequenas no Firefox

Details
Written by: Helio Loureiro
Category: MacOS/Darwin/BSD
Published: October 27, 2022
Hits: 1680

Página do firefox com imagem pequena

Esse problema já vinha arrastando-se por algum tempo.  Desde que peguei o MacBook.  Quando eu trabalhava com um display externo, o Firefox ficava com a fonte normal.  Mas bastava eu usar somente o laptop pra ele ficar ridiculamente pequeno.  Como pode ser visto na image, o texto é legível, mas a barra do Firefox é impossível.  E em alguns sites específicos eu precisava ficar aumentando o zoom pra conseguir ler o texto.

No Macos eu já tinha configurado pra usar uma resolução não tão alta pra justamente não ficar com tudo ridiculamente pequeno na tela (eu particularmente odeio isso).

Tela do Macos com a resolução utilizada.

Mas o Firefox sempre teimava em não seguir a configuração.  E o difícil era... buscar um solução já que eu não sabia qual o problema exatamente.  Tentei "firefox small fonts", "firefox small resolution" e por aí seguiu minha busca.  Sem infrutífera.  Até que hoje eu resolvi buscar por "hidpi" e... bingo!

Basta entrar na configuração do Firefox com "about:config" e alterar o parâmetro "layout.css.devPixelsPerPx".  Só pra ter uma ideia de como estava antes:

Configuração do Firefox com parâmetro como 1 mostrando fonte pequena.

e como ficou depois, só mudando de 1 pra 1.5.

Configuração do Firefox com o parâmetro alterado pra 1.5 e mostrando as fontes bem mais legíveis.

agora sim consigo usar apenas o laptop pra trabalhar.

  1. Rodando programas do KDE no Macos
  2. Containers e trabalhando com Linux x86_64 no Mac
  3. Virei Maconhero
  4. Discurso de Steve Jobs em Stanford

Page 1 of 3

  • 1
  • 2
  • 3

Estatísticas

  • Users 2
  • Articles 460
  • Articles View Hits 3252666

Imagem aleatória