Skip to content

搞英语 → 看世界

翻译英文优质信息和名人推特

Menu
  • 首页
  • 作者列表
  • 独立博客
  • 专业媒体
  • 名人推特
  • 邮件列表
  • 关于本站
Menu

智能菜单栏管理:使用 Bartender 根据屏幕设置调整图标

Posted on 2025-10-08

今天,我听了 Apptories 的最新一期:“实用工具大全回归”。 @viticci想知道如何根据当前屏幕显示或隐藏菜单栏中的图标。以下是我使用 Bartender 的操作方法:当我只使用 MacBook Pro 屏幕时隐藏图标,而当我在家或工作时使用大屏幕时显示所有图标。

免责声明

由于不太熟悉硬件相关的 Bash 脚本,我承认这些脚本是在人工智能的帮助下生成的。但它确实帮我完成了工作。可能仍然存在一些错误,可能需要进行一些调整。

触发因素

我有两个触发器:一个用于检测是否只有 MacBook Pro 屏幕处于活动状态,另一个用于检测是否有其他屏幕连接到计算机。

如果仅使用 MacBook Pro 屏幕,则检测脚本。

 #!/bin/zsh # Script to detect if ONLY the built-in MacBook Pro screen is being used # Returns "true" if only the built-in screen is active, "false" if an external monitor is connected # Get complete information about the screens DISPLAY_INFO=$(system_profiler SPDisplaysDataType 2>/dev/null) # Count the total number of active screens ACTIVE_DISPLAYS=$(echo "$DISPLAY_INFO" | grep -c "Resolution:") # Count internal screens INTERNAL_DISPLAYS=$(echo "$DISPLAY_INFO" | grep -c "Connection Type: Internal") # Check if ONLY the built-in screen is being used if [[ $ACTIVE_DISPLAYS -eq 1 ]] && [[ $INTERNAL_DISPLAYS -eq 1 ]]; then echo "true" exit 0 else echo "false" exit 1 fi

如果连接了附加屏幕,则检测脚本。

 #!/bin/zsh # Script to detect if an external screen is being used # Returns "true" if at least one external screen is being used, "false" otherwise # Get complete information about the screens DISPLAY_INFO=$(system_profiler SPDisplaysDataType 2>/dev/null) # Count the total number of active screens ACTIVE_DISPLAYS=$(echo "$DISPLAY_INFO" | grep -c "Resolution:") # Count internal screens INTERNAL_DISPLAYS=$(echo "$DISPLAY_INFO" | grep -c "Connection Type: Internal") # Calculate the number of external screens (total - internal) EXTERNAL_DISPLAYS=$((ACTIVE_DISPLAYS - INTERNAL_DISPLAYS)) # For debugging (comment these lines for normal use) # echo "ACTIVE_DISPLAYS: $ACTIVE_DISPLAYS" # echo "INTERNAL_DISPLAYS: $INTERNAL_DISPLAYS" # echo "EXTERNAL_DISPLAYS: $EXTERNAL_DISPLAYS" # Check if at least one external screen is being used if [[ $EXTERNAL_DISPLAYS -gt 0 ]]; then echo "true" exit 0 else echo "false" exit 1 fi

预设

上面提到的两个脚本会根据屏幕是否连接来激活两个预设。一个预设我称之为“小屏幕”,它会隐藏所有图标;另一个预设我称之为“大屏幕”,它会默认显示所有内容。

原文: http://alienlebarge.ch/articles/smart-menu-bar-management-adapting-icons-based-on-your-screen-setup-with-bartender

本站文章系自动翻译,站长会周期检查,如果有不当内容,请点此留言,非常感谢。
  • Abhinav
  • Abigail Pain
  • Adam Fortuna
  • Alberto Gallego
  • Alex Wlchan
  • Anil Dash
  • Answer.AI
  • Arne Bahlo
  • Ben Carlson
  • Ben Kuhn
  • Bert Hubert
  • Big Technology
  • Bits about Money
  • Brandon Skerritt
  • Brian Krebs
  • ByteByteGo
  • Chip Huyen
  • Chips and Cheese
  • Christopher Butler
  • Colin Percival
  • Cool Infographics
  • Dan Sinker
  • David Walsh
  • Dmitry Dolzhenko
  • Dustin Curtis
  • eighty twenty
  • Elad Gil
  • Ellie Huxtable
  • Ethan Dalool
  • Ethan Marcotte
  • Exponential View
  • FAIL Blog
  • Founder Weekly
  • Geoffrey Huntley
  • Geoffrey Litt
  • Greg Mankiw
  • HeardThat Blog
  • Henrique Dias
  • Herman Martinus
  • Hypercritical
  • IEEE Spectrum
  • Investment Talk
  • Jaz
  • Jeff Geerling
  • Jonas Hietala
  • Josh Comeau
  • Lenny Rachitsky
  • Li Haoyi
  • Liz Danzico
  • Lou Plummer
  • Luke Wroblewski
  • Maggie Appleton
  • Matt Baer
  • Matt Stoller
  • Matthias Endler
  • Mert Bulan
  • Mind Matters
  • Mostly metrics
  • Naval Ravikant
  • News Letter
  • NextDraft
  • Non_Interactive
  • Not Boring
  • One Useful Thing
  • Phil Eaton
  • Product Market Fit
  • Readwise
  • ReedyBear
  • Robert Heaton
  • Rohit Patel
  • Ruben Schade
  • Sage Economics
  • Sam Altman
  • Sam Rose
  • selfh.st
  • Shtetl-Optimized
  • Simon schreibt
  • Slashdot
  • Small Good Things
  • Steph Ango
  • Stephen Wolfram
  • Steve Blank
  • Taylor Troesh
  • Telegram Blog
  • The Macro Compass
  • The Pomp Letter
  • thesephist
  • Thinking Deep & Wide
  • Tim Kellogg
  • Understanding AI
  • Wes Kao
  • 英文媒体
  • 英文推特
  • 英文独立博客
©2025 搞英语 → 看世界 | Design: Newspaperly WordPress Theme