使用使用脚本的MacOS .app打开支持的文件类型

时间:2018-12-12 22:03:17

标签: bash macos

我创建了一个Sanitized.app,它在plist中定义了自定义UTI,并建立了适当的文件关联。该应用程序的可执行文件是bash脚本,当我尝试打开与自定义UTI匹配的文件时,将执行该脚本。但是,我似乎无法获得本应处理的文件的句柄!我期望它是可执行文件的参数,但是我得到的只是-psi *值。 我需要的是用户尝试打开/查看/编辑/等的文件的路径。

我已经阅读了this Apple developer page上的文档,但这似乎不适用于bash脚本。这可能吗?这是我的清单:

<?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>UTExportedTypeDeclarations</key>
        <array>
            <dict>
                <key>UTTypeIdentifier</key>
                <string>public.myext</string>
                <key>UTTypeReferenceURL</key>
                <string>https://com.company.some</string>
                <key>UTTypeDescription</key>
                <string>Sanitized Description</string>
                <key>UTTypeIconFile</key>
                <string>Sanitized.icns</string>
                <key>UTTypeConformsTo</key>
                <array>
                    <string>public.data</string>
                </array>
                <key>UTTypeTagSpecification</key>
                <dict>
                    <key>com.company.some.myext</key>
                    <string>MYEXT</string>
                    <key>public.filename-extension</key>
                    <array>
                        <string>myext</string>
                    </array>
                    <key>public.mime-type</key>
                    <string>application/vnd.myext</string>
                </dict>
            </dict>
        </array>
        <key>CFBundleDevelopmentRegion</key>
        <string>English</string>
        <key>CFBundleExecutable</key>
        <string>Sanitized</string>
        <key>CFBundleIdentifier</key>
        <string>com.company.some.myext</string>
        <key>CFBundleInfoDictionaryVersion</key>
        <string>6.0</string>
        <key>CFBundleName</key>
        <string>Sanitized Title</string>
        <key>CFBundlePackageType</key>
        <string>APPL</string>
        <key>CFBundleVersion</key>
        <string>1.2.3.4</string>
        <key>CFBundleShortVersionString</key>
        <string>1.2.3.4</string>
        <key>CFBundleAllowMixedLocalizations</key>
        <string>true</string>
        <key>NSHighResolutionCapable</key>
        <string>true</string>
        <key>CFBundleSignature</key>
        <string>????</string>
        <key>CFBundleIconFile</key>
        <string>Sanitized.icns</string>
        <key>CFBundleDocumentTypes</key>
        <array>
            <dict>
                <key>CFBundleTypeRole</key>
                <string>Editor</string>
                <key>LSHandlerRank</key>
                <string>Owner</string>
                <key>LSItemContentTypes</key>
                <array>
                    <string>public.myext</string>
                </array>
            </dict>
            <dict>
                <key>CFBundleTypeExtensions</key>
                <array>
                    <string>myext</string>
                </array>
                <key>CFBundleTypeIconFile</key>
                <string>Sanitized.icns</string>
                <key>CFBundleTypeName</key>
                <string>Sanitized Description</string>
            </dict>
        </array>
    </dict>
</plist>

目前“已消毒”脚本为:

#!/bin/bash
echo $@

我做错什么了吗?或者这不可能吗?我想避免仅为此功能创建一个XCode项目。

0 个答案:

没有答案