set permitted to {"com.apple.iwork.numbers.numbers", "com.apple.iwork.pages.pages", "com.apple.iwork.keynote.key", "com.apple.iwork.numbers.template", "com.apple.iwork.pages.template", "com.apple.keynote.kth"}
tell application "Finder"
if my quelOS() < "1050" then
set leDoc to choose file with prompt "Choose an iWork’s document" of type permitted
else
set leDoc to choose file with prompt "Choose an iWork’s document" of type {"com.apple.package"}
tell application "System Events" to if type identifier of leDoc is not in permitted then error "“" & (leDoc as Unicode text) & "” is not an iWork’s document!"
end if
end tell
--========
on quelOS()
local hexData, hexString
set the hexData to system attribute "sysv"
set hexString to {}
repeat 4 times
set hexString to ((hexData mod 16) as string) & hexString
set hexData to hexData div 16
end repeat
return hexString as string
end quelOS
--========
About the oddity with AddressBook archives file, I received:
OK, I took a look at AddressBook and iCal archives, and there does seem to be an error with the type - the property says it is com.apple.bundle, but it is really com.apple.package. As for using the UTI's, a file needs to have them set in the ContentTypeTree in order for them to be found - both AddressBook and iCal backups only have "com.apple.package", "public.directory", and "public.item" defined, so normally those are the only types that you will be able to use in the of type parameter.
All is not lost however - you can usually use the ContentType, but you need to know what to look for (I'm going to go around this the long way, because there is a bit of conflicting data and I can't explain these things very well). For the previous AddressBook and iCal backup examples, info for returns a type identifier of "BNDL", System Events returns a type identifier of something like "dyn.age80c2xcsy", and the Finder doesn't have a type identifier property at all. System Events is the clue here - a file's metadata has a kMDItemContentType entry with something like "dyn.ah62d4qmuhk2x44pdqm4u". This is the value you can use, even though it doesn't match what System Events gives you - for example:
choose file of type {"dyn.ah62d4qmuhk2x42pcqm4u"}
This UTI is dynamic, so it is most likely different for each machine. For my user account all of the AddressBook backups have the same type, so you should be able to look up that metadata item for your files (without a set UTI) and use it for all items of that type. For scripting other machines, you can get the metadata item at runtime (also note that the ContentType is usually one of the types in the ContentTypeTree).
I don't know the way to grab the kMDItemContentType value.
Yvan KOENIG (from FRANCE samedi 23 août 2008 12:40:07)