the hyphenated enumerator bug and the raw code of a constant

There is a bug somewhere in the AppleScript ecosystem that prevents scripts like this from compiling in Script Editor:

tell application "Finder"
	Packet-written UDF format
	MS-DOS format
end tell

Presumably because the hyphen is interpreted as a minus symbol. After reading page 310 of AppleScript: The Definitive Guide backwards and forwards several times (from different angles and in different areas of the house), I finally worked out that I need to specify a raw constant containing the enumerator code along with the code of the enumeration that said enumerator belongs to.

To track these things down I opened Finder’s dictionary in Script Editor, hit shift-command-s to save it as an .sdef file, and then opened that with TextEdit. There I discovered the enumerators in question nested inside the enumaration edfm. The enumerators themselves were easily identifiable by name, and each contained a unique four-letter code. Using this information I was able to write the following script:

tell application "Finder"
	«constant edfmdfpu»
	«constant edfmdfms»
end tell

Which compiles and produces code that matches the former scriptlet. If, however, we try to compile this code again, we will get a syntax error. The solution is to write the affected code as a string, and then execute it with the run script command.

run script "
tell application \"Finder\"
	«constant edfmdfpu»
	«constant edfmdfms»
end tell
"

I’m really not sure how often this issue comes up in scripting, but perhaps in time my experience will aid 1 or… maybe even 2 (!) other visitors to this forum. Any additional insights regarding this behavior are welcome.

Edit: I’ve stumbled on yet another interesting wrinkle. That is, if you fudge the enumeration reference, the raw code will not be replaced at compile time, but it will still work! This, for example, successfully locates the DVD in my optical drive:

tell application "Finder"
	disks whose format is «constant xxxxdfud»
end tell

Saving a dictionary as an XML .sdef was news to me - very interesting to look at some of them.

For those that might like to look at the code embedded in the Finder dictionary (or any other with some minor mods), open it and save it to your desktop, then run this to space it out so you can read it more easily.

set ptdt to path to desktop as string
set sdef to open for access ptdt & "Finder.sdef"
set outFile to open for access ptdt & "FinderDict.txt" with write permission
set sdefText to read sdef
set fixedText to ""
set text item delimiters to ">"
repeat with k from 1 to count of text items in sdefText
	set fixedText to fixedText & (text item k of sdefText) & ">" & return & return
end repeat
write fixedText to outFile
set text item delimiters to ""
close access sdef
close access outFile

Once you have saved an .sdef file, you can use the terrific freeware application Sdef Editor to inspect the file with ease.

Jon

Dang. I have a script sitting on the screen that was a beginning to just that. Didn’t occur to me to search for one. Thanks for the link, Jon