moretension / duti

A command-line tool to select default applications for document types and URL schemes on Mac OS X
Other
1.48k stars 66 forks source link

Is it possible to unset associations? #21

Open szhu opened 8 years ago

szhu commented 8 years ago

Suppose I have a file of the following type hierarchy:

kMDItemContentTypeTree         = (
    "com.netscape.javascript-source",   // let's say this is associated with AppOne
    "public.script",
    "public.source-code",               // let's say this is associated with AppTwo
    "public.plain-text",
    "public.text",
    "public.data",
    "public.item",
    "public.content",
    "public.executable"
)

I want com.netscape.javascript-source files to be opened by AppTwo, but I don't want to explicitly associate them with AppTwo. I just want to remove the exception so that they get handled the same way as the other public.source-code files.

Is there something I can run along the lines of duti -s NONE public.html all to achieve this effect?

datenreisender commented 7 years ago

I accidentally associated some nonsense URL scheme with applications and would also like to remove those associations. So it would be really nice, if doti would support that!

avxkim commented 6 years ago

Reading the manpage, but can't find how to unset associations.

acthp commented 6 years ago

Having the same problem. How can these settings be removed?

nivekkagicom commented 6 years ago

FWIW Apple does not provide an API to reset/remove the default content handler for a UTI or the default handler for a URL scheme. However, one may specify a new bundle identifier in a followup duti command to set the the default handler to the original application or another application. The only way to reset to the default handlers otherwise is to use lsregister or a third-party tool to reset and rebuild the Launch Services database.

szhu commented 6 years ago

I wonder we can achieve the same effect by:

  1. Making a temporary app
  2. Set the association to that app
  3. Delete the app

I haven't tested it, but I suspect that this will be able to remove custom associations (ones set in Open With…/duti) but it might not be able to remove associations that apps have set in their Info.plist file.

rarylson commented 5 years ago

I had the same problem. To solve this, I had to manually (using PlistBuddy) remove it.

In my example:

$ /usr/libexec/PlistBuddy -c "Print" \
>   ~/Library/Preferences/com.apple.LaunchServices/com.apple.launchservices.secure.plist
# Discover the array number of the entry I want to remove
# In my case: 23
$ /usr/libexec/PlistBuddy -c "Delete :LSHandlers:23" \
>   ~/Library/Preferences/com.apple.LaunchServices/com.apple.launchservices.secure.plist

This is not a good user experience. It would be nice if duty could remove these entries for me.

Ps: Also, to discover the app registered to a given URL scheme, I need to manually use PlistBuddy.

Mellbourn commented 3 years ago

Same problem. I used duti to change the default for public.shell-script because I wanted script to start an editor so I could edit them, stupidly not realizing that I now made it harder to execute shell scripts.

I tried @rarylson procedure but unfortunately it doesn't change anything for me.

Demianeen commented 9 months ago

Wrote some script that can automaticly remove all vscode Dict instances. You can change it to any other app:

#!/bin/bash

# Path to the plist file
PLIST=~/Library/Preferences/com.apple.LaunchServices/com.apple.launchservices.secure.plist

# Backup the original plist file
cp "$PLIST" "${PLIST}.backup"

count_ls_handlers() {
    /usr/libexec/PlistBuddy -c "Print :LSHandlers" "$PLIST" | grep "= Dict {" | wc -l | xargs
}

# Get the total number of LSHandlers entries
COUNT=$(count_ls_handlers)
OLD_COUNT=$(count_ls_handlers)

# Loop through the entries and find VSCode entries
for ((i = 0; i < COUNT; i++)); do
    HANDLER=$(/usr/libexec/PlistBuddy -c "Print :LSHandlers:$i:LSHandlerRoleAll" "$PLIST" 2>/dev/null)
    if [ "$HANDLER" == "com.microsoft.vscode" ]; then
        echo "Removing VSCode handler at index $i"
        /usr/libexec/PlistBuddy -c "Delete :LSHandlers:$i" "$PLIST"
        COUNT=$((COUNT - 1)) # Decrease count as the list gets shorter
        i=$((i - 1))         # Decrease index as next item shifts to current index
    fi
done

NEW_COUNT=$(count_ls_handlers)

echo "Operation completed. $((OLD_COUNT - NEW_COUNT)) entries was removed"

I needed to restart system to make it work though