-
Notifications
You must be signed in to change notification settings - Fork 0
/
set_default_app.sh
executable file
·74 lines (66 loc) · 2.11 KB
/
set_default_app.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/bin/bash
# Bundle Identifiers
# For example:
# mdls -name kMDItemCFBundleIdentifier /System/Applications/Books.app
# Get all bundle identifiers in /Applications
# lsappinfo list | rg --multiline '("[^"]*?") ASN:.*\n.*bundleID=("[^"]*?")' --replace '$1 $2' --only-matching
# System-Declared Uniform Type Identifiers
# https://developer.apple.com/library/archive/documentation/Miscellaneous/Reference/UTIRef/Articles/System-DeclaredUniformTypeIdentifiers.html#//apple_ref/doc/uid/TP40009259
# 检查 duti 是否安装
if ! command -v duti &> /dev/null; then
echo "duti 未安装。请先安装 duti。"
exit 1
fi
# 设置文件类型与应用程序的关联
fileAssociations=(
# 图片文件
"com.interversehq.qView jpg"
"com.interversehq.qView jpeg"
"com.interversehq.qView png"
"com.interversehq.qView gif"
"com.interversehq.qView tiff"
"com.interversehq.qView bmp"
"com.interversehq.qView heic"
# 视频文件
"com.colliderli.iina mov"
"com.colliderli.iina mp4"
"com.colliderli.iina avi"
"com.colliderli.iina mkv"
"com.colliderli.iina m4v"
# 文本文件
"com.microsoft.VSCode txt"
"com.microsoft.VSCode xml"
"com.microsoft.VSCode opml"
"com.microsoft.VSCode json"
"com.microsoft.VSCode html"
"com.microsoft.VSCode css"
"com.microsoft.VSCode js"
"com.microsoft.VSCode ts"
"com.microsoft.VSCode tsx"
"com.microsoft.VSCode pub"
"abnerworks.Typora md"
"com.microsoft.Excel xls"
"com.microsoft.Excel xlsx"
# PDF 文件
"com.apple.iBooksX pdf"
)
# 错误日志
errors=()
# 应用设置
for association in "${fileAssociations[@]}"; do
app=$(echo "$association" | awk '{print $1}')
ext=$(echo "$association" | awk '{print $2}')
if ! duti -s "$app" "$ext" all; then
errors+=("设置 $ext 类型的默认应用程序为 $app 失败。")
fi
done
# 输出错误日志
if [ ${#errors[@]} -ne 0 ]; then
echo "以下文件类型的默认应用程序设置失败:"
for error in "${errors[@]}"; do
echo "$error"
done
exit 1
else
echo "默认应用程序全部设置成功。"
fi