9篇 macos related articles

macos上的启动项管理

守护进程目录

/System/Library/LaunchDaemons/
/Library/LaunchDaemons/

启动项Agent目录

/System/Library/LaunchAgents
/Library/LaunchAgents
~/Library/LaunchAgents
More ~

macos 上查看端口占用

使用命令lsof即可。
lsof -i :3306

lsof -i :3306
COMMAND PID   USER   FD   TYPE            DEVICE SIZE/OFF NODE NAME
mysqld  773 hijack   32u  IPv4 0x5273dd7b96798a1      0t0  TCP localhost:mysql (LISTEN)

也可以指定tcp 如lsof -i tcp:3306

More ~

旧款macbook升级到macOS Catalina 10.15

我的macbook是2011款,曾经换成固态硬盘,内存从2Gx2升到2G+8G,现在基本上还能应付一般开发。
10.14开始就已经不支持这台2011年款macbook。不过也是从某个网站下的patch工具,将10.14的镜像打上补丁可以升级上来。
Screen Shot 2019-10-09 at 23.54.01.png

10.15也有这样的工具,将macOS Catalina的镜像打上补丁支持旧款macbook. 这个工具网站http://dosdude1.com/catalina/

先查这个再看兼容列表是否支持。
Screen Shot 2019-10-10 at 00.12.59.png

More ~

MacOS app renders blank screen with WKWebView

I'm not sure there are differences of WKWebView usage between iOS app and MacOS app. There I have an issue that a web view on the storyboard can not load a request. Typically there is always the white screen, implies nothing loads.

Finally, I found the solution here. In the Capabilities tab of the project target, it's App Sandbox, check the Network: Outgoing Connections (Client).

Screen Shot 2019-07-25 at 22.28.10.png

More ~

在mac命令行执行显示通知

需要用的工具:
osascript在macos上可以执行AppleScript, JavaScript等.
这里介绍AppleScript两个常用命令: display, say.

display

这个命令可以在mac上发送系统通知,macos 会在侧边栏显示这个通知消息。
AppleStript这样写 display notification "hello world!"

为了执行这条命令需要用到osascript, 并且需要-e参数,后面跟的单引号字符引用的命令
执行发送这条通知:
osascript -e 'display notification "hello world!"'

Screen Shot 2019-07-17 at 12.31.58.png

这条通知显示在屏幕右上角,3秒后消失。

More ~

shell tree in macos

Use find to list the current folder:

find . -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g'

Add to ~/.bash_profile or ~/.zshrc
alias tree="find . -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g'"
  

Or install the tree with brew
brew install tree

More ~