do shell script (grep) AppleScript error
do shell script (grep) AppleScript error
- Subject: do shell script (grep) AppleScript error
- From: Mark Douma <email@hidden>
- Date: Sat, 14 Feb 2004 14:19:05 -0500
I'm using grep to search the resource fork of a font suitcase file to
ensure that the font suitcase actually represents a Mac TrueType font
rather than the screen part of a PostScript Type 1 font. In order to do
this, I was trying to use grep to search for (and count the # of
occurrences of) "sfnt", which designates the TT vector resource.
For example, I'd use the following command in Terminal to determine the
state of a particular font suitcase:
grep -c sfnt "/Volumes/mdouma46/Desktop/Arial PS/..namedfork/rsrc"
The "-c" flag signifies to count the number of occurences. If the file
contains an "sfnt" resource, the script would return "1", since it
found "sfnt" once within the file. If the file doesn't contain an
"sfnt" resource, the shell script returns 0 (zero), since it's found 0
occurrences of "sfnt".
This works fine in Terminal, but when trying it from within
AppleScript, it results in an AppleScript error with message "0"
(zero), error number "-1". For example, wrapping that shell script
inside an AppleScript such as the following:
set sh_grep_sfnt_ to "grep -c sfnt \"/Volumes/mdouma46/Desktop/Arial
PS/..namedfork/rsrc\"" as string
set sfnt_ to do shell script sh_grep_sfnt_
I was attempting to set "sfnt_" to either "1" or "0", and then use an
if-then loop to determine what to do based on the result (full script
context below).
Any ideas what's going on here?
on open fonts_
set ttf_list_ to {}
set ps_list_ to {}
repeat with i from 1 to the count of fonts_
set font_ to (item i of fonts_)
set font_info_ to info for font_
tell application "Finder"
set target_folder_path_ to (container of font_ as alias)
set POSIX_target_folder_path_ to POSIX path of target_folder_path_
end tell
if alias of font_info_ is false and folder of font_info_ is true then
process_folder_(font_)
else if ((alias of font_info_ is false) and (name extension of
font_info_ is "dfont")) then
set conversion_type_ to "undfontify" as string
set POSIX_font_path_ to POSIX path of font_ as string
set POSIX_new_font_path_ to target_font_path_(font_info_,
conversion_type_, POSIX_target_folder_path_, target_folder_path_)
process_font_(conversion_type_, POSIX_font_path_,
POSIX_new_font_path_)
else if ((alias of font_info_ is false) and (file type of font_info_
is "FFIL") and (file creator of font_info_ is "DMOV")) then
set POSIX_font_path_ to POSIX path of font_ as string
set sh_grep_sfnt_ to "grep -c sfnt \"" & POSIX_font_path_ &
"/..namedfork/rsrc\""
set sfnt_ to do shell script sh_grep_sfnt_ -- <<<<<<<<<<## script
never gets past here if this line is attempted
if sfnt_ = "1" then
set conversion_type_ to "dfontify" as string
set POSIX_new_font_path_ to target_font_path_(font_info_,
conversion_type_, POSIX_target_folder_path_, target_folder_path_)
process_font_(conversion_type_, POSIX_font_path_,
POSIX_new_font_path_)
else if sfnt_ = "0" then
set end of ps_list_ to POSIX_font_path_
end if
else if (alias of font_info_ is false) and ((name extension of
font_info_ is "ttf") or (name extension of font_info_ is "ttc")) then
set POSIX_font_path_ to POSIX path of font_ as string
set end of ttf_list_ to POSIX_font_path_
end if
end repeat
end open
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.