Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Script the Finder to empty codes' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Script the Finder to empty codes
Authored by: VRic on Aug 18, '04 03:20:58PM
This hint doesn't explain what it is to "remove the type code". To be fair even Apple has had varying positions on the matter. Unless the tools in use offer dedicated presets for this, one needs to know what "empty" type/creator codes really are (NOT empty :-). And once you know this, you don't need dedicated tools any more.

Empty type/creator codes on HFS/HFS+ volumes aren't empty strings: OSType values are tied to the file entry at the filesystem level (not in the resource fork as many believe) and are always exactly 4 bytes, each with a value of 0 for files "without" codes.

The following script for Mac OS X sets the selected files' type & creator codes to 4 null characters as found in "real" un-typed files on HFS/HFS+ volumes (not "????" or 4 spaces, which may still work but I believe aren't sanctioned by Apple any more -- those allowed to specify the existing "unknown" type with characters available on the keyboard, not a default "empty" code that uses null chars).


-- get Finder selection
tell application "Finder"
	set theItems to selection
end tell
if theItems is {} then
	display dialog "Select some files in the Finder to empty their type and creator codes."
end if

-- prepare "empty" OSType value
set nullCh to ASCII character 0
set emptyOSType to nullCh & nullCh & nullCh & nullCh

-- do it
tell application "Finder"
	repeat with thisitem in theItems
		if class of thisitem is document file then
			-- only process documents (not disks, folders, applications, aliases)
			try
				set file type of thisitem to emptyOSType
				set creator type of thisitem to emptyOSType
			on error error_message
				display dialog error_message
			end try
		end if
	end repeat
end tell


[ Reply to This | # ]
Script the Finder to empty codes
Authored by: kyngchaos on Aug 18, '04 04:03:13PM

(I'm a bit flakey when it comes to explaining things ^_^)

With the GUI tools (FileShaper, File Buddy, ...) it's easy - just delete the text from the TYPE text box, and the tool takes care of writing the null characters.

However, I found that with the CLI SetFile (robg added that one to the hint for me), you can't use an empty string, it looks like it really sets it to a zero length string not nulls (at least it caused FileShaper to crash when I tried to check it). So with SetFile you would have to build a null string somehow like with your AppleScript.



[ Reply to This | # ]
Script the Finder to empty codes
Authored by: hypert on Apr 29, '10 11:56:33AM

Thanks - that was a big help to me in clearing some Creator Codes!



[ Reply to This | # ]