将脚本添加到MacOS Finder上下文菜单的方法如下:
my_script.sh
,并将其保存在/Users/your_username/scripts
文件夹中。~/Library/Services
,然后按下回车键。~/Library/Services
文件夹中,创建一个名为My Script.workflow
的新文件夹。My Script.workflow
文件夹中,创建一个名为Contents
的新文件夹。Contents
文件夹中,创建一个名为Info.plist
的新文件,并将以下代码粘贴到其中:<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
<string>run_script</string>
<key>CFBundleIdentifier</key>
<string>com.apple.Automator.MyScript</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>My Script</string>
<key>CFBundlePackageType</key>
<string>WFLW</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2022. All rights reserved.</string>
<key>NSMainNibFile</key>
<string>ScriptMenu</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
<key>WFWorkflowActions</key>
<array>
<dict>
<key>WFWorkflowActionIdentifier</key>
<string>is.workflow.actions.runscript</string>
<key>WFWorkflowActionParameters</key>
<dict>
<key>WFScript</key>
<data>
<![CDATA[
#!/bin/bash
/Users/your_username/scripts/my_script.sh
]]>
</data>
<key>WFScriptInterpreter</key>
<string>/bin/bash</string>
</dict>
</dict>
</array>
</dict>
</plist>
Contents
文件夹中,创建一个名为ScriptMenu.nib
的新文件。/Users/your_username/scripts/my_script.sh
,将“通过输入”设置为“无”,将“通过输出”设置为“无”。~/Library/Services/My Script.workflow
文件夹中。ScriptMenu.nib
。现在,当您在Finder中右键单击文件或文件夹时,应该会看到一个名为“My Script”的新选项。单击该选项将运行您的脚本。
领取专属 10元无门槛券
手把手带您无忧上云