Lord-Kamina / SwiftDefaultApps

Replacement for RCDefaultApps, written in Swift.
Other
1.45k stars 62 forks source link

selecting an app silently fails #4

Open fedelibre opened 6 years ago

fedelibre commented 6 years ago

I'm trying to use SwiftDefaultApps to associate a custom helper application (a simple bash script, actually) with a URI protocol called textedit. This protocol is associated by default to an application called LilyPond. As LilyPond on Mac doesn't handle correctly this protocol, I had to make another "app" (the aforementioned bash script).

Problem: when I select my custom app, the selection is not saved and SwiftDefaultApps doesn't return any error message. I think it should, even if it might be well a problem in my Info.plist. (I'm totally new to Mac and I'm using my father's Mac just to see how to fix this problem)

How can I validate a Info.plist file?

Lord-Kamina commented 6 years ago

The problem is mac is constantly pruning the Launch Services database for what it deems are invalid associations. If an app doesn't declare to the OS that it can handle the protocol, by definition it's going to be an invalid pairing, and AFAIK, it's not possible for bash scripts to declare such a thing. The only thing I can think of is maybe put your script inside an app bundle and then you can declare it's handling the protocol in the Info.plist? That might work.

From: Federico Bruni notifications@github.com notifications@github.com Reply: Lord-Kamina/SwiftDefaultApps reply@reply.github.com reply@reply.github.com Date: August 2, 2018 at 07:50:51 To: Lord-Kamina/SwiftDefaultApps swiftdefaultapps@noreply.github.com swiftdefaultapps@noreply.github.com CC: Subscribed subscribed@noreply.github.com subscribed@noreply.github.com Subject: [Lord-Kamina/SwiftDefaultApps] selecting an app silently fails (#4)

I'm trying to use SwiftDefaultApps to associate a custom helper application

(a simple bash script, actually) with a URI protocol called textedit. This protocol is associated by default to an application called LilyPond http://lilypond.org. As LilyPond on Mac doesn't handle correctly this protocol, I had to make another "app" (the aforementioned bash script).

Problem: when I select my custom app, the selection is not saved and SwiftDefaultApps doesn't return any error message. I think it should, even if it might be well a problem in my Info.plist. (I'm totally new to Mac and I'm using my father's Mac just to see how to fix this problem)

How can I validate a Info.plist file?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/Lord-Kamina/SwiftDefaultApps/issues/4, or mute the thread https://github.com/notifications/unsubscribe-auth/AGJfLNsu2gXTrx59zArKTNX9v84TVo7Hks5uMuebgaJpZM4VsI1y .

fedelibre commented 6 years ago

AFAIK, it's not possible for bash scripts to declare such a thing. The only thing I can think of is maybe put your script inside an app bundle and then you can declare it's handling the protocol in the Info.plist? That might work.

This is what I was trying. I called the app bundle LilypondInvokeEditor and I placed the bash script inside it. Can you spot any error below?

This is the app tree:

$ ls -R /Applications/LilypondInvokeEditor.app/
Contents

/Applications/LilypondInvokeEditor.app//Contents:
Info.plist  MacOS

/Applications/LilypondInvokeEditor.app//Contents/MacOS:
LilypondInvokeEditor

This is the Info.plist file:

$ cat /Applications/LilypondInvokeEditor.app/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>CFBundleDisplayName</key>
    <string>LilypondInvokeEditor</string>
  <key>CFBundleURLTypes</key>
    <array>
        <dict>
            <key>CFBundleTypeRole</key>
            <string>Editor</string>
            <key>CFBundleURLName</key>
            <string>text editor via url</string>
            <key>CFBundleURLSchemes</key>
            <array>
                <string>textedit</string>
            </array>
            <key>NSDocumentClass</key>
            <string>TinyTinyDocument</string>
        </dict>
    </array>
</dict>
</plist>

and this is the bash script:

$ cat /Applications/LilypondInvokeEditor.app/Contents/MacOS/LilypondInvokeEditor 
#!/usr/bin/env bash
export PYTHONPATH="/Applications/LilyPond.app/Contents/Resources/lib/lilypond/current/python:/Applications/LilyPond.app/Contents/Resources/share/lilypond/current/python:$PYTHONPATH"
export GUILE_LOAD_PATH="/Applications/LilyPond.app/Contents/Resources/share/lilypond/current"
export LD_LIBRARY_PATH="/Applications/LilyPond.app/Contents/Resources/lib:$LD_LIBRARY_PATH"
exec "/Applications/LilyPond.app/Contents/Resources/bin/guile" "/Applications/Lilypond.app/Contents/Resources/bin/lilypond-invoke-editor" "$@"

The script itself does work:

$ /Applications/LilypondInvokeEditor.app/Contents/MacOS/LilypondInvokeEditor --version
lilypond-invoke-editor (GNU LilyPond) 2.19.82