Attaching a script to a file type

This isn’t specifically an applescript problem, but it’s one I’ve encountered while scripting, so I still think it’s relevant.

For whatever reason, I prefer to use the X11 versions of some programs (such as emacs) to edit the relevant files. So I wrote a droplet that constructs a command line from the files dropped onto it, then passes that command line to Terminal to invoke emacs on the files. Now, when I drag files onto the droplet, it works fine, but when I try to associate this script with, say, .tex files (using the “Change All” button in the file info dialog), OS X chooses some script other than the one I told it to use and associates that script instead. Has anybody encountered this before?

Here’s the script, for reference:


on open these_items
	set myfiles to ""
	repeat with i from 1 to count of these_items
		set this_item to item i of these_items
		set item_info to info for this_item
		set myfiles to myfiles & (quoted form of POSIX path of this_item as string) & " "
	end repeat
	tell application "Terminal"
		if ((count windows) is 0) or (front window is busy) then
			do script ("emacs " & myfiles & " &")
			activate
			return
		end if
		
		do script ("emacs " & myfiles & " &") in front window
		activate
	end tell
end open

Thanks for any suggestions,

-chris

When you associate a document to an app, the thing is writen to the com.apple.launchservices.plist file. It needs one of a “LSBundleIdentifier” or a “LSBundleSIgnature” defined. For example, this is my entry for .ram files: LSBundleIdentifier=com.realnetworks.realone player; LSBundleSignature=PNst.
AppleScript droplets don’t define a bundle-identifier, and its “CFBundleSignature” (dplt) is shared with any droplet in your HD. That’s because it associates to “whatever droplet”.
You can use any resource-fork editor and modify yourself the “plst” resource, assigning a random and original signature to your droplet. You may need later restart or logout, then you can associate .tex files to your original-signature droplet. If this doesn’t still work, you may need change also the “creator type” of the droplet to match this signature (not sure).

Ah, so that’s what’s been going on. I haven’t tried it yet, but it sure looks promising.

Thanks for your help,

-chris