does not let you select any scpt files, this works for most other types. I did try using type identifiers but they seem even worse at getting it wrong. When I use
choose file of type {"com.apple.iwork.pages.pages"}
it only allows selection of pages files that are of the old package format, even though
type identifier of (info for (choose file))
returns the same thing for both; using the type id for .txt files seems to allow more that .txt files to be selected :mad:. I mean is this just a plain old bug in OS X or am I missing something?
The file type for a compiled script has always been “osas”. The type identifier "com.apple.applescript’ also works for me.
Otherwise you’re right. There does seem to be some inconsistency. Using the name extension sometimes works, sometimes not. Similarly with the type identifier.
Just looking at it quickly, the technique seems to be: if ‘info for’ returns a file type other than “”, use that; otherwise try the name extension; and if that doesn’t work, try the type identifier. Not guaranteed to be foolproof, though.
OK. Thanks, Yvan ” although in this case, the script would be just a test to see what to put in the new script.
-- No longer: set {file type:fileType, name extension:nameExtn} to (info for (choose file))
-- But:
tell application "System Events" to set {file type:fileType, name extension:nameExtn} to my (choose file) -- 'my' to prevent System Events from coming to the front to display the dialog.
if (fileType is missing value) then
set possibility to nameExtn
else
set possibility to fileType
end if
choose file of type {possibility} with prompt "Trying: 'choose file of type {\"" & possibility & "\"}'." -- Test.
I have this script to create files of a given type, then try to work out the correct way to find them in a choose file:
tell current application
open for access file valfile with write permission
close access file valfile
end tell
tell application "Finder"
set valident to file type of (info for file valfile)
tell me to log valident
if valident is "TEXT" then
set valident to type identifier of (info for file valfile)
tell me to log valident
if valident is "com.apple.traditional-mac-plain-text" then
set valident to text 2 thru -1 of valnewtypenam
tell me to log valident
end if
end if
end tell
Exactly as I was advised it checks for a good type, identifier and then if all else fails the extension, with a .bin it returned com.apple.macbinary-archive, for an icon file it returned the extension. I have a folder full of files created this way, I perhaps wrongly use it to test the results on.
choose file of type {"com.apple.macbinary-archive"}
works
choose file of type {"icon"}
does not allow any selection
choose file of type {"icon","com.apple.macbinary-archive"}
Files created with ‘open for access’ are of type “TEXT” unless you explicitly change their ‘file type’ properties afterwards.
The system appears to work from a combination of ‘file type’ and ‘name extension’. If you create a combination the system recognises, the file will (according to my experiments so far) be given a usable ‘type identifier’.
choose file of type {"com.apple.macbinary-archive"}
works
choose file of type {"ichgjghjon"}
does not allow any selection
choose file of type {"ichgjghjon","com.apple.macbinary-archive"}
allows everything to be selected
the main problem is I entered 2 types and nothing was restricted. Yes I entered a garbage name extension but my script needs to be able to handle any new file.
You could use lsregister command to look if a file type is registered in the launch services (this is where the com.apple.icns notation is for). Then when it is not registered you also don’t have to put it in the list of types.
If a user of my app requests a file type to be added than it must even if it doesn’t exist on the machine yet, and I don’t understand the command, I’m not sure how it can help me exactly. It’ not too important, it is working acceptably well.
lsregister can help you too lookup how the file type is defined. I use it for CSV files. When excel is installed it has another file type than machines who hasn’t installed excel. This is for me quite helpful determining which file type I have to use in the choose file command.