如何恢复被 WPS for Mac 篡改的所有文件关联

前情提要

为了使用金山文档,我安装了 WPS for Mac,结果安装下来的一瞬间,就把我所有能改文件关联都改到 WPS 身上了,即使我的 Mac 已经装有 Microsoft Office for Mac 了。

开始操作

想让我一个一个改回文件关联?万一 WPS 某次升级又偷偷给你改回来了那我不是前功尽弃了吗。

这是国产软件中最恶心的部分,人家想恶心你很容易,而你想要补救却要费很大劲。我要不是需要金山文档与同事们写作编辑一些文档,不然我都不会安装 WPS for Mac 的,这次吃一堑长一智了,下次我去使用飞书去吧!

首先我们需要安装一个叫 Duti 的命令行工具,需要使用到 Homebrew:

brew install duti

假设你在使用 zsh(或者没有对 macOS 原生的终端做过任何其他改动),执行下列命令即可将文件关联改回 Microsoft Office。

# =========================
# Word
# =========================
WORD="com.microsoft.Word"

for uti in \
  com.microsoft.word.doc \
  org.openxmlformats.wordprocessingml.document \
  cn.wps.docx.text \
  com.microsoft.word.dot \
  cn.wps.dotx.text \
  org.openxmlformats.wordprocessingml.template \
  cn.wps.docm.text \
  org.openxmlformats.wordprocessingml.document.macroenabled \
  org.openxmlformats.wordprocessingml.template.macroenabled \
  cn.wps.dotm.text \
  com.microsoft.word.mhtml \
  public.rtf
do
  duti -s "$WORD" "$uti" all
done


# =========================
# Excel
# =========================
EXCEL="com.microsoft.Excel"

for uti in \
  public.comma-separated-values-text \
  com.microsoft.excel.space-separated-values-text \
  com.microsoft.excel.xls.biff2 \
  com.microsoft.excel.xls.stationery.biff3 \
  com.microsoft.excel.xls.biff4 \
  com.microsoft.excel.xls.stationery.biff5 \
  com.microsoft.excel.xls.biff5 \
  com.microsoft.excel.xlt \
  org.openxmlformats.spreadsheetml.template.macroenabled \
  com.microsoft.excel.openxmlformats.spreadsheetml.template.macroenabled \
  org.openxmlformats.spreadsheetml.sheet.macroenabled \
  com.microsoft.excel.openxmlformats.spreadsheetml.sheet.macroenabled \
  org.openxmlformats.spreadsheetml.template \
  com.microsoft.excel.openxmlformats.spreadsheetml.template \
  com.microsoft.excel.xls \
  org.openxmlformats.spreadsheetml.sheet \
  com.microsoft.excel.openxmlformats.spreadsheetml.sheet
do
  duti -s "$EXCEL" "$uti" all
done


# =========================
# PowerPoint
# =========================
POWERPOINT="com.microsoft.Powerpoint"

for uti in \
  org.openxmlformats.presentationml.slideshow.macroenabled \
  com.microsoft.powerpoint.openxmlformats.presentationml.slideshow.macroenabled \
  org.openxmlformats.presentationml.template.macroenabled \
  com.microsoft.powerpoint.openxmlformats.presentationml.template.macroenabled \
  org.openxmlformats.presentationml.presentation.macroenabled \
  com.microsoft.powerpoint.openxmlformats.presentationml.presentation.macroenabled \
  com.microsoft.powerpoint.pps \
  org.openxmlformats.presentationml.slideshow \
  com.microsoft.powerpoint.openxmlformats.presentationml.slideshow \
  com.microsoft.powerpoint.pot \
  org.openxmlformats.presentationml.template \
  com.microsoft.powerpoint.openxmlformats.presentationml.template \
  com.microsoft.powerpoint.ppt \
  org.openxmlformats.presentationml.presentation \
  com.microsoft.powerpoint.openxmlformats.presentationml.presentation
do
  duti -s "$POWERPOINT" "$uti" all
done


# =========================
# PDF -> Preview
# =========================
duti -s com.apple.Preview com.adobe.pdf all


# =========================
# Mail -> Apple Mail
# =========================
duti -s com.apple.mail com.apple.mail.email all


# =========================
# ZIP -> Archive Utility
# =========================
duti -s com.apple.archiveutility com.pkware.zip-archive all


# =========================
# TXT / XML / HTML -> TextEdit
# =========================
duti -s com.apple.TextEdit public.plain-text all
duti -s com.apple.TextEdit public.xml all
duti -s com.apple.TextEdit public.html all

上面的指令覆盖了大部分办公文档格式,但是 WPS 实际上还修改了 7z、Markdown 之类的文件格式,这个仍需自行修改一下

总结

要避免出现这种恶劣的情况,最好的办法是不使用 WPS。

例如我的情况,我正是用 WPS 下的金山文档功能来做多人协作的,下次就可以试着去用飞书文档了。