Remove "default application" setting from a file type?

I’m working on a script that performs actions on a file if the file has no default application associated with it.

In testing my script I used an old WordPerfect for DOS file named filename.WPF.

At one point, I opened that file in TextWrangler. Now OS X insists on treating TextWrangler as the default application for this file and any file with a .WPF extension.

Is there a way to clear the default application setting for .WPF files?

Thanks for any advice.

Hello!

I somehow guessed that things like this would soon be an issue :wink:

Download RCDefaultApps preference pane! Can be found here!

Thanks for that! I actually tried RCDefaultApp, but when I chose from the menu for the WPF extension, it replaced TextWranger.App with DoNothing.app. I wonder if there’s a way to remove the default application setting entirely, or if that’s just impossible under OS X…

Hello!

I think it should be possible, you should have a look at extensions as well, as uti’s, and try checking of “Override creator”

I think this is where the removing of file creator type kicks in! :slight_smile: To assure that no default app turns up.

Have a look at the aformentioned article at daringfireball.net! (daringfireball.net is searchable, if you search for creator type, I am sure something turns up, regarding BBEdit!

Thank you again. I think this is the article you mean:

http://daringfireball.net/2004/02/setting_empty_file_and_creator_types

It doesn’t say anything about removing default applications, but I’ll experiment.

I got rid of the default application for WPF by editing com.apple.LaunchServices.plist in my Library/Preferences folder. I searched for WPF and deleted the whole key. I then restarted the system, and there is now no default application for WPF.

I don’t know whether RCDefaultApp would have fixed this by itself if I had restarted after using it, but I will experiment later and report.

I think the way you did it, was the easiest. I’ll be sure to remember that way to do it until next time!

The article I read, was about uti’s and creator types, and how to get rid of it, because if you get rid of it, then you get rid of the uti, and the default app. Gruber’s objective in the article, was to get rid of the default app, and be asked, like you, about what application to launch!

The OS will then ask you for an app to open your file with.

The daringfireball article is from 2004 !!

Meanwhile creator code (and probably file type too) are outdated

Agree with SefanK. Macs use UTI’s now. See here.

Who? :wink:

Hello!

Maybe things have changed, but I am on Snow Leopard, and a uti of a file here, is decided by an algorithm which takes the file extension, and the creator type into account. Not that it matters much, but the document Hank posted a link to, is from November 2009, (shortly after the release of SL), and the aformentioned algorithm for deciding uti’s should therefore also apply to that document as well.

Only if the app hasn’t provided a UTI.

True!

But the way to tinker it, say if you want to have a choice when opening a html file for instance, is to remove the file creator type, as that should then disable the default.app I’ll actually do that almost right away, to see if theory and practice correlates!

Hello!

I have had some pre Snow Leopard memories here (Tiger), you can really only set another default app on a per file basis with finders info window. This fine article by Mr. John Gruber explains it all.

I have have however circumvented the problem, by setting a new default app manually for a file, and then run a script I have written to set another default app for a subtree, there at least also used to be one or two small apps that did something similar for a group of files in one go.

Here is the script. You first set another app as the default app on one of the files, choose two, it then works out the differences needed to be made, then you are prompted for a subtree, then it will change the default app for every file of that kind in the subtree


” © McUsr 2010 not to be posted anywhere else! http://macscripter.net/viewtopic.php?pid=154128
property McUsr : "1.0 Maybe add some help or such"
set fileExt to ""
set resRec to divergingProperties(a reference to fileExt)
if resRec is not null then
	
	set theRootOfTheTree to (choose folder with prompt "Choose a tree to change \"uti's\" within") as text
	changeAllUtis(theRootOfTheTree, resRec, fileExt)
end if


on divergingProperties(fileExt)
	local theSel, propCount, fileNmA, fileNmB, fPropsA, fPropsB, dateA, dateB, newFProps, oldFProps, changeRec
	set propCount to 0
	tell application "Finder"
		set theSel to (get its selection) as alias list
		if (count of theSel) is not 2 then
			display dialog "Needs two files with same extension, where one of them is configured to be opened with another app"
			-- rework som logic here 
			error number -128
		end if
		
		set fileNmA to item 1 of theSel as text
		set fileNmB to item 2 of theSel as text
		repeat with i from 1 to 2
			if extension hidden of item i of theSel is true then set extension hidden of item i of theSel to false
		end repeat
	end tell
	tell application "System Events"
		set fPropsA to (get properties of item fileNmA)
		set contents of fileExt to (name extension of fPropsA)
		set fPropsB to (get properties of item fileNmB)
		if not (name extension of fPropsA is equal to name extension of fPropsB) then
			tell me
				activate
				display dialog "Needs two files with same extension, or of the same type where the two differs in the choice of default app to be opened with."
			end tell
			error number -128
			-- utvide til å gå på type her:
		else
			-- choose which file you want to change all the uti's too.
			
			
			set dateA to modification date of fPropsA
			set dateB to modification date of fPropsB
			if dateB > dateA then
				set newFProps to fPropsB
				set oldFProps to fPropsA
			else
				set newFProps to fPropsA
				set oldFProps to fPropsB
			end if
			-- eventually changing attributes in order of appearance 
			if not (file type of newFProps is equal to file type of oldFProps) then
				set propCount to propCount + 1
				set changeRec to {file type:(file type of newFProps)}
			end if
			
			-- so we are basically clear about what from what properties the uti data will be set.
			if not (kind of newFProps is equal to kind of oldFProps) then
				set changeRec to {kind:(kind of newFProps)}
				if propCount > 0 then
					set changeRec to changeRec & {kind:(kind of newFProps)}
				else
					set changeRec to {kind:(kind of newFProps)}
				end if
				set propCount to propCount + 1
			end if
			if not (creator type of newFProps is equal to creator type of oldFProps) then
				if propCount > 0 then
					set changeRec to changeRec & {creator type:(creator type of newFProps)}
				else
					set changeRec to {creator type:(creator type of newFProps)}
				end if
				set propCount to propCount + 1
			end if
			if not (type identifier of newFProps is equal to type identifier of oldFProps) then
				if propCount > 0 then
					set changeRec to changeRec & {type identifier:(type identifier of newFProps)}
				else
					set changeRec to {type identifier:(type identifier of newFProps)}
				end if
				set propCount to propCount + 1
			end if
			if not (default application of newFProps is equal to default application of oldFProps) then
				if propCount > 0 then
					set changeRec to changeRec & {default application:default application of newFProps} -- problem her
				else
					set changeRec to {default application:(default application of newFProps)}
				end if
				set propCount to propCount + 1
			end if
		end if
	end tell
	if propCount > 1 then -- let the show begin
		-- changeUtiForFileOLD(fileNmB, changeRec)
		return changeRec
	else
		return null
	end if
end divergingProperties

on changeUtiForFile(theFile, theChanges)
	local changedProperty
	log " thefile : " & theFile
	tell application "System Events"
		try
			set changedProperty to file type of theChanges
			-- set file type of file theFile to changedProperty
			set properties of file theFile to {file type:changedProperty}
		on error
			-- goof
		end try
		try
			set changedProperty to kind of theChanges
			-- set kind of file theFile to changedProperty
			set properties of file theFile to {kind:changedProperty}
		on error
			-- goof
		end try
		try
			set changedProperty to creator type of theChanges
			-- set creator type of file theFile to changedProperty
			set properties of file theFile to {creator type:changedProperty}
		on error
			-- goof
			
		end try
		try
			set changedProperty to type identifier of theChanges
			-- set type identifier of file theFile to changedProperty
			set properties of file theFile to {type identifier:changedProperty}
		on error
			-- goof
			
		end try
		try
			set changedProperty to default application of theChanges
			-- set default application of file theFile to changedProperty
			set properties of file theFile to {default application:changedProperty}
		on error
			-- goof
		end try
	end tell
end changeUtiForFile


on changeAllUtis(theRootOfTheTree, theChangeRec, theFileExt)
	local fileText
	tell application "Finder"
		set tSelectedFiles to (every file of folder theRootOfTheTree whose extension hidden is true)
		repeat with aFile in tSelectedFiles
			set extension hidden of aFile to false
		end repeat
		-- copy or move over files of the specified type(s)
		set tSelectedFiles to (every file of folder theRootOfTheTree whose name extension is equal to theFileExt) as alias list
		if tSelectedFiles ≠ {} then
			repeat with aFile in tSelectedFiles
				set fileText to aFile as text
				my changeUtiForFile(fileText, theChangeRec)
			end repeat
		end if
		-- copy over the folders, calling this handler recursively
		set tFolders to (every folder of folder theRootOfTheTree)
		repeat with tThisFolder in tFolders
			my changeAllUtis(tThisFolder as alias, theChangeRec, theFileExt)
		end repeat
	end tell
end changeAllUtis