Parsing headers (was: Re: constant afdregfp)
Parsing headers (was: Re: constant afdregfp)
- Subject: Parsing headers (was: Re: constant afdregfp)
- From: Sun Real <email@hidden>
- Date: Tue, 10 Apr 2001 23:28:14 +1000
Chris Nebel's message of 10/4/01 2:39 PM contained:
>
To answer the original question: "path to" will work with any FindFolder
>
code as a four-character string. FindFolder is the underlying API call
>
that "path to" uses to tell where interesting folders are. For example,
>
"path to" doesn't define a term for the Favorites folder, but you can get
>
it by saying this:
>
>
path to "favs" --> "Macintosh HD:System Folder:Favorites:"
>
>
The authoritative source for these codes is the file Folders.h from the
>
Mac OS Universal Headers. These are designed for C programmers, but you
>
can pick out the relevant information without too much trouble even if
>
you don't know C.
Definitely. I just got this file recently as it happens & wrote a rough
script for parsing it & testing the codes.
For those who might find this useful, the lines of interest in
'Folders.h' look like this:
" kSystemFolderType = FOUR_CHAR_CODE('macs'), /* the system
folder */"
Getting the required items out of lines like the above is reasonably
simple using the text item delimiters & other built in functions like
'word'.
Getting 'word 1' of the line returns "kSystemFolderType".
Setting the tids to single quotes and getting text item 2 gives "macs".
Setting tids to "/*" and chopping the spaces off each end produces "the
system folder".
I called these Name, Code and Description respectively and added Result
where I used the 'path to' command to test for each folder and return the
folder path or an error.
Note that running the code will create the folders if it can and if they
don't already exist. If you have deleted (or never had) your 'Users' or
'Stationery' folders at the root level of your startup disk for example,
then you'll have them and others after running this if your OS supports
it.
>
...and Gestalt.h
>
for "computer" (aka "system attribute" on Mac OS X). Enjoy!
It works on this file too - just uncomment either of the 2 lines noted -
though some of the more obviously handy codes don't make much sense to
me. My 'ascv' (AppleScript version) returns 17826112 for example. I'm
using AS Z1-1.4. My 'sysv' (system version) which is 9.0.4, returns
2308. Can anyone tell me how to interpret these?
Watch for line wraps and Server Mutation.
-- returns a string containing info extracted from either of 2 header
files
-- write this out to a file or paste into spreadsheet for browsing
property idString : "FOUR_CHAR_CODE"
property t : tab
set selectedFile to choose file with prompt "Locate a 'Folders.h' or
'Gestalt.h' file."
set lineList to paragraphs of (read selectedFile) -- get list of lines
of the file
set outString to "Name Code Description Result
" -- header for the tab/return delimited output string
set olTids to AppleScript's text item delimiters -- save TIDS
repeat with i from 1 to length of lineList
tell item i of lineList
if it contains idString then -- process lines that contain our id
set thisName to word 1
set AppleScript's text item delimiters to "'"
set thisCode to text item 2
set AppleScript's text item delimiters to "/*"
try
set thisDescr to (text 2 through -3 of text item 2)
on error
set thisDescr to "n/a"
end try
try
-- uncomment this line for 'Folders.h'
--set reslt to (path to thisCode as string)
set reslt to "testResult" -- test only, delete this line
-- uncomment this line for 'Gestalt.h'
--tell application "Finder" to set reslt to (computer thisCode)
on error errStr number errNum
set reslt to errStr & " (" & errNum & ")"
end try
set outString to outString & thisName & t & thisCode & t & thisDescr &
t & reslt & return
end if
end tell
end repeat
set AppleScript's text item delimiters to olTids -- clean up
outString -- tab/return delimited string
Cheers,
Richard Morton
-- Great Lies of the Music Business: "We really want you in the band"