sveinbjornt / Platypus

Create native Mac applications from command line scripts.
https://sveinbjorn.org/platypus
BSD 3-Clause "New" or "Revised" License
2.85k stars 171 forks source link

Register as URI scheme handler seems unreliable #154

Open dmarmor opened 5 years ago

dmarmor commented 5 years ago

I'm having some trouble trying to create an app that reliably passes along the URLs sent to it to the script. I'm a new Platypus user (love it so far!), so it's possible I'm doing something wrong, but if so, I can't figure out what. Here's my test setup:

Create a Platypus app called TestURLs (or whatever) with a Text Window interface, with Accept dropped items checked, and within those settings, I checked Register as URI scheme handler and added http and https as schemes. Use this as the script:

#!/bin/sh

for arg in "$@" ; do
    echo "arg: '$arg'"
done

In the terminal, issue the following command:

open -a TestURLs 'http://example.com' 'http://foobar.com'

Expected output:

​arg: 'http://example.com'
​arg: 'http://foobar.com'

Actual output varies. Most often, I get the following:

​arg: 'http://example.com'

and it loses the second URL. Sometimes I get no output at all, as if no arguments have been passed. Very rarely, I'll get the expected output of both URLs.

I've verified that if I send the same open command to an ordinary browser, both URLs get opened. For example, this command will open both URLs in Chrome:

open -a 'Google Chrome' 'http://example.com' 'http://foobar.com'

Any ideas what's going on here?

Thanks!

dmarmor commented 5 years ago

Hi again. I've done some more testing, and it appears the same behavior happens with dragged files. If I create an app with Accept dragged files checked, add some UTIs, and then drag 2 or more files of those types onto the app icon, it doesn't reliably pass them both along to the script's arguments.

Not sure if this is related, but there also seems to be a lengthy delay (3-4 seconds on my system, a 2016 MacBook Pro running Mojave) when launching a Platypus app this way (by dragging 1 or more files onto it). If I launch the app with no files, just double-clicking the app icon, it launches right away.

Hope this info is helpful in diagnosing the situation. Thank you!

sveinbjornt commented 5 years ago

This may be due to issues with macOS Launch Services, which is sometimes flaky about how it sends Apple Events. I am very busy with my real job at the moment but I will look into this as soon as possible.

JayBrown commented 4 years ago

I have had success with this, but you need to manually add this kind of stuff to the ./Contents/Info.plist, not just ./Contents/Resources/AppSettings.plist

For example, in a Platypus app I'm currently working on, AppSettings.plist automatically gets the following:

<key>URISchemes</key>
<array>
    <string>uplc</string>
</array>

But you need extra stuff in the Info.plist:

<key>CFBundleURLTypes</key>
<array>
    <dict>
        <key>CFBundleURLName</key>
        <string>Uploha Companion</string>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>uplc</string>
        </array>
    </dict>
</array>