Skip to content

Commit

Permalink
[add] Mac note
Browse files Browse the repository at this point in the history
  • Loading branch information
AIboy996 committed May 27, 2024
1 parent 9ac0db0 commit 343cab4
Show file tree
Hide file tree
Showing 13 changed files with 158 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docs/Blog/2024/fudan.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ include:

<figure markdown>

![](assets/2024-05-26-14-20-13.png){width=500}
![](/Blog/2024/assets/2024-05-26-14-20-13.png){width=500}

<figurecaption>
把这张纸翻出来废了我老大劲,不过确实很有纪念意义
Expand Down
Binary file added docs/Note/Mac/assets/2024-05-27-14-40-09.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/Note/Mac/assets/2024-05-27-14-41-35.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/Note/Mac/assets/2024-05-27-14-46-33.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/Note/Mac/assets/2024-05-27-14-54-32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/Note/Mac/assets/2024-05-27.mov
Binary file not shown.
Binary file added docs/Note/Mac/assets/terminal.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
36 changes: 36 additions & 0 deletions docs/Note/Mac/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
tags:
- Mac
---

# 人生苦短,我用Mac

这系列的note打算写一写我的Mac软件配置,包括但不限于:

- [终端配置](./zsh)(iTerm2+zsh)
- [菜单栏配置](./sketchybar)(sketchybar+yabai)

相关的配置文件保存在我的[dotfiles仓库](https://github.com/AIboy996/dotfiles)

??? question "Ask GPT: 什么是dotfiles?"
Dotfiles 是一种用来配置和定制操作系统环境和各种应用程序的配置文件的统称。这些文件通常是隐藏文件,文件名以点号 (".") 开头,因此被称为 "dotfiles"。这些文件一般位于用户的主目录中,例如 `~/.bashrc``~/.vimrc``~/.gitconfig` 等。

以下是一些常见的 dotfiles 及其用途:

1. **`.bashrc`** 或 **`.bash_profile`**:用于配置 Bash shell 的启动和运行行为。可以在其中设置环境变量、别名、函数等。

2. **`.vimrc`**:用于配置 Vim 文本编辑器的行为和外观。可以在其中设置键绑定、颜色方案、插件等。

3. **`.gitconfig`**:用于配置 Git 版本控制系统的全局设置,例如用户名、电子邮件、别名、差异工具等。

4. **`.zshrc`**:用于配置 Zsh shell 的启动和运行行为,类似于 `.bashrc`,但用于 Zsh。

5. **`.tmux.conf`**:用于配置 tmux 终端复用器的行为和外观。

这些 dotfiles 的目的是让用户能够自定义他们的工作环境,使其更加符合个人习惯和需求。许多开发者会将他们的 dotfiles 进行版本控制,通常使用 Git 来管理这些文件,并将其托管在 GitHub 等代码托管平台上。这样可以方便地在不同设备之间同步配置,并与他人分享自己的配置方案。

在管理 dotfiles 时,通常会使用一些工具和技巧来提高效率,例如:
- **GNU Stow**:一个符号链接管理器,可以用来简化 dotfiles 的组织和部署。
- **Bare Git Repositories**:使用裸 Git 仓库直接在主目录中管理 dotfiles。

通过这些方法,用户可以方便地备份、恢复和分享他们的环境配置。
85 changes: 85 additions & 0 deletions docs/Note/Mac/sketchybar.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
---
tags:
- Mac
- 折腾
---

# sketchybar+yabai
> 相关的配置文件保存在我的[dotfiles仓库](https://github.com/AIboy996/dotfiles)
使用sketchybar+yabai来替代mac原生的菜单栏:

![type:video](./assets/2024-05-27.mov)

主要功能:

- 显示各个Desktop Spaces在运行的窗口(使用yabai实现)
- 点击的时候切换到对应的Space(使用osacript实现)
- 显示当前激活的窗口
- 显示其他自定义内容
- 微信、QQ通知
- 电池
- 日期

软件的安装、启动没啥好说的。跟着官方的教程走就行了。

安装完之后可以设置Mac内置的菜单栏在桌面视图自动隐藏:
![](assets/2024-05-27-14-54-32.png)

## 桌面切换(yabai)
值得一提的是,yabai虽然功能很强大,但是想要实现**切换Desktop Space**的功能需要配置Scripts Addition。

而想要开启这个SA功能个首先需要关闭MacOS的System Integrity Protection,然后才可以:
> yabai uses the macOS Mach APIs to **inject code** into Dock.app; this requires elevated (root) privileges. You can configure your user to execute yabai --load-sa as the root user without having to enter a password. To do this, we add a new configuration entry that is loaded by /etc/sudoers.
看起来就是一个非常危险的操作,我不太愿意这么干。

## 桌面切换(osascript)
所以我寻找了一个替代方案:osascript,这是Mac自带的脚本工具。

> osascript – execute OSA scripts (AppleScript, JavaScript, etc.)
### 开启快捷键
首先,需要开启桌面切换的快捷键:

![](assets/2024-05-27-14-40-09.png)

### 给予权限

其次需要在辅助功能里打开权限(否则osascript无法模拟键盘快捷键):

![](assets/2024-05-27-14-41-35.png)

- AEServer:AppEvent Server
- brew:我的sketchybar是使用`brew services start sketchybar`启动的。
- iTerm2:我用的终端
- osascript:脚本运行软件

### 添加脚本

最后我们可以在sketchybar的配置文件里添加鼠标点击事件的回调函数:

> 这个功能原来是用yabai实现的。
```sh hl_lines="9" title="sketchybar/plugins/space.sh"
mouse_clicked() {
if [ "$BUTTON" = "right" ]; then
# yabai -m space --destroy $SID
sketchybar --trigger windows_on_spaces --trigger space_change
else
# yabai -m space --focus $SID 2>/dev/null
# https://eastmanreference.com/complete-list-of-applescript-key-codes
# simulate control+18, 19, 20
osascript -e "tell application \"System Events\" to key code $((SID+17)) using control down"
fi
}
```

最重要的一行就是一句AppleScript,用来模拟键盘按下特定的快捷键(例如++ctrl+1++):
```sh
osascript -e "tell application \"System Events\" to key code $((SID+17)) using control down"
```

> `key code 18`对应数字键1,更多对应关系如下:
![](assets/2024-05-27-14-46-33.png)
21 changes: 21 additions & 0 deletions docs/Note/Mac/zsh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
tags:
- Mac
- 折腾
- Shell
---

# iTerm2+zsh
> 相关的配置文件保存在我的[dotfiles仓库](https://github.com/AIboy996/dotfiles)
zsh是Mac默认的Shell,对我已经足够好用。iTerm2则比Mac自带的Terminal要好用的多。我使用的zsh主题是[powerlevel10k](https://github.com/romkatv/powerlevel10k),主打一个简洁:

![](./assets/terminal.gif){.nonzoom}

我还安装了很多终端工具,包括但不限于:

- [homebrew](https://brew.sh/)(Mac包管理器)
- [zoxide](https://github.com/ajeetdsouza/zoxide)(cd的上位替代)
- [neofetch](https://github.com/dylanaraps/neofetch)(显示系统信息)
- [trans-shell](https://github.com/Freed-Wu/translate-shell)(命令行翻译工具)
- ...
7 changes: 7 additions & 0 deletions docs/Note/NAS/domain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
tags:
- NAS
- 折腾
---

# 域名两三事
5 changes: 5 additions & 0 deletions nav.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ nav:
- Note/Shell/linux.md
- Note/Shell/man.md
- Note/Shell/ssh.md
- Mac:
- Note/Mac/index.md
- Note/Mac/zsh.md
- Note/Mac/sketchybar.md
- ManimGL:
- Note/manim/hello.md
- MkDocs:
Expand All @@ -49,6 +53,7 @@ nav:
- Note/mkdocs/plugin_dev.md
- NAS:
- Note/NAS/media.md
- Note/NAS/domain.md
- NintendoSwitch:
- Note/NS/crack.md
- Note/NS/stream.md
Expand Down
4 changes: 3 additions & 1 deletion plugins_simplify.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# 只加载一个插件,提高编译速度
plugins:
- tags
- tags
- mkdocs-video:
is_video: true

0 comments on commit 343cab4

Please sign in to comment.