首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

将脚本添加到MacOS Finder上下文菜单

将脚本添加到MacOS Finder上下文菜单的方法如下:

  1. 创建一个脚本文件,例如my_script.sh,并将其保存在/Users/your_username/scripts文件夹中。
  2. 打开Finder,然后选择“前往”>“前往文件夹”,输入~/Library/Services,然后按下回车键。
  3. ~/Library/Services文件夹中,创建一个名为My Script.workflow的新文件夹。
  4. My Script.workflow文件夹中,创建一个名为Contents的新文件夹。
  5. Contents文件夹中,创建一个名为Info.plist的新文件,并将以下代码粘贴到其中:
代码语言:xml
复制
<?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>
  1. Contents文件夹中,创建一个名为ScriptMenu.nib的新文件。
  2. 打开Automator应用程序,然后选择“文件”>“新建”>“服务”。
  3. 在Automator中,将“运行脚本”操作拖放到右侧的工作流程区域中。
  4. 在“运行脚本”操作中,将“脚本内容”设置为/Users/your_username/scripts/my_script.sh,将“通过输入”设置为“无”,将“通过输出”设置为“无”。
  5. 在Automator中,选择“文件”>“保存”,然后将文件保存在~/Library/Services/My Script.workflow文件夹中。
  6. 重命名保存的文件为ScriptMenu.nib

现在,当您在Finder中右键单击文件或文件夹时,应该会看到一个名为“My Script”的新选项。单击该选项将运行您的脚本。

页面内容是否对你有帮助?
有帮助
没帮助

相关·内容

没有搜到相关的视频

领券